Skip to content

Commit e7b394c

Browse files
committed
Refactor compaction logic with TODO comments
1 parent 9e5673d commit e7b394c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

store/lsm_store.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,12 @@ func (s *pebbleStore) ApplyMutations(ctx context.Context, mutations []*KVPairMut
481481
}
482482

483483
func (s *pebbleStore) Compact(ctx context.Context, minTS uint64) error {
484-
// Real Compaction in LSM is hard to trigger precisely for MVCC GC.
485-
// We can set a CompactionFilter in Options that drops keys with TS < minTS
486-
// IF there is a newer version > minTS.
487-
// But Options are set at Open.
488-
// Updating options dynamically is not fully supported for CompactionFilter in standard Pebble API simply.
489-
// However, we can use DeleteRange for VERY old data if we knew the keys.
490-
// For this assignment, we will simply log.
484+
// TODO: Implement MVCC garbage collection.
485+
// We should iterate through all keys and remove versions older than minTS,
486+
// keeping at least one version <= minTS for snapshot consistency.
487+
// This is a heavy operation and should be done in the background or using
488+
// a Pebble CompactionFilter if possible.
489+
// For now, we simply log the request.
491490
s.log.Info("Compact requested", slog.Uint64("minTS", minTS))
492491
return nil
493492
}
@@ -514,7 +513,7 @@ func (s *pebbleStore) Snapshot() (io.ReadWriter, error) {
514513

515514
buf := &bytes.Buffer{}
516515

517-
// Format: [LastCommitTS] [Count] [KeyLen] [Key] [ValLen] [Val] ...
516+
// Format: [LastCommitTS] [KeyLen] [Key] [ValLen] [Val] ...
518517

519518
// We need to persist s.lastCommitTS too.
520519

0 commit comments

Comments
 (0)