Skip to content

Commit

Permalink
FIXMEs for current snapshot deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest committed Oct 3, 2024
1 parent b716f35 commit 3445f29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type Deallocator struct {

// Deallocate adds node to the deallocation list.
func (d Deallocator) Deallocate(nodeAddress NodeAddress, srcSnapshotID SnapshotID) {
if srcSnapshotID == d.snapshotID {
// FIXME (wojciech): Deallocate immediately
return
}

listNodeAddress, _ := d.deallocationLists.Get(srcSnapshotID)
list := NewList(ListConfig{
SnapshotID: d.snapshotID,
Expand Down
2 changes: 2 additions & 0 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type SnapshotConfig struct {

// NewSnapshot creates new snapshot.
func NewSnapshot(config SnapshotConfig) (Snapshot, error) {
// FIXME (wojciech): If it's the already-committed snapshot, mark it as read-only.

if config.SnapshotID == 0 {
config.Allocator.Allocate()
}
Expand Down
7 changes: 6 additions & 1 deletion space.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (s *Space[K, V]) set(pInfo ParentInfo, item DataItem[K, V]) {

return
case stateData:
// FIXME (wojciech): Don't copy the node if split is required.

dataNodeData, dataNode := s.config.DataNodeAllocator.Get(*pInfo.Item)
if dataNode.Header.SnapshotID < s.config.SnapshotID {
newNodeAddress, newNode := s.config.DataNodeAllocator.Copy(dataNodeData)
Expand Down Expand Up @@ -160,7 +162,8 @@ func (s *Space[K, V]) set(pInfo ParentInfo, item DataItem[K, V]) {
}

func (s *Space[K, V]) redistributeNode(pInfo ParentInfo) {
_, dataNode := s.config.DataNodeAllocator.Get(*pInfo.Item)
dataNodeAddress := *pInfo.Item
_, dataNode := s.config.DataNodeAllocator.Get(dataNodeAddress)

pointerNodeAddress, pointerNode := s.config.PointerNodeAllocator.Allocate()
*pointerNode.Header = SpaceNodeHeader{
Expand All @@ -178,6 +181,8 @@ func (s *Space[K, V]) redistributeNode(pInfo ParentInfo) {

s.set(pInfo, dataNode.Items[i])
}

s.config.Deallocator.Deallocate(dataNodeAddress, dataNode.Header.SnapshotID)
}

func hashKey[K comparable](key K, hashMod uint64) Hash {
Expand Down

0 comments on commit 3445f29

Please sign in to comment.