Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@

package org.elasticsearch.common.blobstore.support;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.ReferenceDocs;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.ChunkedLoggingStream;
import org.elasticsearch.common.unit.ByteSizeUnit;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -38,8 +32,6 @@ public static void ensureValidRegisterContent(BytesReference bytesReference) {
}
}

private static final Logger logger = LogManager.getLogger(BlobContainerUtils.class);

/**
* Many blob stores have consistent (linearizable/atomic) read semantics and in these casees it is safe to implement {@link
* BlobContainer#getRegister} by simply reading the blob using this utility.
Expand All @@ -59,28 +51,7 @@ public static BytesReference getRegisterUsingConsistentRead(InputStream inputStr
len -= read;
pos += read;
}
final int nextByte = inputStream.read();
if (nextByte != -1) {
try (
var cls = ChunkedLoggingStream.create(
logger,
Level.ERROR,
"getRegisterUsingConsistentRead including trailing data",
ReferenceDocs.LOGGING
)
) {
cls.write(bytes);
cls.write(nextByte);
final var buffer = new byte[ByteSizeUnit.KB.toIntBytes(1)];
while (true) {
final var readSize = inputStream.read(buffer);
if (readSize == -1) {
break;
}
cls.write(buffer, 0, readSize);
}
}

if (inputStream.read() != -1) {
throw new IllegalStateException(
Strings.format("[%s] failed reading register [%s] due to unexpected trailing data", container, key)
);
Expand Down