make replacement not delete, and filter query results respect limits
- Added detailed logging in GetSerialsByRange, CheckForDeleted, and SaveEvent functions to improve traceability during event processing. - Implemented safety limits in GetSerialsByRange to prevent infinite loops during debugging. - Updated event deletion logic to ensure only specific events are marked as deleted, improving clarity in event management. - Refactored WouldReplaceEvent to maintain compatibility while simplifying the return values. - Adjusted test cases to verify the correct behavior of replaced events and their deletion status.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"lol.mleku.dev/chk"
|
||||
"lol.mleku.dev/log"
|
||||
"next.orly.dev/pkg/database/indexes/types"
|
||||
)
|
||||
|
||||
@@ -28,14 +29,27 @@ func (d *D) GetSerialsByRange(idx Range) (
|
||||
for i := 0; i < 5; i++ {
|
||||
endBoundary = append(endBoundary, 0xff)
|
||||
}
|
||||
for it.Seek(endBoundary); it.Valid(); it.Next() {
|
||||
iterCount := 0
|
||||
it.Seek(endBoundary)
|
||||
log.T.F("GetSerialsByRange: iterator valid=%v, sought to endBoundary", it.Valid())
|
||||
for it.Valid() {
|
||||
iterCount++
|
||||
if iterCount > 100 {
|
||||
// Safety limit to prevent infinite loops in debugging
|
||||
log.T.F("GetSerialsByRange: hit safety limit of 100 iterations")
|
||||
break
|
||||
}
|
||||
item := it.Item()
|
||||
var key []byte
|
||||
key = item.Key()
|
||||
if bytes.Compare(
|
||||
key[:len(key)-5], idx.Start,
|
||||
) < 0 {
|
||||
keyWithoutSerial := key[:len(key)-5]
|
||||
cmp := bytes.Compare(keyWithoutSerial, idx.Start)
|
||||
log.T.F("GetSerialsByRange: iter %d, key prefix matches=%v, cmp=%d", iterCount, bytes.HasPrefix(key, idx.Start[:len(idx.Start)-8]), cmp)
|
||||
if cmp < 0 {
|
||||
// didn't find it within the timestamp range
|
||||
log.T.F("GetSerialsByRange: key out of range (cmp=%d), stopping iteration", cmp)
|
||||
log.T.F(" keyWithoutSerial len=%d: %x", len(keyWithoutSerial), keyWithoutSerial)
|
||||
log.T.F(" idx.Start len=%d: %x", len(idx.Start), idx.Start)
|
||||
return
|
||||
}
|
||||
ser := new(types.Uint40)
|
||||
@@ -44,7 +58,9 @@ func (d *D) GetSerialsByRange(idx Range) (
|
||||
return
|
||||
}
|
||||
sers = append(sers, ser)
|
||||
it.Next()
|
||||
}
|
||||
log.T.F("GetSerialsByRange: iteration complete, found %d serials", len(sers))
|
||||
return
|
||||
},
|
||||
); chk.E(err) {
|
||||
|
||||
Reference in New Issue
Block a user