SQLite online store lets an older write overwrite a newer value

Đang mở
#7,260 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, sqlite

Hướng nghiên cứu

Start by reading SqliteOnlineStore.online_write_batch and the SQLite online store tests; compare its upsert behavior with Redis online_write_batch, as described in the issue. Check how event_ts is stored and handled for older rows, especially the UTC migration in #7235. Done means older event timestamps cannot replace newer values while equal timestamps and legacy ISO text rows remain replaceable, with regression tests covering those cases.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Expected Behavior

The online store is supposed to hold the latest value per entity key (that's how docs/getting-started/components/online-store.md puts it), so a write whose event timestamp is older than the stored one shouldn't replace it. Redis already works this way: its online_write_batch skips any row that isn't newer than the timestamp it holds, a check that goes back to #1961 and was extended to rows inside a single batch in #6656.

Current Behavior

SqliteOnlineStore.online_write_batch upserts with ON CONFLICT(entity_key, feature_name) DO UPDATE SET ... and no condition, so whatever arrives last wins no matter its event time. A feast materialize over an older window, a delayed push or a late batch rolls the entity back to the older value, and get_online_features keeps serving it until something newer gets written. Since SQLite is the default store from feast init, this is the one most people start on.

Steps to reproduce

import os
import tempfile
from datetime import datetime, timedelta, timezone

import pandas as pd

from feast import Entity, FeatureStore, FeatureView, Field, FileSource
from feast.types import Float32
from feast.value_type import ValueType

tmp = tempfile.mkdtemp()
now = datetime.now(timezone.utc).replace(microsecond=0)
src = os.path.join(tmp, "stats.parquet")
pd.DataFrame({"user_id": [42], "ts": [now], "a": [0.0]}).to_parquet(src)
with open(os.path.join(tmp, "feature_store.yaml"), "w") as f:
    f.write(
        f"project: repro\nregistry: {tmp}/registry.db\nprovider: local\n"
        f"online_store:\n  type: sqlite\n  path: {tmp}/online.db\n"
        "offline_store:\n  type: dask\nentity_key_serialization_version: 3\n"
    )

user = Entity(name="user", join_keys=["user_id"], value_type=ValueType.INT64)
fv = FeatureView(
    name="u_fv",
    entities=[user],
    ttl=timedelta(days=1),
    schema=[Field(name="a", dtype=Float32)],
    source=FileSource(path=src, timestamp_field="ts"),
)
fs = FeatureStore(repo_path=tmp)
fs.apply([user, fv])


def write(hours_ago, a):
    row = pd.DataFrame({"user_id": [42], "ts": [now - timedelta(hours=hours_ago)], "a": [a]})
    fs.write_to_online_store("u_fv", row)


def read():
    return fs.get_online_features(["u_fv:a"], [{"user_id": 42}]).to_dict()["a"][0]


write(1, 2.0)
print("after write at now-1h:", read())
write(5, -1.0)
print("after write at now-5h:", read())

On master (136e3b102) this prints:

after write at now-1h: 2.0
after write at now-5h: -1.0
Specifications
  • Version: master at 136e3b102
  • Platform: macOS, Python 3.12, SQLite 3.53.1
  • Subsystem: SQLite online store

Possible Solution

Add a WHERE to the upsert so the row is only replaced when excluded.event_ts >= event_ts. With that, the script above prints 2.0 both times. Equal timestamps would still overwrite so re-materializing the same window stays idempotent, and rows written before #4797 (ISO text in event_ts, which SQLite sorts above any integer) have to stay replaceable. I have this on a branch with tests and can open a PR.

There's one interaction I'd like your take on first. #7235 switches the stored epochs to UTC. On a host west of UTC, rows written before that change hold epochs that are ahead of the real event time by the UTC offset, so with the guard they'd block newer writes, including the full feast materialize backfill that #7235's upgrade notes recommend, until event times catch up (five hours in New York). I could land this after #7235 and add to its upgrade notes that those hosts should rebuild the SQLite file, or put the check behind an option. Which would you rather have? Postgres looks like it has the same unconditional upsert too, but I've only checked SQLite.

Ngôn ngữ chính
Python
Star
7.4k
Fork
1.5k
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
107

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của feast-dev/feast

Tất cả issue của feast-dev/feast

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.