Skip to content

Commit

Permalink
add logs for remote store metadata intermittent read failures
Browse files Browse the repository at this point in the history
Signed-off-by: bansvaru <bansvaru@amazon.com>
  • Loading branch information
linuxpi committed Jul 11, 2023
1 parent 418ab51 commit 25ed20a
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.store.ChecksumIndexInput;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
Expand All @@ -22,6 +26,8 @@
* @opensearch.internal
*/
public class VersionedCodecStreamWrapper<T> {
private static final Logger logger = LogManager.getLogger(VersionedCodecStreamWrapper.class);

// TODO This can be updated to hold a streamReadWriteHandlerFactory and get relevant handler based on the stream versions
private final IndexIOStreamHandler<T> indexIOStreamHandler;
private final int currentVersion;
Expand All @@ -46,10 +52,22 @@ public VersionedCodecStreamWrapper(IndexIOStreamHandler<T> indexIOStreamHandler,
* @return stream content parsed into {@link T}
*/
public T readStream(IndexInput indexInput) throws IOException {
CodecUtil.checksumEntireFile(indexInput);
int readStreamVersion = checkHeader(indexInput);
T content = getHandlerForVersion(readStreamVersion).readContent(indexInput);
return content;
logger.debug("Reading input stream [{}] of length - [{}]", indexInput.toString(), indexInput.length());
try {
CodecUtil.checksumEntireFile(indexInput);
int readStreamVersion = checkHeader(indexInput);
return getHandlerForVersion(readStreamVersion).readContent(indexInput);
} catch (CorruptIndexException cie) {
logger.error(
() -> new ParameterizedMessage(
"Error while validating header/footer for [{}]. Total data length [{}]",
indexInput.toString(),
indexInput.length()
),
cie
);
throw cie;
}
}

/**
Expand Down

0 comments on commit 25ed20a

Please sign in to comment.