|
@@ -32,6 +32,7 @@ import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.conf.Configured;
|
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
|
+import org.apache.hadoop.fs.StorageType;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
|
@@ -83,6 +84,9 @@ import org.apache.hadoop.util.Tool;
|
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import static org.apache.hadoop.hdfs.server.federation.router.Quota.eachByStorageType;
|
|
|
+import static org.apache.hadoop.hdfs.server.federation.router.Quota.orByStorageType;
|
|
|
+import static org.apache.hadoop.hdfs.server.federation.router.Quota.andByStorageType;
|
|
|
|
|
|
/**
|
|
|
* This class provides some Federation administrative access shell commands.
|
|
@@ -125,8 +129,8 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
private String getUsage(String cmd) {
|
|
|
if (cmd == null) {
|
|
|
String[] commands =
|
|
|
- {"-add", "-update", "-rm", "-ls", "-getDestination",
|
|
|
- "-setQuota", "-clrQuota",
|
|
|
+ {"-add", "-update", "-rm", "-ls", "-getDestination", "-setQuota",
|
|
|
+ "-setStorageTypeQuota", "-clrQuota", "-clrStorageTypeQuota",
|
|
|
"-safemode", "-nameservice", "-getDisabledNameservices",
|
|
|
"-refresh", "-refreshRouterArgs",
|
|
|
"-refreshSuperUserGroupsConfiguration"};
|
|
@@ -160,8 +164,13 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
} else if (cmd.equals("-setQuota")) {
|
|
|
return "\t[-setQuota <path> -nsQuota <nsQuota> -ssQuota "
|
|
|
+ "<quota in bytes or quota size string>]";
|
|
|
+ } else if (cmd.equals("-setStorageTypeQuota")) {
|
|
|
+ return "\t[-setStorageTypeQuota <path> -storageType <storage type> "
|
|
|
+ + "<quota in bytes or quota size string>]";
|
|
|
} else if (cmd.equals("-clrQuota")) {
|
|
|
return "\t[-clrQuota <path>]";
|
|
|
+ } else if (cmd.equals("-clrStorageTypeQuota")) {
|
|
|
+ return "\t[-clrStorageTypeQuota <path>]";
|
|
|
} else if (cmd.equals("-safemode")) {
|
|
|
return "\t[-safemode enter | leave | get]";
|
|
|
} else if (cmd.equals("-nameservice")) {
|
|
@@ -241,10 +250,18 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
if (argv.length < 4) {
|
|
|
return false;
|
|
|
}
|
|
|
+ } else if ("-setStorageTypeQuota".equals(cmd)) {
|
|
|
+ if (argv.length < 5) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
} else if ("-clrQuota".equals(cmd)) {
|
|
|
if (argv.length < 2) {
|
|
|
return false;
|
|
|
}
|
|
|
+ } else if ("-clrStorageTypeQuota".equals(cmd)) {
|
|
|
+ if (argv.length < 2) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
} else if ("-safemode".equals(cmd)) {
|
|
|
if (argv.length < 2) {
|
|
|
return false;
|
|
@@ -336,6 +353,11 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
System.out.println(
|
|
|
"Successfully set quota for mount point " + argv[i]);
|
|
|
}
|
|
|
+ } else if ("-setStorageTypeQuota".equals(cmd)) {
|
|
|
+ if (setStorageTypeQuota(argv, i)) {
|
|
|
+ System.out.println(
|
|
|
+ "Successfully set storage type quota for mount point " + argv[i]);
|
|
|
+ }
|
|
|
} else if ("-clrQuota".equals(cmd)) {
|
|
|
while (i < argv.length) {
|
|
|
if (clrQuota(argv[i])) {
|
|
@@ -344,6 +366,14 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
+ } else if ("-clrStorageTypeQuota".equals(cmd)) {
|
|
|
+ while (i < argv.length) {
|
|
|
+ if (clrStorageTypeQuota(argv[i])) {
|
|
|
+ System.out.println("Successfully clear storage type quota for mount"
|
|
|
+ + " point " + argv[i]);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else if ("-safemode".equals(cmd)) {
|
|
|
manageSafeMode(argv[i]);
|
|
|
} else if ("-nameservice".equals(cmd)) {
|
|
@@ -887,6 +917,41 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return updateQuota(mount, nsQuota, ssQuota);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set storage type quota for a mount table entry.
|
|
|
+ *
|
|
|
+ * @param parameters Parameters of the quota.
|
|
|
+ * @param i Index in the parameters.
|
|
|
+ */
|
|
|
+ private boolean setStorageTypeQuota(String[] parameters, int i)
|
|
|
+ throws IOException {
|
|
|
+ long[] typeQuota = new long[StorageType.values().length];
|
|
|
+ eachByStorageType(
|
|
|
+ t -> typeQuota[t.ordinal()] = HdfsConstants.QUOTA_DONT_SET);
|
|
|
+
|
|
|
+ String mount = parameters[i++];
|
|
|
+ if (parameters[i].equals("-storageType")) {
|
|
|
+ i++;
|
|
|
+ StorageType type = StorageType.parseStorageType(parameters[i++]);
|
|
|
+ typeQuota[type.ordinal()] = Long.parseLong(parameters[i]);
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("Invalid argument : " + parameters[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orByStorageType(t -> typeQuota[t.ordinal()] <= 0)) {
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "Input quota value should be a positive number.");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (andByStorageType(
|
|
|
+ t -> typeQuota[t.ordinal()] == HdfsConstants.QUOTA_DONT_SET)) {
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "Must specify at least one of -nsQuota and -ssQuota.");
|
|
|
+ }
|
|
|
+
|
|
|
+ return updateStorageTypeQuota(mount, typeQuota);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Clear quota of the mount point.
|
|
|
*
|
|
@@ -899,6 +964,19 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
HdfsConstants.QUOTA_RESET);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Clear storage type quota of the mount point.
|
|
|
+ *
|
|
|
+ * @param mount Mount table to clear
|
|
|
+ * @return If the quota was cleared.
|
|
|
+ * @throws IOException Error clearing the mount point.
|
|
|
+ */
|
|
|
+ private boolean clrStorageTypeQuota(String mount) throws IOException {
|
|
|
+ long[] typeQuota = new long[StorageType.values().length];
|
|
|
+ eachByStorageType(t -> typeQuota[t.ordinal()] = HdfsConstants.QUOTA_RESET);
|
|
|
+ return updateStorageTypeQuota(mount, typeQuota);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Update quota of specified mount table.
|
|
|
*
|
|
@@ -958,6 +1036,64 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return updateResponse.getStatus();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Update storage type quota of specified mount table.
|
|
|
+ *
|
|
|
+ * @param mount Specified mount table to update.
|
|
|
+ * @param typeQuota Storage type quota.
|
|
|
+ * @return If the quota was updated.
|
|
|
+ * @throws IOException Error updating quota.
|
|
|
+ */
|
|
|
+ private boolean updateStorageTypeQuota(String mount, long[] typeQuota)
|
|
|
+ throws IOException {
|
|
|
+ // Get existing entry
|
|
|
+ MountTableManager mountTable = client.getMountTableManager();
|
|
|
+ GetMountTableEntriesRequest getRequest = GetMountTableEntriesRequest
|
|
|
+ .newInstance(mount);
|
|
|
+ GetMountTableEntriesResponse getResponse = mountTable
|
|
|
+ .getMountTableEntries(getRequest);
|
|
|
+ List<MountTable> results = getResponse.getEntries();
|
|
|
+ MountTable existingEntry = null;
|
|
|
+ for (MountTable result : results) {
|
|
|
+ if (mount.equals(result.getSourcePath())) {
|
|
|
+ existingEntry = result;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (existingEntry == null) {
|
|
|
+ throw new IOException(mount + " doesn't exist in mount table.");
|
|
|
+ } else {
|
|
|
+ final RouterQuotaUsage quotaUsage = existingEntry.getQuota();
|
|
|
+ long[] typeCount = new long[StorageType.values().length];
|
|
|
+ eachByStorageType(
|
|
|
+ t -> typeCount[t.ordinal()] = quotaUsage.getTypeQuota(t));
|
|
|
+ // If all storage type quota were reset, clear the storage type quota.
|
|
|
+ if (andByStorageType(
|
|
|
+ t -> typeQuota[t.ordinal()] == HdfsConstants.QUOTA_RESET)) {
|
|
|
+ eachByStorageType(t -> typeCount[t.ordinal()] =
|
|
|
+ RouterQuotaUsage.QUOTA_USAGE_COUNT_DEFAULT);
|
|
|
+ } else {
|
|
|
+ // If nsQuota or ssQuota was unset, use the value in mount table.
|
|
|
+ eachByStorageType(t -> {
|
|
|
+ if (typeQuota[t.ordinal()] == HdfsConstants.QUOTA_DONT_SET) {
|
|
|
+ typeQuota[t.ordinal()] = quotaUsage.getTypeQuota(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ RouterQuotaUsage updatedQuota = new RouterQuotaUsage.Builder()
|
|
|
+ .typeQuota(typeQuota).typeConsumed(typeCount).build();
|
|
|
+ existingEntry.setQuota(updatedQuota);
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateMountTableEntryRequest updateRequest =
|
|
|
+ UpdateMountTableEntryRequest.newInstance(existingEntry);
|
|
|
+ UpdateMountTableEntryResponse updateResponse = mountTable
|
|
|
+ .updateMountTableEntry(updateRequest);
|
|
|
+ return updateResponse.getStatus();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Manager the safe mode state.
|
|
|
* @param cmd Input command, enter or leave safe mode.
|