diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStats.java b/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStats.java index fff55630877c1..7805ee2e0aea5 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStats.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStats.java @@ -24,8 +24,14 @@ * @opensearch.internal */ public class RemoteStoreStats implements Writeable, ToXContentFragment { - + /** + * Stats related to Remote Segment Store operations + */ private final RemoteRefreshSegmentTracker.Stats remoteSegmentUploadShardStats; + + /** + * Stats related to Remote Translog Store operations + */ private final RemoteTranslogTracker.Stats remoteTranslogShardStats; public RemoteStoreStats( diff --git a/server/src/main/java/org/opensearch/index/remote/RemoteTranslogTracker.java b/server/src/main/java/org/opensearch/index/remote/RemoteTranslogTracker.java index 1cc8c0af69370..c0376375c2c5a 100644 --- a/server/src/main/java/org/opensearch/index/remote/RemoteTranslogTracker.java +++ b/server/src/main/java/org/opensearch/index/remote/RemoteTranslogTracker.java @@ -22,6 +22,9 @@ * Stores Remote Translog Store-related stats for a given IndexShard. */ public class RemoteTranslogTracker { + /** + * The shard that this tracker is associated with + */ public final ShardId shardId; /** @@ -267,6 +270,10 @@ void updateUploadTimeMsMovingAverageWindowSize(int updatedSize) { } } + /** + * Gets the tracker's state as seen in the stats API + * @return Stats object with the tracker's stats + */ public RemoteTranslogTracker.Stats stats() { return new RemoteTranslogTracker.Stats( shardId, @@ -284,6 +291,13 @@ public RemoteTranslogTracker.Stats stats() { ); } + /** + * Validates that the sum of successful operations, failed operations, and the number of operations to add (irrespective of failed/successful) does not exceed the number of operations originally started + * @param startedCount Number of operations started + * @param failedCount Number of operations failed + * @param succeededCount Number of operations successful + * @param countToAdd Number of operations to add + */ private void checkTotal(long startedCount, long failedCount, long succeededCount, long countToAdd) { long delta = startedCount - (failedCount + succeededCount + countToAdd); assert delta >= 0 : "Sum of failure count (" @@ -445,6 +459,11 @@ public boolean equals(Object obj) { } } + /** + * Validates if the stats in this tracker and the stats contained in the given stats object are same or not + * @param other Stats object to compare this tracker against + * @return true if stats are same and false otherwise + */ boolean hasSameStatsAs(RemoteTranslogTracker.Stats other) { return this.getShardId().toString().equals(other.shardId.toString()) && this.getLastUploadTimestamp() == other.lastUploadTimestamp diff --git a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java b/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java index a990cd989e3e9..ec0fd68a2646a 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java @@ -273,35 +273,30 @@ private boolean upload(Long primaryTerm, Long generation) throws IOException { Releasable transferReleasable = Releasables.wrap(deletionPolicy.acquireTranslogGen(getMinFileGeneration())); return translogTransferManager.transferSnapshot(transferSnapshotProvider, new TranslogTransferListener() { /** - * + * Tracker holding stats related to Remote Translog Store operations */ final RemoteTranslogTracker remoteTranslogTracker = RemoteFsTranslog.this.remoteTranslogTracker; /** - * + * Files (.tlog, .ckp, metadata) to upload to Remote Translog Store */ Set toUpload; /** - * + * Total bytes to be uploaded to Remote Translog Store */ long uploadBytes; /** - * + * System nano time when the Remote Translog Store upload is started */ long uploadStartTime; /** - * + * System nano time when the Remote Translog Store upload is completed */ long uploadEndTime; - /** - * - * @param transferSnapshot the transfer snapshot - * @throws IOException - */ @Override public void beforeUpload(TransferSnapshot transferSnapshot) throws IOException { toUpload = RemoteStoreUtils.getUploadBlobsFromSnapshot(transferSnapshot, fileTransferTracker); @@ -311,11 +306,6 @@ public void beforeUpload(TransferSnapshot transferSnapshot) throws IOException { captureStatsBeforeUpload(); } - /** - * - * @param transferSnapshot the transfer snapshot - * @throws IOException - */ @Override public void onUploadComplete(TransferSnapshot transferSnapshot) throws IOException { uploadEndTime = RemoteStoreUtils.getCurrentSystemNanoTime(); @@ -328,12 +318,6 @@ public void onUploadComplete(TransferSnapshot transferSnapshot) throws IOExcepti logger.trace("uploaded translog for {} {} ", primaryTerm, generation); } - /** - * - * @param transferSnapshot the transfer snapshot - * @param ex the exception while processing the {@link TransferSnapshot} - * @throws IOException - */ @Override public void onUploadFailed(TransferSnapshot transferSnapshot, Exception ex) throws IOException { uploadEndTime = RemoteStoreUtils.getCurrentSystemNanoTime(); @@ -349,11 +333,17 @@ public void onUploadFailed(TransferSnapshot transferSnapshot, Exception ex) thro } } + /** + * Adds relevant stats to the tracker when an upload is started + */ private void captureStatsBeforeUpload() { remoteTranslogTracker.incrementUploadsStarted(); remoteTranslogTracker.addUploadBytesStarted(uploadBytes); } + /** + * Adds relevant stats to the tracker when an upload is successfully completed + */ private void captureStatsOnUploadSuccess() { long uploadDurationInMillis = (uploadEndTime - uploadStartTime) / 1_000_000L; remoteTranslogTracker.incrementUploadsSucceeded(); @@ -369,6 +359,9 @@ private void captureStatsOnUploadSuccess() { remoteTranslogTracker.updateUploadTimeMovingAverage(uploadDurationInMillis); } + /** + * Adds relevant stats to the tracker when an upload has failed + */ private void captureStatsOnUploadFailure() { remoteTranslogTracker.incrementUploadsFailed(); remoteTranslogTracker.addUploadTimeInMillis((uploadEndTime - uploadStartTime) / 1_000_000L);