Skip to content

Commit

Permalink
fix stats collection
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <[email protected]>
  • Loading branch information
ashking94 authored and Bhumika Saini committed Sep 4, 2023
1 parent cc052d3 commit 875a5e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ public RemoteFsTranslog(
}
}

RemoteTranslogTransferTracker getRemoteTranslogTracker() {
return remoteTranslogTransferTracker;
}

public static void download(Repository repository, ShardId shardId, ThreadPool threadPool, Path location, Logger logger)
throws IOException {
assert repository instanceof BlobStoreRepository : String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,18 @@ private void downloadToFS(String fileName, Path location, String primaryTerm) th
Files.delete(filePath);
}

long downloadStartTime = System.nanoTime();
boolean downloadStatus = false;
long bytesToRead = 0, downloadStartTime = System.nanoTime();
try (InputStream inputStream = transferService.downloadBlob(remoteDataTransferPath.add(primaryTerm), fileName)) {
// Capture number of bytes for stats before reading
long bytesToRead = inputStream.available();
bytesToRead = inputStream.available();
Files.copy(inputStream, filePath);
downloadStatus = true;
} finally {
remoteTranslogTransferTracker.addDownloadTimeInMillis((System.nanoTime() - downloadStartTime) / 1_000_000L);
remoteTranslogTransferTracker.addDownloadBytesSucceeded(bytesToRead);
} catch (IOException e) {
remoteTranslogTransferTracker.addDownloadTimeInMillis((System.nanoTime() - downloadStartTime) / 1_000_000L);
logger.error(() -> new ParameterizedMessage("Exception while reading file: {}", fileName), e);
if (downloadStatus) {
remoteTranslogTransferTracker.addDownloadBytesSucceeded(bytesToRead);
}
}

// Mark in FileTransferTracker so that the same files are not uploaded at the time of translog sync
Expand All @@ -272,18 +274,22 @@ public TranslogTransferMetadata readMetadata() throws IOException {
ActionListener.wrap(blobMetadataList -> {
if (blobMetadataList.isEmpty()) return;
String filename = blobMetadataList.get(0).name();
long downloadStartTime = System.nanoTime();
boolean downloadStatus = false;
long downloadStartTime = System.nanoTime(), bytesToRead = 0;
try (InputStream inputStream = transferService.downloadBlob(remoteMetadataTransferPath, filename)) {
// Capture number of bytes for stats before reading
long bytesToRead = inputStream.available();
bytesToRead = inputStream.available();
IndexInput indexInput = new ByteArrayIndexInput("metadata file", inputStream.readAllBytes());
metadataSetOnce.set(metadataStreamWrapper.readStream(indexInput));
remoteTranslogTransferTracker.addDownloadTimeInMillis((System.nanoTime() - downloadStartTime) / 1_000_000L);
remoteTranslogTransferTracker.addDownloadBytesSucceeded(bytesToRead);
downloadStatus = true;
} catch (IOException e) {
remoteTranslogTransferTracker.addDownloadTimeInMillis((System.nanoTime() - downloadStartTime) / 1_000_000L);
logger.error(() -> new ParameterizedMessage("Exception while reading metadata file: {}", filename), e);
exceptionSetOnce.set(e);
} finally {
remoteTranslogTransferTracker.addDownloadTimeInMillis((System.nanoTime() - downloadStartTime) / 1_000_000L);
if (downloadStatus) {
remoteTranslogTransferTracker.addDownloadBytesSucceeded(bytesToRead);
}
}
}, e -> {
logger.error(() -> new ParameterizedMessage("Exception while listing metadata files"), e);
Expand Down

0 comments on commit 875a5e5

Please sign in to comment.