Skip to content

[7.12] Take into account base_path setting during repository analysis execution #69718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.blobstore.DeleteResult;
import org.elasticsearch.common.blobstore.support.PlainBlobMetadata;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
Expand Down Expand Up @@ -51,6 +52,7 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.nullValue;
Expand All @@ -59,6 +61,8 @@
@ESIntegTestCase.ClusterScope(transportClientRatio = 0)
public class RepositoryAnalysisSuccessIT extends AbstractSnapshotIntegTestCase {

private static final String BASE_PATH_SETTING_KEY = "base_path";

@Before
public void suppressConsistencyChecks() {
disableRepoConsistencyCheck("repository is not used for snapshots");
Expand All @@ -75,9 +79,16 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {

public void testRepositoryAnalysis() {

createRepositoryNoVerify("test-repo", TestPlugin.ASSERTING_REPO_TYPE);
final Settings.Builder settings = Settings.builder();
if (randomBoolean()) {
settings.put(BASE_PATH_SETTING_KEY, randomAlphaOfLength(10));
}

assertAcked(
clusterAdmin().preparePutRepository("test-repo").setVerify(false).setType(TestPlugin.ASSERTING_REPO_TYPE).setSettings(settings)
);

final AssertingBlobStore blobStore = new AssertingBlobStore();
final AssertingBlobStore blobStore = new AssertingBlobStore(settings.get(BASE_PATH_SETTING_KEY));
for (final RepositoriesService repositoriesService : internalCluster().getInstances(RepositoriesService.class)) {
try {
((AssertingRepository) repositoriesService.repository("test-repo")).setBlobStore(blobStore);
Expand Down Expand Up @@ -140,12 +151,21 @@ public Map<String, Repository.Factory> getRepositories(
clusterService,
bigArrays,
recoverySettings,
new BlobPath()
buildBlobPath(metadata.settings())
)
);
}
}

private static BlobPath buildBlobPath(Settings settings) {
final String basePath = settings.get(BASE_PATH_SETTING_KEY);
if (basePath == null) {
return BlobPath.cleanPath();
} else {
return BlobPath.cleanPath().add(basePath);
}
}

static class AssertingRepository extends BlobStoreRepository {

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

static class AssertingBlobStore implements BlobStore {
private final String pathPrefix;

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

AssertingBlobStore(@Nullable String basePath) {
this.pathPrefix = basePath == null ? "" : basePath + "/";
}

@Override
public BlobContainer blobContainer(BlobPath path) {
assertThat(path.buildAsString(), startsWith("temp-analysis-"));
assertThat(path.buildAsString(), startsWith(pathPrefix + "temp-analysis-"));

synchronized (this) {
if (currentPath == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
throw new IllegalArgumentException("repository [" + request.getRepositoryName() + "] is read-only");
}
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(new BlobPath().add(request.blobPath));
final BlobPath path = blobStoreRepository.basePath().add(request.blobPath);
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(path);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -85,7 +84,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
}

final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(new BlobPath().add(request.getBlobPath()));
final BlobContainer blobContainer = blobStoreRepository.blobStore()
.blobContainer(blobStoreRepository.basePath().add(request.getBlobPath()));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.blobstore.BlobMetadata;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -525,7 +524,7 @@ public BlobAnalyzeAction.Response read(StreamInput in) throws IOException {
}

private BlobContainer getBlobContainer() {
return repository.blobStore().blobContainer(new BlobPath().add(blobPath));
return repository.blobStore().blobContainer(repository.basePath().add(blobPath));
}

private void onWorkerCompletion() {
Expand Down