Skip to content

Commit 15dad8b

Browse files
Simplify BlobStoreRepository Constructor (#40653)
* Thanks to #39346 we can simplify the logic here some more, now that compress is a `final` field
1 parent cb9b4a8 commit 15dad8b

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ class S3Repository extends BlobStoreRepository {
157157

158158
private final String cannedACL;
159159

160-
private final RepositoryMetaData repositoryMetaData;
161-
162160
/**
163161
* Constructs an s3 backed repository
164162
*/
@@ -169,8 +167,6 @@ class S3Repository extends BlobStoreRepository {
169167
super(metadata, settings, namedXContentRegistry);
170168
this.service = service;
171169

172-
this.repositoryMetaData = metadata;
173-
174170
// Parse and validate the user's S3 Storage Class setting
175171
this.bucket = BUCKET_SETTING.get(metadata.settings());
176172
if (bucket == null) {
@@ -216,7 +212,7 @@ class S3Repository extends BlobStoreRepository {
216212

217213
@Override
218214
protected S3BlobStore createBlobStore() {
219-
return new S3BlobStore(service, bucket, serverSideEncryption, bufferSize, cannedACL, storageClass, repositoryMetaData);
215+
return new S3BlobStore(service, bucket, serverSideEncryption, bufferSize, cannedACL, storageClass, metadata);
220216
}
221217

222218
// only use for testing

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
162162

163163
protected final RepositoryMetaData metadata;
164164

165-
protected final NamedXContentRegistry namedXContentRegistry;
166-
167165
private static final int BUFFER_SIZE = 4096;
168166

169167
private static final String SNAPSHOT_PREFIX = "snap-";
@@ -213,11 +211,11 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
213211

214212
private final CounterMetric restoreRateLimitingTimeInNanos = new CounterMetric();
215213

216-
private ChecksumBlobStoreFormat<MetaData> globalMetaDataFormat;
214+
private final ChecksumBlobStoreFormat<MetaData> globalMetaDataFormat;
217215

218-
private ChecksumBlobStoreFormat<IndexMetaData> indexMetaDataFormat;
216+
private final ChecksumBlobStoreFormat<IndexMetaData> indexMetaDataFormat;
219217

220-
private ChecksumBlobStoreFormat<SnapshotInfo> snapshotFormat;
218+
private final ChecksumBlobStoreFormat<SnapshotInfo> snapshotFormat;
221219

222220
private final boolean readOnly;
223221

@@ -240,17 +238,21 @@ protected BlobStoreRepository(RepositoryMetaData metadata, Settings settings,
240238
NamedXContentRegistry namedXContentRegistry) {
241239
this.settings = settings;
242240
this.metadata = metadata;
243-
this.namedXContentRegistry = namedXContentRegistry;
244241
this.compress = COMPRESS_SETTING.get(metadata.settings());
245242
snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
246243
restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
247244
readOnly = metadata.settings().getAsBoolean("readonly", false);
248245

249-
250246
indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT,
251247
BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, compress);
252248
indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT,
253249
BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, compress);
250+
globalMetaDataFormat = new ChecksumBlobStoreFormat<>(METADATA_CODEC, METADATA_NAME_FORMAT,
251+
MetaData::fromXContent, namedXContentRegistry, compress);
252+
indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT,
253+
IndexMetaData::fromXContent, namedXContentRegistry, compress);
254+
snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT,
255+
SnapshotInfo::fromXContentInternal, namedXContentRegistry, compress);
254256
}
255257

256258
@Override
@@ -259,12 +261,6 @@ protected void doStart() {
259261
if (chunkSize != null && chunkSize.getBytes() <= 0) {
260262
throw new IllegalArgumentException("the chunk size cannot be negative: [" + chunkSize + "]");
261263
}
262-
globalMetaDataFormat = new ChecksumBlobStoreFormat<>(METADATA_CODEC, METADATA_NAME_FORMAT,
263-
MetaData::fromXContent, namedXContentRegistry, compress);
264-
indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT,
265-
IndexMetaData::fromXContent, namedXContentRegistry, compress);
266-
snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT,
267-
SnapshotInfo::fromXContentInternal, namedXContentRegistry, compress);
268264
}
269265

270266
@Override

server/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class FsRepository extends BlobStoreRepository {
6363
new ByteSizeValue(Long.MAX_VALUE), new ByteSizeValue(5), new ByteSizeValue(Long.MAX_VALUE), Property.NodeScope);
6464
private final Environment environment;
6565

66-
private ByteSizeValue chunkSize;
66+
private final ByteSizeValue chunkSize;
6767

6868
private final BlobPath basePath;
6969

0 commit comments

Comments
 (0)