SQLite online store lets an older write overwrite a newer value

オープン
#7,260 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, sqlite

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
7.4k
フォーク
1.5k
平均マージ
2日 6時間
マージ済み PR(30日)
107

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

feast-dev/feast のほかの issue

feast-dev/feast の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。