Skip to content

Commit

Permalink
Pass space entries by pointers (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest authored Oct 20, 2024
1 parent 80b61b7 commit ae156d1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 50 deletions.
8 changes: 3 additions & 5 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func BenchmarkBalanceTransfer(b *testing.B) {

for i := 0; i < numOfAddresses; i += 2 {
v := s.Get(accounts[i], pointerNode, dataNode)
_, err := v.Set(2*balance, pool, pointerNode, dataNode)
if err != nil {
if err := v.Set(2*balance, pool, pointerNode, dataNode); err != nil {
panic(err)
}

Expand All @@ -108,15 +107,15 @@ func BenchmarkBalanceTransfer(b *testing.B) {
senderBalance := s.Get(senderAddress, pointerNode, dataNode)
recipientBalance := s.Get(recipientAddress, pointerNode, dataNode)

if _, err := senderBalance.Set(
if err := senderBalance.Set(
senderBalance.Value()-balance,
pool,
pointerNode,
dataNode,
); err != nil {
panic(err)
}
if _, err := recipientBalance.Set(
if err := recipientBalance.Set(
recipientBalance.Value()+balance,
pool,
pointerNode,
Expand All @@ -137,7 +136,6 @@ func BenchmarkBalanceTransfer(b *testing.B) {
}
}
}

b.StopTimer()
}()

Expand Down
24 changes: 17 additions & 7 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
"github.com/samber/lo"

"github.com/outofforest/mass"
"github.com/outofforest/parallel"
"github.com/outofforest/photon"
"github.com/outofforest/quantum/alloc"
Expand All @@ -24,7 +25,7 @@ type Config struct {
type SpaceToCommit struct {
HashMod *uint64
PInfo types.ParentEntry
SpaceInfoValue space.Entry[types.SpaceID, types.SpaceInfo]
SpaceInfoValue *space.Entry[types.SpaceID, types.SpaceInfo]
OriginalPointer types.SpacePointer
}

Expand Down Expand Up @@ -89,6 +90,7 @@ func New(config Config) (*DB, error) {
snapshotToNodeNode: snapshotToNodeNodeAllocator.NewNode(),
spaceInfoNode: spaceInfoNodeAllocator.NewNode(),
listNode: listNodeAllocator.NewNode(),
massSnapshotToNodeEntry: mass.New[space.Entry[types.SnapshotID, types.Pointer]](1000),
spacesToCommit: map[types.SpaceID]SpaceToCommit{},
deallocationListsToCommit: map[types.SnapshotID]ListToCommit{},
availableSnapshots: map[types.SnapshotID]struct{}{},
Expand All @@ -105,6 +107,7 @@ func New(config Config) (*DB, error) {
State: config.State,
PointerNodeAllocator: pointerNodeAllocator,
DataNodeAllocator: snapshotInfoNodeAllocator,
MassEntry: mass.New[space.Entry[types.SnapshotID, types.SnapshotInfo]](1000),
StorageEventCh: db.storageEventCh,
})

Expand All @@ -117,6 +120,7 @@ func New(config Config) (*DB, error) {
State: config.State,
PointerNodeAllocator: pointerNodeAllocator,
DataNodeAllocator: spaceInfoNodeAllocator,
MassEntry: mass.New[space.Entry[types.SpaceID, types.SpaceInfo]](1000),
StorageEventCh: db.storageEventCh,
})

Expand All @@ -130,6 +134,7 @@ func New(config Config) (*DB, error) {
State: config.State,
PointerNodeAllocator: pointerNodeAllocator,
DataNodeAllocator: snapshotToNodeNodeAllocator,
MassEntry: mass.New[space.Entry[types.SnapshotID, types.Pointer]](1000),
StorageEventCh: db.storageEventCh,
},
)
Expand Down Expand Up @@ -161,6 +166,8 @@ type DB struct {
spaceInfoNode *space.Node[space.DataNodeHeader, types.DataItem[types.SpaceID, types.SpaceInfo]]
listNode *list.Node

massSnapshotToNodeEntry *mass.Mass[space.Entry[types.SnapshotID, types.Pointer]]

spacesToCommit map[types.SpaceID]SpaceToCommit
deallocationListsToCommit map[types.SnapshotID]ListToCommit
availableSnapshots map[types.SnapshotID]struct{}
Expand Down Expand Up @@ -203,6 +210,7 @@ func (db *DB) DeleteSnapshot(snapshotID types.SnapshotID, pool *alloc.Pool[types
State: db.config.State,
PointerNodeAllocator: db.pointerNodeAllocator,
DataNodeAllocator: db.snapshotToNodeNodeAllocator,
MassEntry: db.massSnapshotToNodeEntry,
StorageEventCh: db.storageEventCh,
},
)
Expand Down Expand Up @@ -245,6 +253,7 @@ func (db *DB) DeleteSnapshot(snapshotID types.SnapshotID, pool *alloc.Pool[types
State: db.config.State,
PointerNodeAllocator: db.pointerNodeAllocator,
DataNodeAllocator: db.snapshotToNodeNodeAllocator,
MassEntry: db.massSnapshotToNodeEntry,
},
)

Expand All @@ -265,7 +274,7 @@ func (db *DB) DeleteSnapshot(snapshotID types.SnapshotID, pool *alloc.Pool[types
return err
}
if newNextListNodeAddress != nextListNodeAddress {
if _, err := nextDeallocationListValue.Set(
if err := nextDeallocationListValue.Set(
newNextListNodeAddress,
pool,
db.pointerNode,
Expand All @@ -288,7 +297,7 @@ func (db *DB) DeleteSnapshot(snapshotID types.SnapshotID, pool *alloc.Pool[types

if snapshotInfo.NextSnapshotID < db.singularityNode.LastSnapshotID {
nextSnapshotInfoValue := db.snapshots.Get(snapshotInfo.NextSnapshotID, db.pointerNode, db.snapshotInfoNode)
if _, err := nextSnapshotInfoValue.Set(
if err := nextSnapshotInfoValue.Set(
*nextSnapshotInfo,
pool,
db.pointerNode,
Expand All @@ -308,7 +317,7 @@ func (db *DB) DeleteSnapshot(snapshotID types.SnapshotID, pool *alloc.Pool[types
previousSnapshotInfo := previousSnapshotInfoValue.Value()
previousSnapshotInfo.NextSnapshotID = snapshotInfo.NextSnapshotID

if _, err := previousSnapshotInfoValue.Set(
if err := previousSnapshotInfoValue.Set(
previousSnapshotInfo,
pool,
db.pointerNode,
Expand Down Expand Up @@ -349,7 +358,7 @@ func (db *DB) Commit(pool *alloc.Pool[types.LogicalAddress]) error {
continue
}
spaceToCommit.OriginalPointer = *spaceToCommit.PInfo.SpacePointer
if _, err := spaceToCommit.SpaceInfoValue.Set(types.SpaceInfo{
if err := spaceToCommit.SpaceInfoValue.Set(types.SpaceInfo{
HashMod: *spaceToCommit.HashMod,
State: *spaceToCommit.PInfo.State,
Pointer: *spaceToCommit.PInfo.SpacePointer,
Expand All @@ -364,7 +373,7 @@ func (db *DB) Commit(pool *alloc.Pool[types.LogicalAddress]) error {
}

nextSnapshotInfoValue := db.snapshots.Get(db.singularityNode.LastSnapshotID, db.pointerNode, db.snapshotInfoNode)
if _, err := nextSnapshotInfoValue.Set(
if err := nextSnapshotInfoValue.Set(
db.snapshotInfo,
pool,
db.pointerNode,
Expand Down Expand Up @@ -515,7 +524,7 @@ func (db *DB) commitDeallocationLists(pool *alloc.Pool[types.LogicalAddress]) er
sort.Slice(lists, func(i, j int) bool { return lists[i] < lists[j] })

for _, snapshotID := range lists {
_, err := db.deallocationLists.Get(snapshotID, db.pointerNode, db.snapshotToNodeNode).
err := db.deallocationLists.Get(snapshotID, db.pointerNode, db.snapshotToNodeNode).
Set(*db.deallocationListsToCommit[snapshotID].ListRoot, pool, db.pointerNode, db.snapshotToNodeNode)
if err != nil {
return err
Expand Down Expand Up @@ -558,5 +567,6 @@ func GetSpace[K, V comparable](spaceID types.SpaceID, db *DB) (*space.Space[K, V
StorageEventCh: db.storageEventCh,
PointerNodeAllocator: db.pointerNodeAllocator,
DataNodeAllocator: dataNodeAllocator,
MassEntry: mass.New[space.Entry[K, V]](1000),
}), nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
require (
github.com/cespare/xxhash v1.1.0
github.com/outofforest/logger v0.5.5
github.com/outofforest/mass v0.2.1
github.com/outofforest/parallel v0.2.3
github.com/outofforest/photon v0.6.0
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/outofforest/logger v0.3.3/go.mod h1:+M5sO17Va9V33t28Qs9VqRQ8bFV501Uhq2PtQY+R3Ms=
github.com/outofforest/logger v0.5.5 h1:ndsFPPojrRMH2BZzk1MOmf+imooVqrzOG78NSqGfx/Q=
github.com/outofforest/logger v0.5.5/go.mod h1:+h+DeEKd7Q2kYrRy8qME0cTgl8+7SqeFDWCti9cIgVk=
github.com/outofforest/mass v0.2.1 h1:oIzOnoTJqN8eVXo5jxk1htOhW7bL7hy2JHrvnTsfvtU=
github.com/outofforest/mass v0.2.1/go.mod h1:rqr19KwYSKncmsmZCmMatTsg8pI+ElxerH9v1SGU1CQ=
github.com/outofforest/parallel v0.2.3 h1:DRIgHr7XTL4LLgsTqrj041kulv4ajtbCkRbkOG5psWY=
github.com/outofforest/parallel v0.2.3/go.mod h1:cu210xIjJtOMXR2ERzEcNA2kr0Z0xfZjSKw2jTxAQ2E=
github.com/outofforest/photon v0.6.0 h1:wJo8fZ/N4nCr0qsm/b7BlC3JktwNwSp5BzLha+joBDU=
Expand Down
Loading

0 comments on commit ae156d1

Please sign in to comment.