Skip to content

Commit 9ee35f8

Browse files
authored
Take into account base_path setting during repository analysis execution. (#69717)
Relates #67247 Backport of #69690
1 parent 915e1c2 commit 9ee35f8

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

x-pack/plugin/snapshot-repo-test-kit/src/internalClusterTest/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalysisSuccessIT.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.blobstore.DeleteResult;
1818
import org.elasticsearch.common.blobstore.support.PlainBlobMetadata;
1919
import org.elasticsearch.common.bytes.BytesReference;
20+
import org.elasticsearch.common.settings.Settings;
2021
import org.elasticsearch.common.unit.ByteSizeValue;
2122
import org.elasticsearch.common.unit.TimeValue;
2223
import org.elasticsearch.common.util.BigArrays;
@@ -51,6 +52,7 @@
5152
import java.util.function.Consumer;
5253
import java.util.stream.Collectors;
5354

55+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5456
import static org.hamcrest.Matchers.equalTo;
5557
import static org.hamcrest.Matchers.lessThanOrEqualTo;
5658
import static org.hamcrest.Matchers.nullValue;
@@ -59,6 +61,8 @@
5961
@ESIntegTestCase.ClusterScope(transportClientRatio = 0)
6062
public class RepositoryAnalysisSuccessIT extends AbstractSnapshotIntegTestCase {
6163

64+
private static final String BASE_PATH_SETTING_KEY = "base_path";
65+
6266
@Before
6367
public void suppressConsistencyChecks() {
6468
disableRepoConsistencyCheck("repository is not used for snapshots");
@@ -75,9 +79,16 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
7579

7680
public void testRepositoryAnalysis() {
7781

78-
createRepositoryNoVerify("test-repo", TestPlugin.ASSERTING_REPO_TYPE);
82+
final Settings.Builder settings = Settings.builder();
83+
if (randomBoolean()) {
84+
settings.put(BASE_PATH_SETTING_KEY, randomAlphaOfLength(10));
85+
}
86+
87+
assertAcked(
88+
clusterAdmin().preparePutRepository("test-repo").setVerify(false).setType(TestPlugin.ASSERTING_REPO_TYPE).setSettings(settings)
89+
);
7990

80-
final AssertingBlobStore blobStore = new AssertingBlobStore();
91+
final AssertingBlobStore blobStore = new AssertingBlobStore(settings.get(BASE_PATH_SETTING_KEY));
8192
for (final RepositoriesService repositoriesService : internalCluster().getInstances(RepositoriesService.class)) {
8293
try {
8394
((AssertingRepository) repositoriesService.repository("test-repo")).setBlobStore(blobStore);
@@ -140,12 +151,21 @@ public Map<String, Repository.Factory> getRepositories(
140151
clusterService,
141152
bigArrays,
142153
recoverySettings,
143-
new BlobPath()
154+
buildBlobPath(metadata.settings())
144155
)
145156
);
146157
}
147158
}
148159

160+
private static BlobPath buildBlobPath(Settings settings) {
161+
final String basePath = settings.get(BASE_PATH_SETTING_KEY);
162+
if (basePath == null) {
163+
return BlobPath.cleanPath();
164+
} else {
165+
return BlobPath.cleanPath().add(basePath);
166+
}
167+
}
168+
149169
static class AssertingRepository extends BlobStoreRepository {
150170

151171
private final AtomicReference<BlobStore> blobStoreRef = new AtomicReference<>();
@@ -181,6 +201,7 @@ public BlobPath basePath() {
181201
}
182202

183203
static class AssertingBlobStore implements BlobStore {
204+
private final String pathPrefix;
184205

185206
@Nullable // if no current blob container
186207
private String currentPath;
@@ -193,9 +214,13 @@ static class AssertingBlobStore implements BlobStore {
193214
private long maxBlobSize = new RepositoryAnalyzeAction.Request("dummy").getMaxBlobSize().getBytes();
194215
private long maxTotalBlobSize = new RepositoryAnalyzeAction.Request("dummy").getMaxTotalDataSize().getBytes();
195216

217+
AssertingBlobStore(@Nullable String basePath) {
218+
this.pathPrefix = basePath == null ? "" : basePath + "/";
219+
}
220+
196221
@Override
197222
public BlobContainer blobContainer(BlobPath path) {
198-
assertThat(path.buildAsString(), startsWith("temp-analysis-"));
223+
assertThat(path.buildAsString(), startsWith(pathPrefix + "temp-analysis-"));
199224

200225
synchronized (this) {
201226
if (currentPath == null) {

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/BlobAnalyzeAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
178178
throw new IllegalArgumentException("repository [" + request.getRepositoryName() + "] is read-only");
179179
}
180180
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
181-
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(new BlobPath().add(request.blobPath));
181+
final BlobPath path = blobStoreRepository.basePath().add(request.blobPath);
182+
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(path);
182183

183184
logger.trace("handling [{}]", request);
184185

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/GetBlobChecksumAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.action.support.ActionFilters;
1818
import org.elasticsearch.action.support.HandledTransportAction;
1919
import org.elasticsearch.common.blobstore.BlobContainer;
20-
import org.elasticsearch.common.blobstore.BlobPath;
2120
import org.elasticsearch.common.inject.Inject;
2221
import org.elasticsearch.common.io.stream.StreamInput;
2322
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -85,7 +84,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
8584
}
8685

8786
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
88-
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(new BlobPath().add(request.getBlobPath()));
87+
final BlobContainer blobContainer = blobStoreRepository.blobStore()
88+
.blobContainer(blobStoreRepository.basePath().add(request.getBlobPath()));
8989

9090
logger.trace("handling [{}]", request);
9191

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.elasticsearch.common.UUIDs;
3030
import org.elasticsearch.common.blobstore.BlobContainer;
3131
import org.elasticsearch.common.blobstore.BlobMetadata;
32-
import org.elasticsearch.common.blobstore.BlobPath;
3332
import org.elasticsearch.common.inject.Inject;
3433
import org.elasticsearch.common.io.stream.StreamInput;
3534
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -525,7 +524,7 @@ public BlobAnalyzeAction.Response read(StreamInput in) throws IOException {
525524
}
526525

527526
private BlobContainer getBlobContainer() {
528-
return repository.blobStore().blobContainer(new BlobPath().add(blobPath));
527+
return repository.blobStore().blobContainer(repository.basePath().add(blobPath));
529528
}
530529

531530
private void onWorkerCompletion() {

0 commit comments

Comments
 (0)