Skip to content
Merged
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
23 changes: 12 additions & 11 deletions google-cloud-bigtable/conformance/test_proxy/test_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,20 @@ def bulk_mutate_rows req, _call
end

results = table.mutate_rows entries
failed_entries = results.reject { |r| r.status.code.zero? }.map do |result|
Google::Cloud::Bigtable::V2::MutateRowsResponse::Entry.new(
index: result.index,
status: Google::Rpc::Status.new(
code: result.status.code,
message: result.status.message
)
)
end

Google::Bigtable::Testproxy::MutateRowsResult.new(
status: ok_status,
status: failed_entries.empty? ? ok_status : failed_entries.first.status,
# Entries should include only the failed rows, where status != 0 (OK)
entries: results.reject { |r| r.status.code.zero? }.map do |result|
Google::Cloud::Bigtable::V2::MutateRowsResponse::Entry.new(
index: result.index,
status: Google::Rpc::Status.new(
code: result.status.code,
message: result.status.message
)
)
end
entries: failed_entries
)
rescue Google::Cloud::Error => e
LOGGER.info "BulkMutateRows failed: Caught #{e}"
Expand Down Expand Up @@ -364,7 +365,7 @@ def read_modify_write_row req, _call
result = table.read_modify_write_row(req.request.row_key, req.request.rules.map do |r|
rule = Google::Cloud::Bigtable::ReadModifyWriteRule.new r.family_name, r.column_qualifier
rule.append r.append_value if r.append_value && r.append_value != ""
rule.increment r.increment_amount if r.increment_amount&.positive?
rule.increment r.increment_amount if r.increment_amount&.nonzero?
rule
end)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def mutate_rows entries, cookies = {}
app_profile_id: @table.app_profile_id,
call_options: call_options
)
[response.flat_map(&:entries), nil, cookies]
[normalize_entries(response, entries.length), nil, cookies]
rescue GRPC::BadStatus => e
info = e.status_details.find { |d| d.is_a? Google::Rpc::RetryInfo }
delay = if info&.retry_delay
Expand All @@ -117,6 +117,27 @@ def mutate_rows entries, cookies = {}
[statuses, delay, cookies]
end

def normalize_entries response, count
by_index = {}
response.each do |res|
res.entries.each { |e| by_index[e.index] = e if e.status }
end
Array.new count do |i|
by_index[i] || missing_entry(i)
end
end

def missing_entry index
status = Google::Rpc::Status.new(
code: Google::Rpc::Code::INTERNAL,
message: "Missing entry result in MutateRows response"
)
Google::Cloud::Bigtable::V2::MutateRowsResponse::Entry.new(
index: index,
status: status
)
end

##
# Collects failed entries, retries mutation, and updates status.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,39 @@ def mock.mutate_rows request, call_options
_(responses[1].status.message).must_equal "success"
_(responses[1].status.details).must_equal []
end

it "marks missing response entries as INTERNAL error without retrying" do
req_entries = req_entries_grpc
res = Google::Cloud::Bigtable::V2::MutateRowsResponse.new(
entries: [
{ index: 0, status: { code: Google::Rpc::Code::OK, message: "success", details: [] } }
]
)

mock = Minitest::Mock.new
req = {
table_name: table_path(instance_id, table_id),
entries: req_entries,
app_profile_id: app_profile_id
}
mock.expect :mutate_rows, [res], [req, nil]

bigtable.service.mocked_client = mock

mutation_entries = req_entries.map do |r|
entry = Google::Cloud::Bigtable::MutationEntry.new(r.row_key)
entry.mutations.concat(r.mutations)
entry
end
responses = table.mutate_rows(mutation_entries)

mock.verify
_(responses.length).must_equal 2
_(responses[0].index).must_equal 0
_(responses[0].status.code).must_equal Google::Rpc::Code::OK
_(responses[1].index).must_equal 1
_(responses[1].status.code).must_equal Google::Rpc::Code::INTERNAL
_(responses[1].status.description).must_equal "INTERNAL"
_(responses[1].status.message).must_equal "Missing entry result in MutateRows response"
end
end
Loading