Skip to content

Commit

Permalink
Optimize update detection (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest authored Nov 21, 2024
1 parent a037a97 commit edc7c2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
// StoreCapacity is the maximum capacity of store array in store request.
StoreCapacity = 10

sleepDuration = 10 * time.Microsecond
atomicDivider = 100
)

Expand Down Expand Up @@ -143,7 +144,7 @@ func (qr *Reader) Read(ctx context.Context) (*TransactionRequest, error) {
break
}

time.Sleep(10 * time.Microsecond)
time.Sleep(sleepDuration)

if ctx.Err() != nil {
return nil, errors.WithStack(ctx.Err())
Expand Down
35 changes: 18 additions & 17 deletions space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"unsafe"

"github.com/cespare/xxhash"
"github.com/samber/lo"

"github.com/outofforest/mass"
"github.com/outofforest/photon"
Expand All @@ -33,7 +34,8 @@ func New[K, V comparable](config Config[K, V]) *Space[K, V] {
}

defaultInit := Entry[K, V]{
space: s,
space: s,
nextDataNodeState: lo.ToPtr(types.StateFree),
storeRequest: pipeline.StoreRequest{
NoSnapshots: s.config.NoSnapshots,
PointersToStore: 1,
Expand Down Expand Up @@ -584,7 +586,7 @@ func (s *Space[K, V]) walkPointers(v *Entry[K, V], hashBuff []byte) {
v.storeRequest.PointersToStore++
v.parentIndex = index
if nextIndex == index {
v.nextDataNodeState = nil
v.nextDataNodeState = lo.ToPtr(types.StateFree)
} else {
v.nextDataNodeState = &pointerNode.Pointers[nextIndex].State
}
Expand Down Expand Up @@ -629,19 +631,19 @@ func (s *Space[K, V]) walkDataItems(v *Entry[K, V], hashMatches []uint64) bool {

// Entry represents entry in the space.
type Entry[K, V comparable] struct {
space *Space[K, V]
storeRequest pipeline.StoreRequest

itemP *types.DataItem[K, V]
keyHashP *types.KeyHash
keyHash types.KeyHash
key K
value V
space *Space[K, V]
nextDataNodeState *types.State
parentIndex uint64
dataItemIndex uint64
exists bool
level uint8
storeRequest pipeline.StoreRequest

itemP *types.DataItem[K, V]
keyHashP *types.KeyHash
keyHash types.KeyHash
key K
value V
parentIndex uint64
dataItemIndex uint64
exists bool
level uint8
}

// Value returns the value from entry.
Expand Down Expand Up @@ -710,15 +712,14 @@ func dataItemIndex(keyHash types.KeyHash, numOfDataItems uint64) uint64 {
}

func detectUpdate[K, V comparable](v *Entry[K, V]) {
pointer := v.storeRequest.Store[v.storeRequest.PointersToStore-1].Pointer
switch {
case v.nextDataNodeState != nil && *v.nextDataNodeState != types.StateFree:
case *v.nextDataNodeState != types.StateFree:
v.storeRequest.PointersToStore--
v.level--

v.keyHashP = nil
v.itemP = nil
case v.keyHashP != nil && (pointer.State != types.StateData ||
case v.keyHashP != nil && (v.storeRequest.Store[v.storeRequest.PointersToStore-1].Pointer.State != types.StateData ||
(*v.keyHashP != 0 && (*v.keyHashP != v.keyHash || v.itemP.Key != v.key))):
v.keyHashP = nil
v.itemP = nil
Expand Down

0 comments on commit edc7c2d

Please sign in to comment.