|
@@ -18,6 +18,7 @@
|
|
|
package org.apache.hadoop.hdfs.tools.federation;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.PrintStream;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
@@ -26,6 +27,7 @@ import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
+import java.util.TreeMap;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
@@ -46,6 +48,10 @@ import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.server.federation.router.RouterClient;
|
|
|
import org.apache.hadoop.hdfs.server.federation.router.RouterQuotaUsage;
|
|
|
import org.apache.hadoop.hdfs.server.federation.router.RouterStateManager;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.CachedRecordStore;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.RecordStore;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.StateStoreUtils;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntryRequest;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntryResponse;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.protocol.DisableNameserviceRequest;
|
|
@@ -70,7 +76,9 @@ import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableE
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryResponse;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryRequest;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryResponse;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
|
|
|
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.store.records.impl.pb.PBRecord;
|
|
|
import org.apache.hadoop.ipc.ProtobufRpcEngine2;
|
|
|
import org.apache.hadoop.ipc.RPC;
|
|
|
import org.apache.hadoop.ipc.RefreshResponse;
|
|
@@ -97,6 +105,7 @@ import static org.apache.hadoop.hdfs.server.federation.router.Quota.andByStorage
|
|
|
public class RouterAdmin extends Configured implements Tool {
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(RouterAdmin.class);
|
|
|
+ private static final String DUMP_COMMAND = "-dumpState";
|
|
|
|
|
|
private RouterClient client;
|
|
|
|
|
@@ -133,7 +142,7 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
String[] commands =
|
|
|
{"-add", "-update", "-rm", "-ls", "-getDestination", "-setQuota",
|
|
|
"-setStorageTypeQuota", "-clrQuota", "-clrStorageTypeQuota",
|
|
|
- "-safemode", "-nameservice", "-getDisabledNameservices",
|
|
|
+ DUMP_COMMAND, "-safemode", "-nameservice", "-getDisabledNameservices",
|
|
|
"-refresh", "-refreshRouterArgs",
|
|
|
"-refreshSuperUserGroupsConfiguration", "-refreshCallQueue"};
|
|
|
StringBuilder usage = new StringBuilder();
|
|
@@ -187,6 +196,8 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return "\t[-refreshSuperUserGroupsConfiguration]";
|
|
|
} else if (cmd.equals("-refreshCallQueue")) {
|
|
|
return "\t[-refreshCallQueue]";
|
|
|
+ } else if (cmd.equals(DUMP_COMMAND)) {
|
|
|
+ return "\t[" + DUMP_COMMAND + "]";
|
|
|
}
|
|
|
return getUsage(null);
|
|
|
}
|
|
@@ -224,7 +235,8 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
if (arg.length > 1) {
|
|
|
throw new IllegalArgumentException("No arguments allowed");
|
|
|
}
|
|
|
- } else if (arg[0].equals("-refreshCallQueue")) {
|
|
|
+ } else if (arg[0].equals("-refreshCallQueue") ||
|
|
|
+ arg[0].equals(DUMP_COMMAND)) {
|
|
|
if (arg.length > 1) {
|
|
|
throw new IllegalArgumentException("No arguments allowed");
|
|
|
}
|
|
@@ -286,6 +298,15 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Does this command run in the local process?
|
|
|
+ * @param cmd the string of the command
|
|
|
+ * @return is this a local command?
|
|
|
+ */
|
|
|
+ boolean isLocalCommand(String cmd) {
|
|
|
+ return DUMP_COMMAND.equals(cmd);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int run(String[] argv) throws Exception {
|
|
|
if (argv.length < 1) {
|
|
@@ -303,6 +324,10 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
System.err.println("Not enough parameters specificed for cmd " + cmd);
|
|
|
printUsage(cmd);
|
|
|
return exitCode;
|
|
|
+ } else if (isLocalCommand(argv[0])) {
|
|
|
+ if (DUMP_COMMAND.equals(argv[0])) {
|
|
|
+ return dumpStateStore(getConf(), System.out) ? 0 : -1;
|
|
|
+ }
|
|
|
}
|
|
|
String address = null;
|
|
|
// Initialize RouterClient
|
|
@@ -1301,6 +1326,49 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return returnCode;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Dumps the contents of the StateStore to stdout.
|
|
|
+ * @return true if it was successful
|
|
|
+ */
|
|
|
+ public static boolean dumpStateStore(Configuration conf,
|
|
|
+ PrintStream output) throws IOException {
|
|
|
+ StateStoreService service = new StateStoreService();
|
|
|
+ conf.setBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE, false);
|
|
|
+ service.init(conf);
|
|
|
+ service.loadDriver();
|
|
|
+ if (!service.isDriverReady()) {
|
|
|
+ System.err.println("Can't initialize driver");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // Get the stores sorted by name
|
|
|
+ Map<String, RecordStore<? extends BaseRecord>> stores = new TreeMap<>();
|
|
|
+ for(RecordStore<? extends BaseRecord> store: service.getRecordStores()) {
|
|
|
+ String recordName = StateStoreUtils.getRecordName(store.getRecordClass());
|
|
|
+ stores.put(recordName, store);
|
|
|
+ }
|
|
|
+ for (Entry<String, RecordStore<? extends BaseRecord>> pair: stores.entrySet()) {
|
|
|
+ String recordName = pair.getKey();
|
|
|
+ RecordStore<? extends BaseRecord> store = pair.getValue();
|
|
|
+ output.println("---- " + recordName + " ----");
|
|
|
+ if (store instanceof CachedRecordStore) {
|
|
|
+ for (Object record: ((CachedRecordStore) store).getCachedRecords()) {
|
|
|
+ if (record instanceof BaseRecord && record instanceof PBRecord) {
|
|
|
+ BaseRecord baseRecord = (BaseRecord) record;
|
|
|
+ // Generate the pseudo-json format of the protobuf record
|
|
|
+ String recordString = ((PBRecord) record).getProto().toString();
|
|
|
+ // Indent each line
|
|
|
+ recordString = " " + recordString.replaceAll("\n", "\n ");
|
|
|
+ output.println(String.format(" %s:", baseRecord.getPrimaryKey()));
|
|
|
+ output.println(recordString);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ output.println();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ service.stop();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Normalize a path for that filesystem.
|
|
|
*
|
|
@@ -1341,4 +1409,4 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return mode;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|