Skip to content

Commit bb5c2d8

Browse files
committed
fix: Raise on failed Bigtable mutate_rows statuses in BigtableOnlineStore
Table.mutate_rows does not raise when rows fail. It returns one status per row, and None for a row that never got a response on google-cloud-bigtable < 2.45. _write_rows_to_bt ignored the result, so failed writes were dropped and feast materialize exited 0. Check every status after mutate_rows and raise RuntimeError with the failed row count, the table and the first failed row key and status. Signed-off-by: Van Anh Giang <27738449+AnhVanGiang@users.noreply.github.com>
1 parent f2abc7c commit bb5c2d8

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

‎sdk/python/feast/infra/online_stores/bigtable.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,25 @@ def _write_rows_to_bt(
408408
utils.make_tzaware(timestamp).isoformat().encode(),
409409
)
410410
rows.append(bt_row)
411-
bt_table.mutate_rows(rows)
411+
# mutate_rows does not raise when rows fail. It returns one status per row,
412+
# and None for a row that never got a response (google-cloud-bigtable < 2.45).
413+
statuses = bt_table.mutate_rows(rows)
414+
failed = [
415+
(row, status)
416+
for row, status in zip(rows, statuses)
417+
if status is None or status.code != 0
418+
]
419+
if failed:
420+
row, status = failed[0]
421+
reason = (
422+
"no status returned"
423+
if status is None
424+
else f"code={status.code} message={status.message!r}"
425+
)
426+
raise RuntimeError(
427+
f"Failed to write {len(failed)} of {len(rows)} rows to Bigtable table "
428+
f"{bt_table.table_id}; first failure (row key {row.row_key!r}): {reason}"
429+
)
412430

413431
if progress:
414432
progress(len(rows))

‎sdk/python/tests/unit/infra/online_store/test_bigtable_online_store.py‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from dataclasses import dataclass, field
22
from datetime import datetime, timezone
33
from typing import List
4-
from unittest.mock import patch
4+
from unittest.mock import MagicMock, patch
55

66
import pytest
77

88
pytest.importorskip("google.cloud.bigtable")
99

1010
from concurrent import futures # noqa: E402
1111

12+
from google.rpc import status_pb2 # noqa: E402
13+
1214
import feast.infra.online_stores.bigtable as bigtable_module # noqa: E402
1315
from feast.infra.offline_stores.dask import DaskOfflineStoreConfig # noqa: E402
1416
from feast.infra.online_stores.bigtable import ( # noqa: E402
@@ -117,3 +119,62 @@ def test_write_concurrency_sets_thread_pool_size():
117119
store.online_write_batch(config, feature_view, _rows(4), None)
118120

119121
mock_pool.assert_called_once_with(max_workers=3)
122+
123+
124+
OK = status_pb2.Status(code=0)
125+
UNAVAILABLE = status_pb2.Status(code=14, message="connection refused")
126+
127+
128+
def _mock_bt_table(statuses):
129+
bt_table = MagicMock()
130+
bt_table.table_id = "tbl"
131+
bt_table.direct_row.side_effect = lambda row_key: MagicMock(row_key=row_key)
132+
bt_table.mutate_rows.return_value = statuses
133+
return bt_table
134+
135+
136+
def _write_rows(bt_table, n, progress=None):
137+
with patch.object(BigtableOnlineStore, "_compute_row_key", return_value=b"key"):
138+
BigtableOnlineStore()._write_rows_to_bt(
139+
rows_to_write=_rows(n),
140+
bt_table=bt_table,
141+
feature_view_name="fv",
142+
config=_make_repo_config(),
143+
progress=progress,
144+
)
145+
146+
147+
def test_write_rows_to_bt_reports_progress_when_all_rows_succeed():
148+
progress = MagicMock()
149+
_write_rows(_mock_bt_table([OK, OK, OK]), 3, progress)
150+
progress.assert_called_once_with(3)
151+
152+
153+
def test_write_rows_to_bt_raises_on_failed_row_status():
154+
# mutate_rows reports per-row failures in its return value instead of raising.
155+
progress = MagicMock()
156+
with pytest.raises(RuntimeError, match=r"1 of 3 rows .* tbl.*code=14"):
157+
_write_rows(_mock_bt_table([OK, UNAVAILABLE, OK]), 3, progress)
158+
progress.assert_not_called()
159+
160+
161+
def test_write_rows_to_bt_raises_when_row_has_no_status():
162+
# google-cloud-bigtable < 2.45 leaves None for rows still failing at the retry deadline.
163+
with pytest.raises(RuntimeError, match=r"2 of 2 rows .*no status returned"):
164+
_write_rows(_mock_bt_table([None, None]), 2)
165+
166+
167+
def test_online_write_batch_raises_on_failed_row_status():
168+
bt_table = _mock_bt_table([UNAVAILABLE, UNAVAILABLE])
169+
client = MagicMock()
170+
client.instance.return_value.table.return_value = bt_table
171+
172+
with (
173+
patch.object(BigtableOnlineStore, "_get_client", return_value=client),
174+
patch.object(BigtableOnlineStore, "_get_table_name", return_value="tbl"),
175+
patch.object(BigtableOnlineStore, "_compute_row_key", return_value=b"key"),
176+
pytest.raises(RuntimeError, match="2 of 2 rows"),
177+
):
178+
BigtableOnlineStore().online_write_batch(
179+
_make_repo_config(), MockFeatureView(name="fv"), _rows(2), None
180+
)

0 commit comments

Comments
 (0)