codelipenghui commented on a change in pull request #6183: Namespace level
offloader
URL: https://github.com/apache/pulsar/pull/6183#discussion_r373752908
##########
File path:
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java
##########
@@ -1287,6 +1291,106 @@ void run() throws PulsarAdminException {
}
}
+ @Parameters(commandDescription = "Set the offload policies for a
namespace")
+ private class SetOffload extends CliCommand {
+ @Parameter(description = "tenant/namespace", required = true)
+ private java.util.List<String> params;
+
+ @Parameter(
+ names = {"--region", "-r"},
+ description = "The long term storage region, " +
+ "default is s3ManagedLedgerOffloadRegion or
gcsManagedLedgerOffloadRegion in broker.conf",
+ required = false)
+ private String region;
+
+ @Parameter(
+ names = {"--bucket", "-b"},
+ description = "Bucket to place offloaded ledger into",
+ required = true)
+ private String bucket;
+
+ @Parameter(
+ names = {"--endpoint", "-e"},
+ description = "Alternative endpoint to connect to, " +
+ "s3 default is s3ManagedLedgerOffloadServiceEndpoint
in broker.conf",
+ required = false)
+ private String endpoint;
+
+ @Parameter(
+ names = {"--maxBlockSize", "-mbs"},
+ description = "Max block size (eg: 32M, 64M), default is 64MB",
+ required = false)
+ private String maxBlockSizeStr;
+
+ @Parameter(
+ names = {"--readBufferSize", "-rbs"},
+ description = "Read buffer size (eg: 1M, 5M), default is 1MB",
+ required = false)
+ private String readBufferSizeStr;
+
+ private final String[] DRIVER_NAMES = {"S3", "aws-s3",
"google-cloud-storage"};
+
+ public boolean isS3Driver(String driver) {
+ if (StringUtils.isEmpty(driver)) {
+ return false;
+ }
+ return driver.equalsIgnoreCase(DRIVER_NAMES[0]) ||
driver.equalsIgnoreCase(DRIVER_NAMES[1]);
+ }
+
+ @Override
+ void run() throws PulsarAdminException {
+ String namespace = validateNamespace(params);
+
+ String offloadDriver =
admin.brokers().getRuntimeConfigurations().get("managedLedgerOffloadDriver");
+ if (isS3Driver(offloadDriver) && Strings.isNullOrEmpty(region) &&
Strings.isNullOrEmpty(endpoint)) {
+ throw new ParameterException(
+ "Either s3ManagedLedgerOffloadRegion or
s3ManagedLedgerOffloadServiceEndpoint must be set"
+ + " if s3 offload enabled");
+ }
+
+ long maxBlockSize = 0;
+ if (StringUtils.isNotEmpty(maxBlockSizeStr)) {
+ maxBlockSize = validateSizeString(maxBlockSizeStr);
+ }
+ long readBufferSize = 0;
+ if (StringUtils.isNotEmpty(readBufferSizeStr)) {
+ readBufferSize = validateSizeString(readBufferSizeStr);
+ }
+
+ final int maxBlockSizeInBytes;
+ if (maxBlockSize > 0 && maxBlockSize <= Integer.MAX_VALUE) {
+ maxBlockSizeInBytes = new Long(maxBlockSize).intValue();
+ } else {
+ maxBlockSizeInBytes = OffloadPolicies.MAX_BLOCK_SIZE_IN_BYTES;
+ }
+
+ final int readBufferSizeInBytes;
+ if (readBufferSize > 0 && readBufferSize <= Integer.MAX_VALUE) {
+ readBufferSizeInBytes = new Long(readBufferSize).intValue();
+ } else {
+ readBufferSizeInBytes =
OffloadPolicies.READ_BUFFER_SIZE_IN_BYTES;
+ }
Review comment:
I think not correct here, is the MAX_* is limit the max available value? or
a default value. From the logic, it is a default value.
If used for default value, it's better named DEFAULT_BLOCK_SIZE_IN_BYTES and
DEFAULT_READ_BUFFER_SIZE_IN_BYTES.
And we'd better throw exceptions when the blockSize and readBufferSize user
specify is a non-negative value or 0. because offloader can't uses 0 value or a
negative value. If users don't want modify this value, empty maxBlockSizeStr
and readBufferSizeStr is fine.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services