Skip to content
Draft
Show file tree
Hide file tree
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 @@ -150,7 +150,7 @@ private AccumulatingRead(
IOAutoCloseable onCloseCallback) {
super(rangeSpec, retryContext, onCloseCallback);
this.readId = readId;
this.hasher = hasher;
this.hasher = (rangeSpec.begin() == 0) ? new CumulativeHasher(hasher, 0, rangeSpec.maxLength()) : hasher;
this.complete = SettableApiFuture.create();
this.childRefs = Collections.synchronizedList(new ArrayList<>());
}
Expand Down Expand Up @@ -280,7 +280,7 @@ static class StreamingRead extends BaseObjectReadSessionStreamRead<ScatteringByt
IOAutoCloseable onCloseCallback) {
super(rangeSpec, retryContext, onCloseCallback);
this.readId = new AtomicLong(readId);
this.hasher = hasher;
this.hasher = (rangeSpec.begin() == 0) ? new CumulativeHasher(hasher, 0, rangeSpec.maxLength()) : hasher;
this.closed = false;
this.failFuture = SettableApiFuture.create();
this.queue = new ArrayBlockingQueue<>(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ public void onResponse(BidiReadObjectResponse response) {
executor.execute(
StorageException.liftToRunnable(
() -> {
try {
validateCumulativeChecksum(read);
} catch (UncheckedCumulativeChecksumMismatchException e) {
state.removeOutstandingReadOnFailure(id, read::fail).onFailure(e);
return;
}
read.eof();
// don't remove the outstanding read until the future has been resolved
state.removeOutstandingRead(id);
Expand Down Expand Up @@ -545,6 +551,15 @@ public void onComplete() {
}
}

private void validateCumulativeChecksum(ObjectReadSessionStreamRead<?> read) {
Hasher hasher = read.hasher();
if (hasher instanceof CumulativeHasher) {
CumulativeHasher cumulativeHasher = (CumulativeHasher) hasher;
com.google.storage.v2.Object metadata = state.getMetadata();
cumulativeHasher.validateCumulativeChecksum(metadata);
}
}

static ObjectReadSessionStream create(
ScheduledExecutorService executor,
ZeroCopyBidiStreamingCallable<BidiReadObjectRequest, BidiReadObjectResponse> callable,
Expand Down
Loading
Loading