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

Change IOContext from READONCE to DEFAULT to avoid WrongThreadException (#17502) #17544

Merged
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 @@ -460,7 +460,7 @@ private void uploadNewSegments(
batchUploadListener.onFailure(ex);
});
statsListener.beforeUpload(src);
remoteDirectory.copyFrom(storeDirectory, src, IOContext.READONCE, aggregatedListener, isLowPriorityUpload());
remoteDirectory.copyFrom(storeDirectory, src, IOContext.DEFAULT, aggregatedListener, isLowPriorityUpload());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ private void uploadBlob(
ActionListener<Void> listener,
boolean lowPriorityUpload
) throws Exception {
assert ioContext != IOContext.READONCE : "Remote upload will fail with IoContext.READONCE";
long expectedChecksum = calculateChecksumOfChecksum(from, src);
long contentLength;
try (IndexInput indexInput = from.openInput(src, ioContext)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testCopyFrom() throws IOException, InterruptedException {
storeDirectory,
filename,
filename,
IOContext.READ,
IOContext.DEFAULT,
() -> postUploadInvoked.set(true),
new ActionListener<>() {
@Override
Expand Down Expand Up @@ -132,7 +132,7 @@ public void testCopyFromWithException() throws IOException, InterruptedException
storeDirectory,
filename,
filename,
IOContext.READ,
IOContext.DEFAULT,
() -> postUploadInvoked.set(true),
new ActionListener<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@

import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
import org.apache.lucene.tests.store.MockDirectoryWrapper;
Expand Down Expand Up @@ -203,6 +206,19 @@ public synchronized void crash() throws IOException {
public Set<String> getPendingDeletions() throws IOException {
return in.getPendingDeletions();
}

// In remote store feature, the upload flow is async and IndexInput can be opened and closed
// by different threads, so we always use IOContext.DEFAULT.
// But MockDirectoryWrapper throws an exception if segments_N fil is opened with any IOContext other than READONCE.
// Following change is temporary override to avoid the test failures. We should fix the multiple thread access
// in remote store upload flow.
@Override
public synchronized IndexInput openInput(String name, IOContext context) throws IOException {
if (name.startsWith(IndexFileNames.SEGMENTS)) {
context = IOContext.READONCE;
}
return super.openInput(name, context);
}
}

static final class CloseableDirectory implements Closeable {
Expand Down
Loading