@@ -79,7 +79,7 @@ google::bigtable::v2::MutateRowsRequest const& BulkMutatorState::BeforeStart() {
7979}
8080
8181std::vector<int > BulkMutatorState::OnRead (
82- google::bigtable::v2::MutateRowsResponse& response) {
82+ google::bigtable::v2::MutateRowsResponse response) {
8383 std::vector<int > res;
8484 for (auto & entry : *response.mutable_entries ()) {
8585 // The type of `entry.index()` is a 64-bit int. But we can never create more
@@ -197,14 +197,42 @@ grpc::Status BulkMutator::MakeOneRequest(bigtable::DataClient& client,
197197 // Read the stream of responses.
198198 btproto::MutateRowsResponse response;
199199 while (stream->Read (&response)) {
200- state_.OnRead (response);
200+ state_.OnRead (std::move ( response) );
201201 }
202202 // Handle any errors in the stream.
203203 auto grpc_status = stream->Finish ();
204204 state_.OnFinish (MakeStatusFromRpcError (grpc_status));
205205 return grpc_status;
206206}
207207
208+ Status BulkMutator::MakeOneRequest (bigtable_internal::BigtableStub& stub) {
209+ // Send the request to the server.
210+ auto const & mutations = state_.BeforeStart ();
211+
212+ // Configure the context
213+ auto const & options = google::cloud::internal::CurrentOptions ();
214+ auto context = absl::make_unique<grpc::ClientContext>();
215+ google::cloud::internal::ConfigureContext (*context, options);
216+
217+ struct UnpackVariant {
218+ BulkMutatorState& state;
219+ bool operator ()(btproto::MutateRowsResponse r) {
220+ state.OnRead (std::move (r));
221+ return true ;
222+ }
223+ bool operator ()(Status s) {
224+ state.OnFinish (std::move (s));
225+ return false ;
226+ }
227+ };
228+
229+ // Read the stream of responses.
230+ auto stream = stub.MutateRows (std::move (context), mutations);
231+ while (absl::visit (UnpackVariant{state_}, stream->Read ())) {
232+ }
233+ return state_.last_status ();
234+ }
235+
208236std::vector<FailedMutation> BulkMutator::OnRetryDone () && {
209237 return std::move (state_).OnRetryDone ();
210238}
0 commit comments