Search in sources :

Example 1 with CloudStorageCompactor

use of com.github.ambry.cloud.CloudStorageCompactor in project ambry by linkedin.

the class AzureCompactionTool method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    ArgumentAcceptingOptionSpec<String> propsFileOpt = parser.accepts(PROPS_FILE, "Properties file path").withRequiredArg().describedAs(PROPS_FILE).ofType(String.class);
    String commandName = AzureCompactionTool.class.getSimpleName();
    parser.accepts(PURGE_OPTION, "Flag to purge dead blobs from the partition");
    parser.nonOptions("The partitions to compact").ofType(String.class);
    OptionSet optionSet = parser.parse(args);
    String propsFilePath = optionSet.valueOf(propsFileOpt);
    if (propsFilePath == null) {
        printHelpAndExit(parser);
    }
    Properties properties = Utils.loadProps(propsFilePath);
    ToolUtils.addClusterMapProperties(properties);
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    // User needs to specify this option to actually delete blobs
    boolean testMode = !optionSet.has(PURGE_OPTION);
    List<String> partitions = (List<String>) optionSet.nonOptionArguments();
    if (!testMode && partitions.isEmpty()) {
        printHelpAndExit(parser);
    }
    Set<PartitionId> partitionIdSet = partitions.stream().map(path -> new PartitionPathId(path)).collect(Collectors.toSet());
    AzureCloudDestination azureDest = null;
    try {
        azureDest = (AzureCloudDestination) new AzureCloudDestinationFactory(verifiableProperties, new MetricRegistry(), null).getCloudDestination();
        CloudConfig cloudConfig = new CloudConfig(verifiableProperties);
        CloudStorageCompactor compactor = new CloudStorageCompactor(azureDest, cloudConfig, partitionIdSet, new VcrMetrics(new MetricRegistry()));
        // Attempt clean shutdown if someone Ctrl-C's us.
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            logger.info("Received shutdown signal. Shutting down compactor.");
            compactor.shutdown();
        }));
        if (testMode) {
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.systemDefault());
            List<Pair<String, Long>> progressList = azureDest.getAzureStorageCompactor().getAllCompactionProgress();
            progressList.forEach(pair -> {
                String progress = dateTimeFormatter.format(Instant.ofEpochMilli(pair.getSecond()));
                // TODO: write to user specified output file
                System.out.println(pair.getFirst() + "\t" + progress);
            });
        } else {
            compactor.compactPartitions();
        }
        System.exit(0);
    } catch (Exception ex) {
        logger.error("Command {} failed", commandName, ex);
        System.exit(1);
    } finally {
        if (azureDest != null) {
            azureDest.close();
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) VcrMetrics(com.github.ambry.cloud.VcrMetrics) CloudConfig(com.github.ambry.config.CloudConfig) JSONObject(org.json.JSONObject) Map(java.util.Map) OptionParser(joptsimple.OptionParser) OptionSet(joptsimple.OptionSet) ReplicaState(com.github.ambry.clustermap.ReplicaState) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) Logger(org.slf4j.Logger) Pair(com.github.ambry.utils.Pair) PartitionState(com.github.ambry.clustermap.PartitionState) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Set(java.util.Set) Utils(com.github.ambry.utils.Utils) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) CloudStorageCompactor(com.github.ambry.cloud.CloudStorageCompactor) ZoneId(java.time.ZoneId) ArgumentAcceptingOptionSpec(joptsimple.ArgumentAcceptingOptionSpec) ToolUtils(com.github.ambry.tools.util.ToolUtils) List(java.util.List) ReplicaId(com.github.ambry.clustermap.ReplicaId) DateTimeFormatter(java.time.format.DateTimeFormatter) PartitionId(com.github.ambry.clustermap.PartitionId) VcrMetrics(com.github.ambry.cloud.VcrMetrics) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) CloudConfig(com.github.ambry.config.CloudConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) PartitionId(com.github.ambry.clustermap.PartitionId) OptionParser(joptsimple.OptionParser) IOException(java.io.IOException) CloudStorageCompactor(com.github.ambry.cloud.CloudStorageCompactor) List(java.util.List) OptionSet(joptsimple.OptionSet) DateTimeFormatter(java.time.format.DateTimeFormatter) Pair(com.github.ambry.utils.Pair)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 CloudStorageCompactor (com.github.ambry.cloud.CloudStorageCompactor)1 VcrMetrics (com.github.ambry.cloud.VcrMetrics)1 PartitionId (com.github.ambry.clustermap.PartitionId)1 PartitionState (com.github.ambry.clustermap.PartitionState)1 ReplicaId (com.github.ambry.clustermap.ReplicaId)1 ReplicaState (com.github.ambry.clustermap.ReplicaState)1 CloudConfig (com.github.ambry.config.CloudConfig)1 VerifiableProperties (com.github.ambry.config.VerifiableProperties)1 ToolUtils (com.github.ambry.tools.util.ToolUtils)1 Pair (com.github.ambry.utils.Pair)1 Utils (com.github.ambry.utils.Utils)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1