Skip to content

Commit 106f7a8

Browse files
committed
revert: revert previous appendable upload checksum validation implementation
1 parent f1a8e57 commit 106f7a8

3 files changed

Lines changed: 5 additions & 273 deletions

File tree

google/cloud/storage/internal/async/connection_impl_appendable_upload_test.cc

Lines changed: 0 additions & 256 deletions
Original file line numberDiff line numberDiff line change
@@ -631,262 +631,6 @@ TEST_F(AsyncConnectionImplAppendableTest, AppendableUploadRedirectNoHandle) {
631631
next.first.set_value(true);
632632
}
633633

634-
TEST_F(AsyncConnectionImplAppendableTest,
635-
StartAppendableObjectUploadWithChecksum) {
636-
auto constexpr kRequestText = R"pb(
637-
write_object_spec {
638-
resource {
639-
bucket: "projects/_/buckets/test-bucket"
640-
name: "test-object"
641-
content_type: "text/plain"
642-
}
643-
}
644-
)pb";
645-
AsyncSequencer<bool> sequencer;
646-
auto mock = std::make_shared<storage::testing::MockStorageStub>();
647-
648-
google::storage::v2::Object initial_resource;
649-
initial_resource.set_bucket("projects/_/buckets/test-bucket");
650-
initial_resource.set_name("test-object");
651-
initial_resource.set_size(1024);
652-
initial_resource.mutable_checksums()->set_crc32c(12345); // Some dummy CRC
653-
654-
auto stream = std::make_unique<MockAsyncBidiWriteObjectStream>();
655-
EXPECT_CALL(*stream, Start).WillOnce([&] {
656-
return sequencer.PushBack("Start");
657-
});
658-
659-
EXPECT_CALL(*stream, Read)
660-
.WillOnce([&, initial_resource] {
661-
return sequencer.PushBack("Read(Takeover)")
662-
.then([initial_resource](auto) {
663-
auto response = google::storage::v2::BidiWriteObjectResponse{};
664-
*response.mutable_resource() = initial_resource;
665-
return absl::make_optional(std::move(response));
666-
});
667-
})
668-
.WillOnce([&, initial_resource] {
669-
return sequencer.PushBack("Read(FinalObject)")
670-
.then([initial_resource](auto) {
671-
auto response = google::storage::v2::BidiWriteObjectResponse{};
672-
*response.mutable_resource() = initial_resource;
673-
response.mutable_resource()->set_size(
674-
initial_resource.size() + 9); // "some data" size is 9
675-
return absl::make_optional(std::move(response));
676-
});
677-
});
678-
679-
EXPECT_CALL(*stream, Cancel).Times(1);
680-
EXPECT_CALL(*stream, Finish).WillOnce([&] {
681-
return sequencer.PushBack("Finish").then([](auto) { return Status{}; });
682-
});
683-
684-
EXPECT_CALL(*stream, Write)
685-
.WillOnce([&](google::storage::v2::BidiWriteObjectRequest const& request,
686-
grpc::WriteOptions wopt) {
687-
EXPECT_TRUE(request.state_lookup());
688-
EXPECT_FALSE(wopt.is_last_message());
689-
return sequencer.PushBack("Write(StateLookup)");
690-
})
691-
.WillOnce(
692-
[&](google::storage::v2::BidiWriteObjectRequest const& /*request*/,
693-
grpc::WriteOptions wopt) {
694-
EXPECT_FALSE(wopt.is_last_message());
695-
return sequencer.PushBack("Write(data)");
696-
})
697-
.WillOnce([&](google::storage::v2::BidiWriteObjectRequest const& request,
698-
grpc::WriteOptions wopt) {
699-
EXPECT_TRUE(request.finish_write());
700-
EXPECT_TRUE(wopt.is_last_message());
701-
// Here we expect full checksums to be set because we had the resource
702-
// in takeover.
703-
EXPECT_TRUE(request.has_object_checksums());
704-
auto expected_crc =
705-
google::cloud::storage_internal::ExtendCrc32c(12345, "some data");
706-
EXPECT_EQ(request.object_checksums().crc32c(), expected_crc);
707-
return sequencer.PushBack("Write(Finalize)");
708-
});
709-
710-
EXPECT_CALL(*mock, AsyncBidiWriteObject).WillOnce([&] {
711-
return std::unique_ptr<AsyncBidiWriteObjectStream>(std::move(stream));
712-
});
713-
714-
internal::AutomaticallyCreatedBackgroundThreads pool(1);
715-
// Enable CRC32C validation in options
716-
auto options = TestOptions().set<storage::EnableCrc32cValidationOption>(true);
717-
auto connection = MakeTestConnection(pool.cq(), mock, options);
718-
719-
auto request = google::storage::v2::BidiWriteObjectRequest{};
720-
ASSERT_TRUE(TextFormat::ParseFromString(kRequestText, &request));
721-
request.mutable_write_object_spec()->set_appendable(true);
722-
723-
auto pending = connection->StartAppendableObjectUpload(
724-
{std::move(request), connection->options()});
725-
726-
auto next = sequencer.PopFrontWithName();
727-
EXPECT_EQ(next.second, "Start");
728-
next.first.set_value(true);
729-
730-
next = sequencer.PopFrontWithName();
731-
EXPECT_EQ(next.second, "Write(StateLookup)");
732-
next.first.set_value(true);
733-
734-
next = sequencer.PopFrontWithName();
735-
EXPECT_EQ(next.second, "Read(Takeover)");
736-
next.first.set_value(true);
737-
738-
auto r = pending.get();
739-
ASSERT_STATUS_OK(r);
740-
auto writer = *std::move(r);
741-
742-
// Write some data.
743-
auto w1 = writer->Write(storage::WritePayload("some data"));
744-
next = sequencer.PopFrontWithName();
745-
EXPECT_EQ(next.second, "Write(data)");
746-
next.first.set_value(true);
747-
EXPECT_STATUS_OK(w1.get());
748-
749-
// Finalize the upload.
750-
auto w2 = writer->Finalize({});
751-
next = sequencer.PopFrontWithName();
752-
EXPECT_EQ(next.second, "Write(Finalize)");
753-
next.first.set_value(true);
754-
next = sequencer.PopFrontWithName();
755-
EXPECT_EQ(next.second, "Read(FinalObject)");
756-
next.first.set_value(true);
757-
758-
auto response = w2.get();
759-
ASSERT_STATUS_OK(response);
760-
761-
writer.reset();
762-
next = sequencer.PopFrontWithName();
763-
EXPECT_EQ(next.second, "Finish");
764-
next.first.set_value(true);
765-
}
766-
767-
// TODO(#16174): Figure out why this test fails to compile in MSVC.
768-
#ifndef _WIN32
769-
770-
TEST_F(AsyncConnectionImplAppendableTest,
771-
ResumeAppendableObjectUploadWithChecksum) {
772-
auto constexpr kRequestText = R"pb(
773-
append_object_spec { object: "test-object" }
774-
)pb";
775-
AsyncSequencer<bool> sequencer;
776-
auto mock = std::make_shared<storage::testing::MockStorageStub>();
777-
778-
constexpr std::int64_t kPersistedSize = 16384;
779-
constexpr std::uint32_t kPersistedCrc = 12345;
780-
781-
auto stream = std::make_unique<MockAsyncBidiWriteObjectStream>();
782-
EXPECT_CALL(*stream, Start).WillOnce([&] {
783-
return sequencer.PushBack("Start");
784-
});
785-
786-
EXPECT_CALL(*stream, Read)
787-
.WillOnce([&] {
788-
return sequencer.PushBack("Read(PersistedSize)").then([](auto) {
789-
auto response = google::storage::v2::BidiWriteObjectResponse{};
790-
response.set_persisted_size(kPersistedSize);
791-
response.mutable_persisted_data_checksums()->set_crc32c(
792-
kPersistedCrc);
793-
return absl::make_optional(std::move(response));
794-
});
795-
})
796-
.WillOnce([&] {
797-
return sequencer.PushBack("Read(FinalObject)").then([](auto) {
798-
auto response = google::storage::v2::BidiWriteObjectResponse{};
799-
auto object = google::storage::v2::Object{};
800-
object.set_bucket("projects/_/buckets/test-bucket");
801-
object.set_name("test-object");
802-
object.set_size(kPersistedSize + 9);
803-
*response.mutable_resource() = std::move(object);
804-
return absl::make_optional(std::move(response));
805-
});
806-
});
807-
808-
EXPECT_CALL(*stream, Cancel).Times(1);
809-
EXPECT_CALL(*stream, Finish).WillOnce([&] {
810-
return sequencer.PushBack("Finish").then([](auto) { return Status{}; });
811-
});
812-
813-
EXPECT_CALL(*stream, Write)
814-
.WillOnce([&](google::storage::v2::BidiWriteObjectRequest const& request,
815-
grpc::WriteOptions wopt) {
816-
EXPECT_TRUE(request.state_lookup());
817-
EXPECT_FALSE(wopt.is_last_message());
818-
return sequencer.PushBack("Write(StateLookup)");
819-
})
820-
.WillOnce(
821-
[&](google::storage::v2::BidiWriteObjectRequest const& /*request*/,
822-
grpc::WriteOptions wopt) {
823-
EXPECT_FALSE(wopt.is_last_message());
824-
return sequencer.PushBack("Write(data)");
825-
})
826-
.WillOnce([&](google::storage::v2::BidiWriteObjectRequest const& request,
827-
grpc::WriteOptions wopt) {
828-
EXPECT_TRUE(request.finish_write());
829-
EXPECT_TRUE(wopt.is_last_message());
830-
EXPECT_TRUE(request.has_object_checksums());
831-
EXPECT_EQ(request.object_checksums().crc32c(), 2901820631);
832-
return sequencer.PushBack("Write(Finalize)");
833-
});
834-
835-
EXPECT_CALL(*mock, AsyncBidiWriteObject)
836-
.WillOnce([&](auto const&, auto, auto) {
837-
return std::unique_ptr<AsyncBidiWriteObjectStream>(std::move(stream));
838-
});
839-
840-
internal::AutomaticallyCreatedBackgroundThreads pool(1);
841-
auto options = TestOptions().set<storage::EnableCrc32cValidationOption>(true);
842-
auto connection = MakeTestConnection(pool.cq(), mock, options);
843-
844-
auto request = google::storage::v2::BidiWriteObjectRequest{};
845-
ASSERT_TRUE(TextFormat::ParseFromString(kRequestText, &request));
846-
auto pending = connection->ResumeAppendableObjectUpload(
847-
{std::move(request), connection->options()});
848-
849-
auto next = sequencer.PopFrontWithName();
850-
EXPECT_EQ(next.second, "Start");
851-
next.first.set_value(true);
852-
853-
next = sequencer.PopFrontWithName();
854-
EXPECT_EQ(next.second, "Write(StateLookup)");
855-
next.first.set_value(true);
856-
857-
next = sequencer.PopFrontWithName();
858-
EXPECT_EQ(next.second, "Read(PersistedSize)");
859-
next.first.set_value(true);
860-
861-
auto r = pending.get();
862-
ASSERT_STATUS_OK(r);
863-
auto writer = *std::move(r);
864-
865-
auto w1 = writer->Write(storage::WritePayload("some data"));
866-
next = sequencer.PopFrontWithName();
867-
EXPECT_EQ(next.second, "Write(data)");
868-
next.first.set_value(true);
869-
EXPECT_STATUS_OK(w1.get());
870-
871-
auto w2 = writer->Finalize({});
872-
next = sequencer.PopFrontWithName();
873-
EXPECT_EQ(next.second, "Write(Finalize)");
874-
next.first.set_value(true);
875-
next = sequencer.PopFrontWithName();
876-
EXPECT_EQ(next.second, "Read(FinalObject)");
877-
next.first.set_value(true);
878-
879-
auto response = w2.get();
880-
ASSERT_STATUS_OK(response);
881-
882-
writer.reset();
883-
next = sequencer.PopFrontWithName();
884-
EXPECT_EQ(next.second, "Finish");
885-
next.first.set_value(true);
886-
}
887-
888-
#endif
889-
890634
} // namespace
891635
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
892636
} // namespace storage_internal

google/cloud/storage/internal/async/writer_connection_impl.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,10 @@ AsyncWriterConnectionImpl::Finalize(storage::WritePayload payload) {
146146

147147
auto p = WritePayloadImpl::GetImpl(payload);
148148
auto size = p.size();
149-
auto action = PartialUpload::kFinalizeWithChecksum;
150-
if (request_.has_append_object_spec() ||
151-
request_.write_object_spec().appendable()) {
152-
if (!absl::holds_alternative<google::storage::v2::Object>(
153-
persisted_state_) &&
154-
!persisted_data_checksums_.has_value()) {
155-
action = PartialUpload::kFinalize;
156-
}
157-
}
149+
auto action = request_.has_append_object_spec() ||
150+
request_.write_object_spec().appendable()
151+
? PartialUpload::kFinalize
152+
: PartialUpload::kFinalizeWithChecksum;
158153
auto coro = PartialUpload::Call(impl_, hash_function_, std::move(write),
159154
std::move(p), std::move(action));
160155
return coro->Start().then([coro, size, this](auto f) mutable {

google/cloud/storage/internal/async/writer_connection_resumed.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,8 @@ class AsyncWriterConnectionResumedState
508508
}
509509

510510
// Recreate the underlying stream if still active.
511-
auto hash = hash_function_;
512-
if (checksums && checksums->has_crc32c()) {
513-
hash = std::make_shared<
514-
::google::cloud::storage::internal::Crc32cHashFunction>(
515-
checksums->crc32c(), persisted_offset);
516-
}
517-
518511
impl_ = std::make_unique<AsyncWriterConnectionImpl>(
519-
options_, initial_request_, std::move(res->stream), std::move(hash),
512+
options_, initial_request_, std::move(res->stream), hash_function_,
520513
persisted_offset, false, checksums);
521514
// OnQuery will restart the WriteLoop if necessary.
522515
OnQuery(std::move(lk), persisted_offset);

0 commit comments

Comments
 (0)