Repository navigation
feat: Batch Bigtable online reads across feature views - #7198
Conversation
There was a problem hiding this comment.
Devin Review found 1 potential issue.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| features = features_by_table[bt_table_name] | ||
| features_by_table[bt_table_name] = ( | ||
| list(dict.fromkeys(features + requested_features)) | ||
| if features and requested_features | ||
| else None | ||
| ) |
There was a problem hiding this comment.
🔴 Unrequested columns exhaust serving memory
When co-located views share column names but request different subsets, features_by_table fetches unrequested values from each view. _read_rows buffers those values before response filtering, so a previously safe request can exhaust server memory.
Learn more
get_online_features previously used the per-view read loop, which sent each view's own column filter. The batched path uses one union of those filters for every row in a table. _read_rows collects the entire result in memory, then _process_bt_row decodes all columns before response population discards the extras. The batching guards cap filter size and row count, not this payload.
Example: Request 200 entities across ten views on the same entities. Each view stores the same ten column names as 64 KiB byte features, and the service selects a different one from each view. The request stays below 2,048 rows and uses a short filter. The old path reads 125 MiB of feature values in total. The batch buffers about 1.22 GiB of raw feature values alone, enough to exceed a 1 GiB server limit before decoding.
Recommended fix: Preserve each row's column projection in the backend. For example, batch only rows that share the same requested qualifier set, or use a row-key-aware filter with the existing size fallback. Cover co-located views that store the same columns but request disjoint subsets, and assert that the backend does not return the extra cells.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in 229c1f6. The shared filter did match a column that one view stores under the same name as a feature requested from another view. A request where that would happen now reads one feature view at a time, so a batched read returns the same cells as the per-view reads. The check compares each view's schema with the shared filter, so views with distinct feature names, and views asked for the same shared names, are still batched. It is covered by test_unrequested_columns_are_not_read.
I did not use a row-key-aware filter. It would add a row-key condition per view to a filter that already has to stay under the 20 KB limit, and I can only check its behaviour on the emulator, not on a real instance.
There was a problem hiding this comment.
the current schema check still misses cells left by schema changes. removing a feature from a view does not delete its Bigtable qualifier: update retains the table and _write_rows_to_bt only sets the supplied cells. if view A formerly stored a large payload feature, now requests only score, and view B requests payload, the union filter fetches A's retired payload too. table.features no longer contains it, so the fallback does not run and the extra cells are buffered and decoded. we need to preserve each view's requested qualifier set at the backend, including retired columns, and add a regression with a stored qualifier absent from the current schema.
There was a problem hiding this comment.
Fixed in 6717b40. You're right, the schema check could not see a qualifier left behind by a removed feature.
The batched read now uses the row-key-aware filter. It is a RowFilterUnion with one branch per feature view: a RowKeyRegexFilter for that view's row keys (^[0-9a-f]+#<escaped view name>$) chained with the view's own ColumnQualifierRegexFilter. A view requested without a feature list gets the row-key condition alone. Each row key matches exactly one branch, so every view keeps its own qualifier set at the backend whatever its rows hold, and the schema check is removed. Requests that fell back to per-view reads because of shared names are batched again.
The 16,000-byte fallback now measures the whole filter (every regex plus a per-view allowance for the proto framing; a test checks that this is an upper bound on the serialized size). A request naming a feature view whose name is not plain ASCII reads one view at a time, since I only build the row key pattern for ASCII names.
Regression: test_column_removed_from_the_schema_is_not_read stores a payload qualifier on fv_a that its schema does not list, requests score from fv_a and payload from fv_b, and asserts that fv_a's payload cell is not returned and that the cells match the per-view path. It fails on 229c1f6.
I said earlier that I could only check this kind of filter on the emulator, and that is still the case. I ran nine request shapes against Google's Bigtable emulator, including the retired qualifier, view names where one ends with another, and names containing . and #; the cells and responses match the per-view path in each. The emulator does not enforce the 20 KB filter limit, and nothing was run against a real instance.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7198 +/- ##
==========================================
+ Coverage 53.70% 53.81% +0.10%
==========================================
Files 462 462
Lines 58556 58628 +72
Branches 8637 8649 +12
==========================================
+ Hits 31447 31549 +102
+ Misses 24972 24939 -33
- Partials 2137 2140 +3
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
franciscojavierarceo
left a comment
There was a problem hiding this comment.
we need to finish the projection fix in the existing thread. the current-schema guard cannot account for retired Bigtable qualifiers, so requests can still fetch and retain large values that the previous per-view path excluded. the thread now has a concrete schema-evolution case to cover.
Feature views keyed on the same entities share one Bigtable table, and
each view's rows are keyed {entity_id}#{feature_view_name}. The generic
_read_features_per_fv still issued one ReadRows call per feature view.
BigtableOnlineStore now overrides _read_features_per_fv to group the
requested views by Bigtable table and fetch each table's rows with a
single ReadRows call, using the union of the requested feature columns.
Row keys shared by one view requested under several aliases are read
and decoded once. Single-view requests, and requests larger than the
new max_batched_result_rows (entity rows x feature views, default 2048,
0 turns batching off), keep the per-view path, as for PostgreSQL and
DynamoDB. So does a request whose union column filter would pass
16,000 bytes, because Bigtable rejects a row filter over 20 KB.
online_read and the batched path share a new _read_rows helper.
Refs feast-dev#3259
Signed-off-by: Edson <zhuoxi2000@gmail.com>
The column filter of a batched read is shared by every feature view of a Bigtable table, so it also matched a column that one view stores under the same name as a feature requested from another view. Those cells were read and decoded, then dropped when the response was built. A request where the shared filter would return such a column now reads one feature view at a time, like a request over the size limits. Signed-off-by: Edson <zhuoxi2000@gmail.com>
A batched read used one column filter for every feature view of a Bigtable table, and fell back to per-view reads when a view's current schema showed that the filter would return an unrequested column. That check could not see a column left behind by a feature that was later removed from a view: update keeps the table and online_write_batch only sets the cells it is given, so the old cells were still read and decoded. The filter of a batched read now has one branch per feature view, which matches the view's rows by row key and passes only the features requested from that view. A batched read returns the same cells as the per-view reads whatever the rows hold, so the schema check is gone. The size limit is applied to the whole filter, and a request naming a feature view whose name is not plain ASCII reads one view at a time. Signed-off-by: Edson <zhuoxi2000@gmail.com>
6717b40 to
a9d2318
Compare
What this PR does / why we need it:
Part of #3259:
get_online_featuresmakes one store call per feature view. As with Redis, PostgreSQL (#6832) and DynamoDB (#7134), this adds a per-store_read_features_per_fvoverride, here for Bigtable.Bigtable already co-locates what the issue asks to read together. Every feature view keyed on the same entities shares one Bigtable table (
_get_table_nameis built from the sorted entities and the project), and each view's rows are keyed{entity_id}#{feature_view_name}. The generic path still sent oneReadRowscall per feature view. Now the rows of all those views come back from one call.Changes in
sdk/python/feast/infra/online_stores/bigtable.py:BigtableOnlineStore._read_features_per_fvgroups the requested views by Bigtable table and issues oneReadRowscall per table. TheRowSetholds the row keys of every view in that table. Each view's rows are then picked out by row key, and_populate_response_from_feature_datais called ingrouped_refsorder, so the response layout is unchanged.RowFilterUnionwith one branch per feature view: aRowKeyRegexFiltermatching that view's row keys (^[0-9a-f]+#<escaped view name>$) chained with aColumnQualifierRegexFilterfor the features requested from that view plusevent_ts. A view requested without a feature list gets the row-key condition alone. A row key matches exactly one branch, so each view's rows pass only the columns requested from that view, as on the per-view path. This holds for whatever the rows contain, including a qualifier left behind by a feature that was later removed from the view. (The first commit used one column filter for the whole table and the second added a check against the views' schemas; both were replaced after review.)_process_bt_rowpopsevent_tsfrom the row's cells.max_batched_result_rows(entity rows × feature views, default 2048).max_batched_result_rows: 0turns batching off. The knob and its default mirror PostgreSQL and DynamoDB.MAX_BATCHED_FILTER_BYTES(16,000 bytes, a margin under the limit), the request keeps the generic path, so a wide request that works on master still sends the same per-view filters. The size is an upper bound computed from the regexes plus 32 bytes per view for the proto framing. With 24-character feature names this takes about 640 requested features in one table.online_readand the batched path share a new_read_rows(config, bt_table_name, row_keys, filter_)helper and the_column_filter/_column_filter_regexhelpers. Foronline_readthe filter expression and the found-rows-by-key mapping are the same as before.online_read_async.Docs: a "Bigtable exception" paragraph in
docs/how-to-guides/online-server-performance-tuning.mdnext to the Redis/PostgreSQL/DynamoDB ones, the Bigtable row in the store table there, and a "Batched Multi-Feature-View Reads" section indocs/reference/online-stores/bigtable.md.Not covered here:
max_read_workerscould follow if wanted.app_profile_idto thebt_instance.table(...)call inonline_read. That call now lives in_read_rows, so whichever lands second has to carry the argument there. I'll do it here if feat: Add Bigtable online store support for the Go feature server #7193 merges first.online_readto the versioned feature view name. Whichever of the two lands second also needs that versioned name in the row keys built by_read_features_per_fv, not only a rebase. I'm happy to do that here if feat: Add feature view versioning support to Bigtable online store #7013 merges first.Which issue(s) this PR fixes:
Refs #3259. That issue is labelled keep-open and covers several stores, so this PR does not close it.
Checks
git commit -s)Testing Strategy
New
sdk/python/tests/unit/infra/online_store/test_bigtable_batched_read.py. It followstest_bigtable_online_store.py: it usespytest.importorskip("google.cloud.bigtable")and patchesBigtableOnlineStore._get_client. The client is replaced by an in-memory fake that records everyread_rowscall and the cells it returns, and evaluates the union, chain, row-key regex and column-qualifier regex filters. The result tests also compare the response withOnlineStore._read_features_per_fvon the same data. The tests cover:read_rowscall with 6 row keys, instead of 3 calls; same response as the generic path.NOT_FOUND) and a repeated driver row.max_batched_result_rows0 / 3 / 4 for a 2-entity × 2-view request -> 2 / 2 / 1 calls; the default is 2048 and negative values are rejected.scoreandextra:scorefrom one andextrafrom the other; one of them without a feature list; the same features from both. Each is 1 call, and the fake returns the same feature cells as on the generic path.payloadqualifier that its schema no longer lists, withpayloadrequested from another view -> 1 call, the retired cell is not returned, same cells as the generic path..and#-> 1 call, same cells as the generic path.With
bigtable.pyfrom master (plus the two constants so the test module imports), 17 of the 19 new tests fail; the single-view test and the non-ASCII test pass there, since they check behaviour that already exists. Withbigtable.pyfrom the second commit (229c1f6), the retired-qualifier test fails because thepayloadcell of the first view is returned.Those are mock-level tests. I also ran a scratch script against Google's Bigtable emulator (
cloud.google.com/go/bigtable/cmd/emulator): it creates the tables withupdate, writes withonline_write_batch, and reads the same request through the batched path and throughOnlineStore._read_features_per_fv. The script also records the cells eachReadRowscall returns. Responses and cells were identical in all nine request shapes:ReadRowscalls, batchedpayloadqualifier,payloadrequested from another view.,#)The emulator does not enforce the 20 KB limit (it accepted a 22,852-byte filter when I forced batching on the first commit), so the fallback itself is covered by the unit test and the quota documentation, not by a rejected request. I did not run the LocalCloud test (
tests/localcloud/test_localcloud_gcp.py::test_bigtable_online_store_round_trip) or anything against a real Bigtable instance.ruff checkandruff format --check(0.16.9) pass on the touched files.mypyonfeast/infra/online_stores/bigtable.pyreports no issues.Misc
Size: +224/−23 in
bigtable.py, +7/−1 in docs, and +467 for the new test file (698 added lines in total; the PostgreSQL and DynamoDB PRs were +827 and +710).