Skip to content
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

[Transform] Do not use PIT in the presence of remote indices in source #99803

Merged
merged 3 commits into from
Sep 22, 2023
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
5 changes: 5 additions & 0 deletions docs/changelog/99803.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 99803
summary: Do not use PIT in the presence of remote indices in source
area: Transform
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected void doNextSearch(long waitTimeInNanos, ActionListener<SearchResponse>

injectPointInTimeIfNeeded(
buildSearchRequest(),
ActionListener.wrap(pitSearchRequest -> doSearch(pitSearchRequest, nextPhase), nextPhase::onFailure)
ActionListener.wrap(searchRequest -> doSearch(searchRequest, nextPhase), nextPhase::onFailure)
);
}

Expand Down Expand Up @@ -435,7 +435,8 @@ private void injectPointInTimeIfNeeded(
ActionListener<Tuple<String, SearchRequest>> listener
) {
SearchRequest searchRequest = namedSearchRequest.v2();
if (disablePit || searchRequest.indices().length == 0) {
// We explicitly disable PIT in the presence of remote clusters in the source due to huge PIT handles causing performance problems.
if (disablePit || searchRequest.indices().length == 0 || transformConfig.getSource().requiresRemoteCluster()) {
listener.onResponse(namedSearchRequest);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.elasticsearch.transport.ActionNotFoundTransportException;
import org.elasticsearch.xpack.core.indexing.IndexerState;
import org.elasticsearch.xpack.core.transform.transforms.SettingsConfig;
import org.elasticsearch.xpack.core.transform.transforms.SourceConfig;
import org.elasticsearch.xpack.core.transform.transforms.TransformCheckpoint;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfigTests;
Expand Down Expand Up @@ -290,6 +291,7 @@ public void testPitInjectionIfPitNotSupported() throws InterruptedException {
}

public void testDisablePit() throws InterruptedException {
// TransformConfigTests.randomTransformConfig never produces remote indices in the source, hence we are safe here. */
TransformConfig config = TransformConfigTests.randomTransformConfig();
boolean pitEnabled = config.getSettings().getUsePit() == null || config.getSettings().getUsePit();

Expand Down Expand Up @@ -349,6 +351,65 @@ public void testDisablePit() throws InterruptedException {
}
}

public void testDisablePitWhenThereIsRemoteIndexInSource() throws InterruptedException {
TransformConfig config = new TransformConfig.Builder(TransformConfigTests.randomTransformConfig())
// Remote index is configured within source
.setSource(new SourceConfig("remote-cluster:remote-index"))
.build();
boolean pitEnabled = config.getSettings().getUsePit() == null || config.getSettings().getUsePit();

try (PitMockClient client = new PitMockClient(getTestName(), true)) {
MockClientTransformIndexer indexer = new MockClientTransformIndexer(
mock(ThreadPool.class),
new TransformServices(
mock(IndexBasedTransformConfigManager.class),
mock(TransformCheckpointService.class),
mock(TransformAuditor.class),
new TransformScheduler(Clock.systemUTC(), mock(ThreadPool.class), Settings.EMPTY)
),
mock(CheckpointProvider.class),
new AtomicReference<>(IndexerState.STOPPED),
null,
client,
mock(TransformIndexerStats.class),
config,
null,
new TransformCheckpoint(
"transform",
Instant.now().toEpochMilli(),
0L,
Collections.emptyMap(),
Instant.now().toEpochMilli()
),
new TransformCheckpoint(
"transform",
Instant.now().toEpochMilli(),
2L,
Collections.emptyMap(),
Instant.now().toEpochMilli()
),
new SeqNoPrimaryTermAndIndex(1, 1, TransformInternalIndexConstants.LATEST_INDEX_NAME),
mock(TransformContext.class),
false
);

// Because remote index is configured within source, we expect PIT *not* being used regardless the transform settings
this.<SearchResponse>assertAsync(
listener -> indexer.doNextSearch(0, listener),
response -> assertNull(response.pointInTimeId())
);

// reverse the setting
indexer.applyNewSettings(new SettingsConfig.Builder().setUsePit(pitEnabled == false).build());

// Because remote index is configured within source, we expect PIT *not* being used regardless the transform settings
this.<SearchResponse>assertAsync(
listener -> indexer.doNextSearch(0, listener),
response -> assertNull(response.pointInTimeId())
);
}
}

public void testHandlePitIndexNotFound() throws InterruptedException {
// simulate a deleted index due to ILM
try (PitMockClient client = new PitMockClient(getTestName(), true)) {
Expand Down