SQLite online store lets an older write overwrite a newer value

Aperta
#7,260 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, sqlite

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
7.4k
Fork
1.5k
Merge medio
2g 6h
PR unite (30g)
107

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di feast-dev/feast

Tutte le issue di feast-dev/feast

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.