add dgraph backend to benchmark suite with safe type assertions for multi-backend support
This commit is contained in:
@@ -10,12 +10,12 @@ import (
|
||||
"next.orly.dev/pkg/database/indexes/types"
|
||||
"next.orly.dev/pkg/encoders/event"
|
||||
"next.orly.dev/pkg/encoders/filter"
|
||||
"next.orly.dev/pkg/encoders/hex"
|
||||
// "next.orly.dev/pkg/encoders/hex"
|
||||
"next.orly.dev/pkg/encoders/tag"
|
||||
)
|
||||
|
||||
func (d *D) GetSerialById(id []byte) (ser *types.Uint40, err error) {
|
||||
log.T.F("GetSerialById: input id=%s", hex.Enc(id))
|
||||
// log.T.F("GetSerialById: input id=%s", hex.Enc(id))
|
||||
var idxs []Range
|
||||
if idxs, err = GetIndexesFromFilter(&filter.F{Ids: tag.NewFromBytesSlice(id)}); chk.E(err) {
|
||||
return
|
||||
@@ -58,7 +58,7 @@ func (d *D) GetSerialById(id []byte) (ser *types.Uint40, err error) {
|
||||
return
|
||||
}
|
||||
if !idFound {
|
||||
err = errorf.T("id not found in database: %s", hex.Enc(id))
|
||||
// err = errorf.T("id not found in database: %s", hex.Enc(id))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (d *D) GetSerialsByIds(ids *tag.T) (
|
||||
func (d *D) GetSerialsByIdsWithFilter(
|
||||
ids *tag.T, fn func(ev *event.E, ser *types.Uint40) bool,
|
||||
) (serials map[string]*types.Uint40, err error) {
|
||||
log.T.F("GetSerialsByIdsWithFilter: input ids count=%d", ids.Len())
|
||||
// log.T.F("GetSerialsByIdsWithFilter: input ids count=%d", ids.Len())
|
||||
|
||||
// Initialize the result map with estimated capacity to reduce reallocations
|
||||
serials = make(map[string]*types.Uint40, ids.Len())
|
||||
|
||||
@@ -33,7 +33,7 @@ func (d *D) GetSerialsByRange(idx Range) (
|
||||
}
|
||||
iterCount := 0
|
||||
it.Seek(endBoundary)
|
||||
log.T.F("GetSerialsByRange: iterator valid=%v, sought to endBoundary", it.Valid())
|
||||
// log.T.F("GetSerialsByRange: iterator valid=%v, sought to endBoundary", it.Valid())
|
||||
for it.Valid() {
|
||||
iterCount++
|
||||
if iterCount > 100 {
|
||||
@@ -46,12 +46,12 @@ func (d *D) GetSerialsByRange(idx Range) (
|
||||
key = item.Key()
|
||||
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)
|
||||
// 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)
|
||||
// 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)
|
||||
@@ -62,7 +62,7 @@ func (d *D) GetSerialsByRange(idx Range) (
|
||||
sers = append(sers, ser)
|
||||
it.Next()
|
||||
}
|
||||
log.T.F("GetSerialsByRange: iteration complete, found %d serials", len(sers))
|
||||
// log.T.F("GetSerialsByRange: iteration complete, found %d serials", len(sers))
|
||||
return
|
||||
},
|
||||
); chk.E(err) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"lol.mleku.dev/chk"
|
||||
"lol.mleku.dev/errorf"
|
||||
"lol.mleku.dev/log"
|
||||
"next.orly.dev/pkg/database/indexes/types"
|
||||
"next.orly.dev/pkg/encoders/event"
|
||||
"next.orly.dev/pkg/encoders/filter"
|
||||
@@ -21,7 +20,7 @@ import (
|
||||
// pubkeys that also may delete the event, normally only the author is allowed
|
||||
// to delete an event.
|
||||
func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
|
||||
log.T.F("CheckForDeleted: checking event %x", ev.ID)
|
||||
// log.T.F("CheckForDeleted: checking event %x", ev.ID)
|
||||
keys := append([][]byte{ev.Pubkey}, admins...)
|
||||
authors := tag.NewFromBytesSlice(keys...)
|
||||
// if the event is addressable, check for a deletion event with the same
|
||||
@@ -186,9 +185,9 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
|
||||
return
|
||||
}
|
||||
// otherwise we check for a delete by event id
|
||||
log.T.F("CheckForDeleted: checking for e-tag deletion of event %x", ev.ID)
|
||||
log.T.F("CheckForDeleted: authors filter: %v", authors)
|
||||
log.T.F("CheckForDeleted: looking for tag e with value: %s", hex.Enc(ev.ID))
|
||||
// log.T.F("CheckForDeleted: checking for e-tag deletion of event %x", ev.ID)
|
||||
// log.T.F("CheckForDeleted: authors filter: %v", authors)
|
||||
// log.T.F("CheckForDeleted: looking for tag e with value: %s", hex.Enc(ev.ID))
|
||||
var idxs []Range
|
||||
if idxs, err = GetIndexesFromFilter(
|
||||
&filter.F{
|
||||
@@ -201,18 +200,18 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
|
||||
); chk.E(err) {
|
||||
return
|
||||
}
|
||||
log.T.F("CheckForDeleted: found %d indexes", len(idxs))
|
||||
// log.T.F("CheckForDeleted: found %d indexes", len(idxs))
|
||||
var sers types.Uint40s
|
||||
for i, idx := range idxs {
|
||||
log.T.F("CheckForDeleted: checking index %d: %v", i, idx)
|
||||
for _, idx := range idxs {
|
||||
// log.T.F("CheckForDeleted: checking index %d: %v", i, idx)
|
||||
var s types.Uint40s
|
||||
if s, err = d.GetSerialsByRange(idx); chk.E(err) {
|
||||
return
|
||||
}
|
||||
log.T.F("CheckForDeleted: index %d returned %d serials", i, len(s))
|
||||
// log.T.F("CheckForDeleted: index %d returned %d serials", i, len(s))
|
||||
if len(s) > 0 {
|
||||
// Any e-tag deletion found means the exact event was deleted and cannot be resubmitted
|
||||
log.T.F("CheckForDeleted: found e-tag deletion for event %x", ev.ID)
|
||||
// log.T.F("CheckForDeleted: found e-tag deletion for event %x", ev.ID)
|
||||
err = errorf.E("blocked: %0x has been deleted", ev.ID)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -180,10 +180,10 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (
|
||||
if idxs, err = GetIndexesForEvent(ev, serial); chk.E(err) {
|
||||
return
|
||||
}
|
||||
log.T.F(
|
||||
"SaveEvent: generated %d indexes for event %x (kind %d)", len(idxs),
|
||||
ev.ID, ev.Kind,
|
||||
)
|
||||
// log.T.F(
|
||||
// "SaveEvent: generated %d indexes for event %x (kind %d)", len(idxs),
|
||||
// ev.ID, ev.Kind,
|
||||
// )
|
||||
|
||||
// Serialize event once to check size
|
||||
eventDataBuf := new(bytes.Buffer)
|
||||
@@ -247,10 +247,10 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (
|
||||
if err = txn.Set(keyBuf.Bytes(), nil); chk.E(err) {
|
||||
return
|
||||
}
|
||||
log.T.F(
|
||||
"SaveEvent: stored small event inline (%d bytes)",
|
||||
len(eventData),
|
||||
)
|
||||
// log.T.F(
|
||||
// "SaveEvent: stored small event inline (%d bytes)",
|
||||
// len(eventData),
|
||||
// )
|
||||
} else {
|
||||
// Large event: store separately with evt prefix
|
||||
keyBuf := new(bytes.Buffer)
|
||||
@@ -260,10 +260,10 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (
|
||||
if err = txn.Set(keyBuf.Bytes(), eventData); chk.E(err) {
|
||||
return
|
||||
}
|
||||
log.T.F(
|
||||
"SaveEvent: stored large event separately (%d bytes)",
|
||||
len(eventData),
|
||||
)
|
||||
// log.T.F(
|
||||
// "SaveEvent: stored large event separately (%d bytes)",
|
||||
// len(eventData),
|
||||
// )
|
||||
}
|
||||
|
||||
// Additionally, store replaceable/addressable events with specialized keys for direct access
|
||||
@@ -293,7 +293,7 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (
|
||||
if err = txn.Set(keyBuf.Bytes(), nil); chk.E(err) {
|
||||
return
|
||||
}
|
||||
log.T.F("SaveEvent: also stored addressable event with specialized key")
|
||||
// log.T.F("SaveEvent: also stored addressable event with specialized key")
|
||||
} else if isReplaceableEvent && isSmallEvent {
|
||||
// Replaceable event: also store with rev|pubkey_hash|kind|size|data
|
||||
pubHash := new(types.PubHash)
|
||||
@@ -340,7 +340,7 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (
|
||||
// This ensures subsequent queries will see the new event
|
||||
if d.queryCache != nil {
|
||||
d.queryCache.Invalidate()
|
||||
log.T.F("SaveEvent: invalidated query cache")
|
||||
// log.T.F("SaveEvent: invalidated query cache")
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user