From 15dad8bca93980a502df4ba58f612c6bc0eddf54 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 1 Apr 2019 20:51:55 +0200 Subject: [PATCH] Simplify BlobStoreRepository Constructor (#40653) * Thanks to #39346 we can simplify the logic here some more, now that compress is a `final` field --- .../repositories/s3/S3Repository.java | 6 +---- .../blobstore/BlobStoreRepository.java | 22 ++++++++----------- .../repositories/fs/FsRepository.java | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java index 522f15661bd64..f9d6ada5da38f 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java @@ -157,8 +157,6 @@ class S3Repository extends BlobStoreRepository { private final String cannedACL; - private final RepositoryMetaData repositoryMetaData; - /** * Constructs an s3 backed repository */ @@ -169,8 +167,6 @@ class S3Repository extends BlobStoreRepository { super(metadata, settings, namedXContentRegistry); this.service = service; - this.repositoryMetaData = metadata; - // Parse and validate the user's S3 Storage Class setting this.bucket = BUCKET_SETTING.get(metadata.settings()); if (bucket == null) { @@ -216,7 +212,7 @@ class S3Repository extends BlobStoreRepository { @Override protected S3BlobStore createBlobStore() { - return new S3BlobStore(service, bucket, serverSideEncryption, bufferSize, cannedACL, storageClass, repositoryMetaData); + return new S3BlobStore(service, bucket, serverSideEncryption, bufferSize, cannedACL, storageClass, metadata); } // only use for testing diff --git a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java index a73626351d875..6a99cf2eb97f2 100644 --- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java @@ -162,8 +162,6 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp protected final RepositoryMetaData metadata; - protected final NamedXContentRegistry namedXContentRegistry; - private static final int BUFFER_SIZE = 4096; private static final String SNAPSHOT_PREFIX = "snap-"; @@ -213,11 +211,11 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp private final CounterMetric restoreRateLimitingTimeInNanos = new CounterMetric(); - private ChecksumBlobStoreFormat globalMetaDataFormat; + private final ChecksumBlobStoreFormat globalMetaDataFormat; - private ChecksumBlobStoreFormat indexMetaDataFormat; + private final ChecksumBlobStoreFormat indexMetaDataFormat; - private ChecksumBlobStoreFormat snapshotFormat; + private final ChecksumBlobStoreFormat snapshotFormat; private final boolean readOnly; @@ -240,17 +238,21 @@ protected BlobStoreRepository(RepositoryMetaData metadata, Settings settings, NamedXContentRegistry namedXContentRegistry) { this.settings = settings; this.metadata = metadata; - this.namedXContentRegistry = namedXContentRegistry; this.compress = COMPRESS_SETTING.get(metadata.settings()); snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); readOnly = metadata.settings().getAsBoolean("readonly", false); - indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, compress); indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT, BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, compress); + globalMetaDataFormat = new ChecksumBlobStoreFormat<>(METADATA_CODEC, METADATA_NAME_FORMAT, + MetaData::fromXContent, namedXContentRegistry, compress); + indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT, + IndexMetaData::fromXContent, namedXContentRegistry, compress); + snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, + SnapshotInfo::fromXContentInternal, namedXContentRegistry, compress); } @Override @@ -259,12 +261,6 @@ protected void doStart() { if (chunkSize != null && chunkSize.getBytes() <= 0) { throw new IllegalArgumentException("the chunk size cannot be negative: [" + chunkSize + "]"); } - globalMetaDataFormat = new ChecksumBlobStoreFormat<>(METADATA_CODEC, METADATA_NAME_FORMAT, - MetaData::fromXContent, namedXContentRegistry, compress); - indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT, - IndexMetaData::fromXContent, namedXContentRegistry, compress); - snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, - SnapshotInfo::fromXContentInternal, namedXContentRegistry, compress); } @Override diff --git a/server/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java b/server/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java index e3e986c1eca9a..d2a27cc2bb3ef 100644 --- a/server/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java +++ b/server/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java @@ -63,7 +63,7 @@ public class FsRepository extends BlobStoreRepository { new ByteSizeValue(Long.MAX_VALUE), new ByteSizeValue(5), new ByteSizeValue(Long.MAX_VALUE), Property.NodeScope); private final Environment environment; - private ByteSizeValue chunkSize; + private final ByteSizeValue chunkSize; private final BlobPath basePath;