fix: resolve all 55 identified bugs across the codebase

Comprehensive bug fix pass across all subsystems:
- Critical: lexer infinite loop, WAL lock discipline, checkpoint safety,
  compaction verification, HMAC key truncation, healthCheck leak
- High: MVCC lock safety, B-Tree delete rebalancing, Raft stale term
  handling, replication socket leaks and ack cleanup, sharding migration
  with old assignments, 2PC recovery, JWT/SCRAM auth fixes, wire protocol
  bounds checks
- Medium: config error handling, MERGE parser completeness, IR/codegen
  correctness, UDF bounds checks, LIMIT cost accuracy, mmap safety
- Low: timeout handling, float parsing edge cases, uint32 truncation,
  cache entry cleanup

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 10:59:51 +03:00
parent 7fc6adbe47
commit 2d310a33a1
23 changed files with 765 additions and 207 deletions
+18 -7
View File
@@ -72,6 +72,7 @@ proc compact*(cs: CompactionStrategy, level: int): CompactionResult =
var allEntries: seq[Entry] = @[]
# Read all entries from SSTable files
var failedLoad = false
for t in tables:
try:
let sst = loadSSTable(t.path)
@@ -80,8 +81,13 @@ proc compact*(cs: CompactionStrategy, level: int): CompactionResult =
if found:
allEntries.add(entry)
inc entriesRead
except:
discard
except CatchableError as e:
echo "[ERROR] Failed to load SSTable for compaction: ", t.path, ": ", e.msg
failedLoad = true
break
if failedLoad:
return CompactionResult()
# Sort by key, then by timestamp (newest first for dedup)
allEntries.sort(proc(a, b: Entry): int =
@@ -120,12 +126,19 @@ proc compact*(cs: CompactionStrategy, level: int): CompactionResult =
createdAt: tables[^1].createdAt,
)
# Verify output SSTable before deleting sources
let (ok, msg) = verifySSTable(outputPath)
if not ok:
echo "[ERROR] Compaction output verification failed: ", msg
try: removeFile(outputPath) except: discard
return CompactionResult()
# Remove old SSTable files
for t in tables:
try:
removeFile(t.path)
except:
discard
except CatchableError as e:
echo "[WARN] Failed to remove old SSTable: ", t.path, ": ", e.msg
# Update level arrays
var newTables: seq[SSTableMeta] = @[]
@@ -166,7 +179,6 @@ type
key*: string
data*: seq[byte]
accessCount*: int
lastAccess*: int64
dirty*: bool
PageCache* = ref object
@@ -196,7 +208,6 @@ proc evict*(cache: PageCache) =
proc put*(cache: PageCache, key: string, data: seq[byte]) =
if key in cache.pages:
cache.pages[key].data = data
cache.pages[key].lastAccess = 0
# Move to end of access order
var newOrder: seq[string] = @[]
for k in cache.accessOrder:
@@ -208,7 +219,7 @@ proc put*(cache: PageCache, key: string, data: seq[byte]) =
cache.evict()
cache.pages[key] = CacheEntry(
key: key, data: data,
accessCount: 1, lastAccess: 0, dirty: false,
accessCount: 1, dirty: false,
)
cache.accessOrder.add(key)