HADOOP-15215 s3guard set-capacity command to fail on read/write of 0 (Gabor Bota)
This commit is contained in:
parent
c0ef7e7680
commit
93ac01cb59
|
@ -439,6 +439,10 @@ public abstract class S3GuardTool extends Configured implements Tool {
|
|||
static class SetCapacity extends S3GuardTool {
|
||||
public static final String NAME = "set-capacity";
|
||||
public static final String PURPOSE = "Alter metadata store IO capacity";
|
||||
public static final String READ_CAP_INVALID = "Read capacity must have "
|
||||
+ "value greater than or equal to 1.";
|
||||
public static final String WRITE_CAP_INVALID = "Write capacity must have "
|
||||
+ "value greater than or equal to 1.";
|
||||
private static final String USAGE = NAME + " [OPTIONS] [s3a://BUCKET]\n" +
|
||||
"\t" + PURPOSE + "\n\n" +
|
||||
"Common options:\n" +
|
||||
|
@ -478,11 +482,17 @@ public abstract class S3GuardTool extends Configured implements Tool {
|
|||
|
||||
String readCap = getCommandFormat().getOptValue(READ_FLAG);
|
||||
if (StringUtils.isNotEmpty(readCap)) {
|
||||
Preconditions.checkArgument(Integer.parseInt(readCap) > 0,
|
||||
READ_CAP_INVALID);
|
||||
|
||||
S3GuardTool.println(out, "Read capacity set to %s", readCap);
|
||||
options.put(S3GUARD_DDB_TABLE_CAPACITY_READ_KEY, readCap);
|
||||
}
|
||||
String writeCap = getCommandFormat().getOptValue(WRITE_FLAG);
|
||||
if (StringUtils.isNotEmpty(writeCap)) {
|
||||
Preconditions.checkArgument(Integer.parseInt(writeCap) > 0,
|
||||
WRITE_CAP_INVALID);
|
||||
|
||||
S3GuardTool.println(out, "Write capacity set to %s", writeCap);
|
||||
options.put(S3GUARD_DDB_TABLE_CAPACITY_WRITE_KEY, writeCap);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.apache.hadoop.io.IOUtils;
|
|||
import org.apache.hadoop.util.ExitUtil;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
|
||||
import static org.apache.hadoop.fs.s3a.Constants.S3GUARD_DDB_TABLE_NAME_KEY;
|
||||
import static org.apache.hadoop.fs.s3a.Constants.S3GUARD_METASTORE_NULL;
|
||||
import static org.apache.hadoop.fs.s3a.Constants.S3_METADATA_STORE_IMPL;
|
||||
import static org.apache.hadoop.fs.s3a.s3guard.S3GuardTool.E_BAD_STATE;
|
||||
|
@ -286,6 +287,23 @@ public abstract class AbstractS3GuardToolTestBase extends AbstractS3ATestBase {
|
|||
"prune", testPath.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCapacityFailFast() throws Exception{
|
||||
Configuration conf = getConfiguration();
|
||||
conf.set(S3GUARD_DDB_TABLE_NAME_KEY, getFileSystem().getBucket());
|
||||
|
||||
S3GuardTool.SetCapacity cmdR = new S3GuardTool.SetCapacity(conf);
|
||||
String[] argsR = new String[]{cmdR.getName(), "-read", "0", "s3a://bucket"};
|
||||
intercept(IllegalArgumentException.class,
|
||||
S3GuardTool.SetCapacity.READ_CAP_INVALID, () -> cmdR.run(argsR));
|
||||
|
||||
S3GuardTool.SetCapacity cmdW = new S3GuardTool.SetCapacity(conf);
|
||||
String[] argsW = new String[]{cmdW.getName(), "-write", "0",
|
||||
"s3a://bucket"};
|
||||
intercept(IllegalArgumentException.class,
|
||||
S3GuardTool.SetCapacity.WRITE_CAP_INVALID, () -> cmdW.run(argsW));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroyNoBucket() throws Throwable {
|
||||
intercept(FileNotFoundException.class,
|
||||
|
|
Loading…
Reference in New Issue