From b85d91175c518b4e28339a589a3ef9da20864fbd Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 16 Nov 2023 09:29:31 -0800 Subject: [PATCH] updates --- store/storage/sqlite/db.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/store/storage/sqlite/db.go b/store/storage/sqlite/db.go index 02b1fee84f67..eded6cf60878 100644 --- a/store/storage/sqlite/db.go +++ b/store/storage/sqlite/db.go @@ -189,15 +189,18 @@ func (db *Database) ApplyChangeset(version uint64, cs *store.Changeset) error { return b.Write() } +// Prune removes all versions of all keys that are <= the given version. It keeps +// the latest (non-tombstoned) version of each key/value tuple to handle queries +// above the prune version. This is analogous to RocksDB full_history_ts_low. +// +// We perform the prune by deleting all versions of a key, excluding reserved keys, +// that are <= the given version, except for the latest version of the key. func (db *Database) Prune(version uint64) error { tx, err := db.storage.Begin() if err != nil { return fmt.Errorf("failed to create SQL transaction: %w", err) } - // Delete all versions less than or equal to the target version, except we keep - // the last one to handle above the prune version. This is analogous to RocksDB - // full_history_ts_low. pruneStmt := `DELETE FROM state_storage WHERE version < ( SELECT max(version) FROM state_storage t2 WHERE