diff --git a/server/src/main/java/org/opensearch/index/translog/transfer/FileSnapshot.java b/server/src/main/java/org/opensearch/index/translog/transfer/FileSnapshot.java index 290fc6d6508dd..a3fd6d8cdfcd6 100644 --- a/server/src/main/java/org/opensearch/index/translog/transfer/FileSnapshot.java +++ b/server/src/main/java/org/opensearch/index/translog/transfer/FileSnapshot.java @@ -66,10 +66,6 @@ public long getContentLength() throws IOException { return fileChannel == null ? content.length : fileChannel.size(); } - public FileChannel getFileChannel() { - return fileChannel; - } - public InputStream inputStream() throws IOException { return fileChannel != null ? new BufferedInputStream(Channels.newInputStream(fileChannel)) diff --git a/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java b/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java index f3ce4c1ccd7e3..1a4b862e5a6d5 100644 --- a/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java +++ b/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java @@ -36,10 +36,6 @@ import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.channels.Channels; -import java.nio.channels.FileChannel; -import java.nio.channels.ReadableByteChannel; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -252,23 +248,11 @@ private Map createCheckpointDataAsObjectMetadata(TransferFileSna metadata.put(CHECKPOINT_FILE_CHECKSUM_KEY, checksumBase64); // Set the file data value - FileChannel fileChannel = checkpointFileSnapshot.getFileChannel(); - long fileSize = fileChannel.size(); - ByteBuffer buffer = ByteBuffer.allocate((int) fileSize); - try { - int bytesRead = 0; - while (buffer.hasRemaining()) { - bytesRead = fileChannel.read(buffer); - if (bytesRead == -1) { - break; // End of stream - } - } - } catch (IOException e) { - logger.error("Error reading translog.ckp file"); - throw e; - } - buffer.flip(); - String fileDataBase64 = Base64.getEncoder().encodeToString(buffer.array()); + Path checkpointFilePath = checkpointFileSnapshot.getPath(); + long fileSize = Files.size(checkpointFilePath); + assert fileSize < 1500 : "checkpoint file size is more than 1.5KB size, can't be stored as metadata"; + byte[] fileBytes = Files.readAllBytes(checkpointFilePath); + String fileDataBase64 = Base64.getEncoder().encodeToString(fileBytes); metadata.put(CHECKPOINT_FILE_DATA_KEY, fileDataBase64); return metadata;