Search in sources :

Example 6 with VcrMetrics

use of com.github.ambry.cloud.VcrMetrics 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)6 VcrMetrics (com.github.ambry.cloud.VcrMetrics)6 CloudBlobMetadata (com.github.ambry.cloud.CloudBlobMetadata)3 PartitionId (com.github.ambry.clustermap.PartitionId)3 BlobId (com.github.ambry.commons.BlobId)3 CloudConfig (com.github.ambry.config.CloudConfig)3 VerifiableProperties (com.github.ambry.config.VerifiableProperties)3 Before (org.junit.Before)3 ClusterMap (com.github.ambry.clustermap.ClusterMap)2 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)2 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)2 Document (com.microsoft.azure.cosmosdb.Document)2 RequestOptions (com.microsoft.azure.cosmosdb.RequestOptions)2 AsyncDocumentClient (com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)1 BlobBatch (com.azure.storage.blob.batch.BlobBatch)1 BlobBatchClient (com.azure.storage.blob.batch.BlobBatchClient)1 CloudRequestAgent (com.github.ambry.cloud.CloudRequestAgent)1