Skip to content

Commit 06ad2af

Browse files
Unify blob store compress setting
Blob store compression was all implemented generally, except reading the setting for it. Moved the setting to BlobStoreRepository to unify this. Also removed deprecated env setting 'repositories.fs.compress'. This is a follow up on elastic#39073
1 parent ed20d7c commit 06ad2af

File tree

9 files changed

+24
-55
lines changed

9 files changed

+24
-55
lines changed

modules/repository-url/src/main/java/org/elasticsearch/repositories/url/URLRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class URLRepository extends BlobStoreRepository {
8383
*/
8484
public URLRepository(RepositoryMetaData metadata, Environment environment,
8585
NamedXContentRegistry namedXContentRegistry) {
86-
super(metadata, environment.settings(), false, namedXContentRegistry);
86+
super(metadata, environment.settings(), namedXContentRegistry);
8787

8888
if (URL_SETTING.exists(metadata.settings()) == false && REPOSITORIES_URL_SETTING.exists(environment.settings()) == false) {
8989
throw new RepositoryException(metadata.name(), "missing url");

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepository.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,18 @@ public static final class Repository {
7575
s -> LocationMode.PRIMARY_ONLY.toString(), s -> LocationMode.valueOf(s.toUpperCase(Locale.ROOT)), Property.NodeScope);
7676
public static final Setting<ByteSizeValue> CHUNK_SIZE_SETTING =
7777
Setting.byteSizeSetting("chunk_size", MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, MAX_CHUNK_SIZE, Property.NodeScope);
78-
public static final Setting<Boolean> COMPRESS_SETTING = Setting.boolSetting("compress", false, Property.NodeScope);
7978
public static final Setting<Boolean> READONLY_SETTING = Setting.boolSetting("readonly", false, Property.NodeScope);
8079
}
8180

8281
private final BlobPath basePath;
8382
private final ByteSizeValue chunkSize;
84-
private final Environment environment;
8583
private final AzureStorageService storageService;
8684
private final boolean readonly;
8785

8886
public AzureRepository(RepositoryMetaData metadata, Environment environment, NamedXContentRegistry namedXContentRegistry,
8987
AzureStorageService storageService) {
90-
super(metadata, environment.settings(), Repository.COMPRESS_SETTING.get(metadata.settings()), namedXContentRegistry);
88+
super(metadata, environment.settings(), namedXContentRegistry);
9189
this.chunkSize = Repository.CHUNK_SIZE_SETTING.get(metadata.settings());
92-
this.environment = environment;
9390
this.storageService = storageService;
9491

9592
final String basePath = Strings.trimLeadingCharacter(Repository.BASE_PATH_SETTING.get(metadata.settings()), '/');

plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageRepository.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.common.Strings;
2626
import org.elasticsearch.common.blobstore.BlobPath;
2727
import org.elasticsearch.common.settings.Setting;
28-
import org.elasticsearch.common.settings.Settings;
2928
import org.elasticsearch.common.unit.ByteSizeUnit;
3029
import org.elasticsearch.common.unit.ByteSizeValue;
3130
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@@ -36,7 +35,6 @@
3635
import java.util.function.Function;
3736

3837
import static org.elasticsearch.common.settings.Setting.Property;
39-
import static org.elasticsearch.common.settings.Setting.boolSetting;
4038
import static org.elasticsearch.common.settings.Setting.byteSizeSetting;
4139
import static org.elasticsearch.common.settings.Setting.simpleString;
4240

@@ -53,13 +51,10 @@ class GoogleCloudStorageRepository extends BlobStoreRepository {
5351
simpleString("bucket", Property.NodeScope, Property.Dynamic);
5452
static final Setting<String> BASE_PATH =
5553
simpleString("base_path", Property.NodeScope, Property.Dynamic);
56-
static final Setting<Boolean> COMPRESS =
57-
boolSetting("compress", false, Property.NodeScope, Property.Dynamic);
5854
static final Setting<ByteSizeValue> CHUNK_SIZE =
5955
byteSizeSetting("chunk_size", MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, MAX_CHUNK_SIZE, Property.NodeScope, Property.Dynamic);
6056
static final Setting<String> CLIENT_NAME = new Setting<>("client", "default", Function.identity());
6157

62-
private final Settings settings;
6358
private final GoogleCloudStorageService storageService;
6459
private final BlobPath basePath;
6560
private final ByteSizeValue chunkSize;
@@ -69,8 +64,7 @@ class GoogleCloudStorageRepository extends BlobStoreRepository {
6964
GoogleCloudStorageRepository(RepositoryMetaData metadata, Environment environment,
7065
NamedXContentRegistry namedXContentRegistry,
7166
GoogleCloudStorageService storageService) {
72-
super(metadata, environment.settings(), getSetting(COMPRESS, metadata), namedXContentRegistry);
73-
this.settings = environment.settings();
67+
super(metadata, environment.settings(), namedXContentRegistry);
7468
this.storageService = storageService;
7569

7670
String basePath = BASE_PATH.get(metadata.settings());

plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public final class HdfsRepository extends BlobStoreRepository {
6868

6969
public HdfsRepository(RepositoryMetaData metadata, Environment environment,
7070
NamedXContentRegistry namedXContentRegistry) {
71-
super(metadata, environment.settings(), metadata.settings().getAsBoolean("compress", false), namedXContentRegistry);
71+
super(metadata, environment.settings(), namedXContentRegistry);
7272

7373
this.environment = environment;
7474
this.chunkSize = metadata.settings().getAsBytesSize("chunk_size", null);

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ class S3Repository extends BlobStoreRepository {
122122
static final Setting<ByteSizeValue> CHUNK_SIZE_SETTING = Setting.byteSizeSetting("chunk_size", new ByteSizeValue(1, ByteSizeUnit.GB),
123123
new ByteSizeValue(5, ByteSizeUnit.MB), new ByteSizeValue(5, ByteSizeUnit.TB));
124124

125-
/**
126-
* When set to true metadata files are stored in compressed format. This setting doesn’t affect index
127-
* files that are already compressed by default. Defaults to false.
128-
*/
129-
static final Setting<Boolean> COMPRESS_SETTING = Setting.boolSetting("compress", false);
130-
131125
/**
132126
* Sets the S3 storage class type for the backup files. Values may be standard, reduced_redundancy,
133127
* standard_ia. Defaults to standard.
@@ -172,7 +166,7 @@ class S3Repository extends BlobStoreRepository {
172166
final Settings settings,
173167
final NamedXContentRegistry namedXContentRegistry,
174168
final S3Service service) {
175-
super(metadata, settings, COMPRESS_SETTING.get(metadata.settings()), namedXContentRegistry);
169+
super(metadata, settings, namedXContentRegistry);
176170
this.service = service;
177171

178172
this.repositoryMetaData = metadata;

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ public void apply(Settings value, Settings current, Settings previous) {
199199
FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING,
200200
FilterAllocationDecider.CLUSTER_ROUTING_REQUIRE_GROUP_SETTING,
201201
FsRepository.REPOSITORIES_CHUNK_SIZE_SETTING,
202-
FsRepository.REPOSITORIES_COMPRESS_SETTING,
203202
FsRepository.REPOSITORIES_LOCATION_SETTING,
204203
IndicesQueryCache.INDICES_CACHE_QUERY_SIZE_SETTING,
205204
IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.elasticsearch.common.lucene.Lucene;
5757
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
5858
import org.elasticsearch.common.metrics.CounterMetric;
59+
import org.elasticsearch.common.settings.Setting;
5960
import org.elasticsearch.common.settings.Settings;
6061
import org.elasticsearch.common.unit.ByteSizeUnit;
6162
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -193,6 +194,13 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
193194

194195
private static final String DATA_BLOB_PREFIX = "__";
195196

197+
/**
198+
* When set to true metadata files are stored in compressed format. This setting doesn’t affect index
199+
* files that are already compressed by default. Changing the setting does not invalidate existing files since reads
200+
* do not observe the setting, instead they examine the file to see if it is compressed or not.
201+
*/
202+
public static final Setting<Boolean> COMPRESS_SETTING = Setting.boolSetting("compress", false, Setting.Property.NodeScope);
203+
196204
private final Settings settings;
197205

198206
private final boolean compress;
@@ -225,17 +233,15 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
225233

226234
/**
227235
* Constructs new BlobStoreRepository
228-
*
229-
* @param metadata The metadata for this repository including name and settings
236+
* @param metadata The metadata for this repository including name and settings
230237
* @param settings Settings for the node this repository object is created on
231-
* @param compress true if metadata and snapshot files should be compressed
232238
*/
233-
protected BlobStoreRepository(RepositoryMetaData metadata, Settings settings, boolean compress,
239+
protected BlobStoreRepository(RepositoryMetaData metadata, Settings settings,
234240
NamedXContentRegistry namedXContentRegistry) {
235241
this.settings = settings;
236-
this.compress = compress;
237242
this.metadata = metadata;
238243
this.namedXContentRegistry = namedXContentRegistry;
244+
this.compress = COMPRESS_SETTING.get(metadata.settings());
239245
snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
240246
restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
241247
readOnly = metadata.settings().getAsBoolean("readonly", false);

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public class FsRepository extends BlobStoreRepository {
6161
new ByteSizeValue(Long.MAX_VALUE), new ByteSizeValue(5), new ByteSizeValue(Long.MAX_VALUE), Property.NodeScope);
6262
public static final Setting<ByteSizeValue> REPOSITORIES_CHUNK_SIZE_SETTING = Setting.byteSizeSetting("repositories.fs.chunk_size",
6363
new ByteSizeValue(Long.MAX_VALUE), new ByteSizeValue(5), new ByteSizeValue(Long.MAX_VALUE), Property.NodeScope);
64-
public static final Setting<Boolean> COMPRESS_SETTING = Setting.boolSetting("compress", false, Property.NodeScope);
65-
public static final Setting<Boolean> REPOSITORIES_COMPRESS_SETTING =
66-
Setting.boolSetting("repositories.fs.compress", false, Property.NodeScope, Property.Deprecated);
6764
private final Environment environment;
6865

6966
private ByteSizeValue chunkSize;
@@ -75,7 +72,7 @@ public class FsRepository extends BlobStoreRepository {
7572
*/
7673
public FsRepository(RepositoryMetaData metadata, Environment environment,
7774
NamedXContentRegistry namedXContentRegistry) {
78-
super(metadata, environment.settings(), calculateCompress(metadata, environment), namedXContentRegistry);
75+
super(metadata, environment.settings(), namedXContentRegistry);
7976
this.environment = environment;
8077
String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings());
8178
if (location.isEmpty()) {
@@ -106,11 +103,6 @@ public FsRepository(RepositoryMetaData metadata, Environment environment,
106103
this.basePath = BlobPath.cleanPath();
107104
}
108105

109-
private static boolean calculateCompress(RepositoryMetaData metadata, Environment environment) {
110-
return COMPRESS_SETTING.exists(metadata.settings())
111-
? COMPRESS_SETTING.get(metadata.settings()) : REPOSITORIES_COMPRESS_SETTING.get(environment.settings());
112-
}
113-
114106
@Override
115107
protected BlobStore createBlobStore() throws Exception {
116108
final String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings());

server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryTests.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
2323
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2424
import org.elasticsearch.client.Client;
25-
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
2625
import org.elasticsearch.common.UUIDs;
2726
import org.elasticsearch.common.settings.Settings;
2827
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -248,40 +247,28 @@ public void testBadChunksize() throws Exception {
248247
.get());
249248
}
250249

251-
public void testFsRepositoryCompressDeprecated() {
252-
final Path location = ESIntegTestCase.randomRepoPath(node().settings());
253-
final Settings settings = Settings.builder().put(node().settings()).put("location", location).build();
254-
final RepositoryMetaData metaData = new RepositoryMetaData("test-repo", REPO_TYPE, settings);
255-
256-
Settings useCompressSettings = Settings.builder()
257-
.put(node().getEnvironment().settings())
258-
.put(FsRepository.REPOSITORIES_COMPRESS_SETTING.getKey(), true)
259-
.build();
260-
Environment useCompressEnvironment =
261-
new Environment(useCompressSettings, node().getEnvironment().configFile());
262-
263-
new FsRepository(metaData, useCompressEnvironment, null);
264-
265-
assertWarnings("[repositories.fs.compress] setting was deprecated in Elasticsearch and will be removed in a future release!" +
266-
" See the breaking changes documentation for the next major version.");
267-
}
268-
269250
private BlobStoreRepository setupRepo() {
270251
final Client client = client();
271252
final Path location = ESIntegTestCase.randomRepoPath(node().settings());
272253
final String repositoryName = "test-repo";
273254

255+
Settings.Builder repoSettings = Settings.builder().put(node().settings()).put("location", location);
256+
boolean compress = randomBoolean();
257+
if (compress) {
258+
repoSettings.put(BlobStoreRepository.COMPRESS_SETTING.getKey(), true);
259+
}
274260
AcknowledgedResponse putRepositoryResponse =
275261
client.admin().cluster().preparePutRepository(repositoryName)
276262
.setType(REPO_TYPE)
277-
.setSettings(Settings.builder().put(node().settings()).put("location", location))
263+
.setSettings(repoSettings)
278264
.get();
279265
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
280266

281267
final RepositoriesService repositoriesService = getInstanceFromNode(RepositoriesService.class);
282268
final BlobStoreRepository repository =
283269
(BlobStoreRepository) repositoriesService.repository(repositoryName);
284270
assertThat("getBlobContainer has to be lazy initialized", repository.getBlobContainer(), nullValue());
271+
assertEquals("Compress must be set to", compress, repository.isCompress());
285272
return repository;
286273
}
287274

0 commit comments

Comments
 (0)