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

Optimize read write lock constructs during translog upload to remote store #9636

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -292,6 +292,17 @@ private boolean prepareForUpload(Long generation) throws IOException {
}
}

/**
* This method does the remote store upload by first acquiring the lock on the uploadMutex monitor. The synchronized
* is required to restrict multiple uploads happening concurrently. The read lock is required to ensure that the
* underlying translog readers are not deleted and the current writer is not converted to a reader at the time of
* upload.
*
* @param primaryTerm current primary term
* @param generation current generation
* @return true if upload is successful
* @throws IOException if the upload fails due to any underlying exceptions.
*/
private boolean performUpload(Long primaryTerm, Long generation) throws IOException {
synchronized (uploadMutex) {
try (Releasable ignored = readLock.acquire()) {
Expand Down Expand Up @@ -362,10 +373,8 @@ private boolean syncToDisk() throws IOException {
@Override
public void sync() throws IOException {
try {
if (syncToDisk() || syncNeeded()) {
if (prepareForUpload(null)) {
performUpload(primaryTermSupplier.getAsLong(), null);
}
if (syncToDisk() || syncNeeded() || prepareForUpload(null)) {
ashking94 marked this conversation as resolved.
Show resolved Hide resolved
performUpload(primaryTermSupplier.getAsLong(), null);
}
} catch (final Exception e) {
tragedy.setTragicException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

import org.opensearch.index.translog.transfer.TransferSnapshot;

import java.io.Closeable;
import java.io.IOException;

/**
* The listener to be invoked on the completion or failure of a {@link TransferSnapshot}
*
* @opensearch.internal
*/
public interface TranslogTransferListener {
public interface TranslogTransferListener extends Closeable {
/**
* Invoked when the transfer of {@link TransferSnapshot} succeeds
* @param transferSnapshot the transfer snapshot
Expand All @@ -32,8 +33,4 @@ public interface TranslogTransferListener {
* @throws IOException the exception during the transfer of data
*/
void onUploadFailed(TransferSnapshot transferSnapshot, Exception ex) throws IOException;

default void close() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public void onUploadComplete(TransferSnapshot transferSnapshot) {
public void onUploadFailed(TransferSnapshot transferSnapshot, Exception ex) {
translogTransferFailed.incrementAndGet();
}

@Override
public void close() {}
}));
assertEquals(4, fileTransferSucceeded.get());
assertEquals(0, fileTransferFailed.get());
Expand Down