Skip to content

Commit

Permalink
chore: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWhitehead committed May 31, 2024
1 parent 41eaa81 commit f046ba1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ private long internalWrite(ByteBuffer[] srcs, int srcsOffset, int srcsLength, bo
}

if (i == data.length - 1 && !finished) {
builder.setFlush(true).setStateLookup(true);
if (finalize) {
builder.setFinishWrite(true);
finished = true;
} else {
builder.setFlush(true).setStateLookup(true);
}
}

BidiWriteObjectRequest build = builder.build();
Expand Down Expand Up @@ -209,8 +214,11 @@ private BidiWriteObjectRequest finishMessage() {
long offset = writeCtx.getTotalSentBytes().get();
Crc32cLengthKnown crc32cValue = writeCtx.getCumulativeCrc32c().get();

BidiWriteObjectRequest.Builder b =
writeCtx.newRequestBuilder().setFinishWrite(true).setWriteOffset(offset);
BidiWriteObjectRequest.Builder b = writeCtx.newRequestBuilder();
if (!first) {
b.clearUploadId().clearObjectChecksums();
}
b.setFinishWrite(true).setWriteOffset(offset);
if (crc32cValue != null) {
b.setObjectChecksums(ObjectChecksums.newBuilder().setCrc32C(crc32cValue.getValue()).build());
}
Expand Down Expand Up @@ -312,7 +320,12 @@ public void onNext(BidiWriteObjectResponse value) {
} else if (finalizing && value.hasPersistedSize()) {
long totalSentBytes = writeCtx.getTotalSentBytes().get();
long persistedSize = value.getPersistedSize();
if (persistedSize < totalSentBytes) {
// if a flush: true, state_lookup: true message is in the stream along with a
// finish_write: true, GCS can respond with the incremental update, gracefully handle this
// message
if (totalSentBytes == persistedSize) {
writeCtx.getConfirmedBytes().set(persistedSize);
} else if (persistedSize < totalSentBytes) {
clientDetectedError(
ResumableSessionFailureScenario.SCENARIO_3.toStorageException(
ImmutableList.of(lastWrittenRequest), value, context, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.MessageOrBuilder;
import com.google.storage.v2.BidiWriteObjectRequest;
import com.google.storage.v2.ReadObjectResponse;
import com.google.storage.v2.WriteObjectRequest;
import io.grpc.CallOptions;
import io.grpc.Channel;
Expand Down Expand Up @@ -112,6 +113,8 @@ static String fmtProto(@NonNull Object obj) {
return fmtProto((WriteObjectRequest) obj);
} else if (obj instanceof BidiWriteObjectRequest) {
return fmtProto((BidiWriteObjectRequest) obj);
} else if (obj instanceof ReadObjectResponse) {
return fmtProto((ReadObjectResponse) obj);
} else if (obj instanceof MessageOrBuilder) {
return fmtProto((MessageOrBuilder) obj);
} else {
Expand Down Expand Up @@ -156,6 +159,22 @@ static String fmtProto(@NonNull BidiWriteObjectRequest msg) {
return msg.toString();
}

@NonNull
static String fmtProto(@NonNull ReadObjectResponse msg) {
if (msg.hasChecksummedData()) {
ByteString content = msg.getChecksummedData().getContent();
if (content.size() > 20) {
ReadObjectResponse.Builder b = msg.toBuilder();
ByteString snip = ByteString.copyFromUtf8(String.format("<snip (%d)>", content.size()));
ByteString trim = content.substring(0, 20).concat(snip);
b.getChecksummedDataBuilder().setContent(trim);

return b.build().toString();
}
}
return msg.toString();
}

private static final class InterceptorProvider implements GrpcInterceptorProvider {
private static final InterceptorProvider INSTANCE = new InterceptorProvider();

Expand Down

0 comments on commit f046ba1

Please sign in to comment.