Skip to content

Commit

Permalink
better exception handling
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Bansal <[email protected]>
  • Loading branch information
linuxpi committed Mar 11, 2024
1 parent da709a6 commit dde1609
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package org.opensearch.index.translog.transfer;

import org.apache.logging.log4j.Logger;
import org.opensearch.common.logging.Loggers;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.index.remote.RemoteTranslogTransferTracker;
import org.opensearch.index.translog.transfer.FileSnapshot.TransferFileSnapshot;
Expand All @@ -33,11 +35,13 @@ public class FileTransferTracker implements FileTransferListener {
private final RemoteTranslogTransferTracker remoteTranslogTransferTracker;
private Map<String, Long> bytesForTlogCkpFileToUpload;
private long fileTransferStartTime = -1;
private final Logger logger;

public FileTransferTracker(ShardId shardId, RemoteTranslogTransferTracker remoteTranslogTransferTracker) {
this.shardId = shardId;
this.fileTransferTracker = new ConcurrentHashMap<>();
this.remoteTranslogTransferTracker = remoteTranslogTransferTracker;
this.logger = Loggers.getLogger(getClass(), shardId);
}

void recordFileTransferStartTime(long uploadStartTime) {
Expand Down Expand Up @@ -68,8 +72,14 @@ public void onSuccess(TransferFileSnapshot fileSnapshot) {
long durationInMillis = (System.nanoTime() - fileTransferStartTime) / 1_000_000L;
remoteTranslogTransferTracker.addUploadTimeInMillis(durationInMillis);
remoteTranslogTransferTracker.addUploadBytesSucceeded(bytesForTlogCkpFileToUpload.get(fileSnapshot.getName()));
add(fileSnapshot.getName(), TransferState.SUCCESS);
} catch (Exception ex) {
logger.error("Failure to update translog upload success stats", ex);

Check warning on line 76 in server/src/main/java/org/opensearch/index/translog/transfer/FileTransferTracker.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/translog/transfer/FileTransferTracker.java#L75-L76

Added lines #L75 - L76 were not covered by tests
}

try {
// add() gets a dedicated try/catch as its on the critical path
add(fileSnapshot.getName(), TransferState.SUCCESS);
} catch (IllegalStateException ex) {
throw new FileTransferException(fileSnapshot, ex);

Check warning on line 83 in server/src/main/java/org/opensearch/index/translog/transfer/FileTransferTracker.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/translog/transfer/FileTransferTracker.java#L82-L83

Added lines #L82 - L83 were not covered by tests
}
}
Expand Down

0 comments on commit dde1609

Please sign in to comment.