From d65a95a2c667bdb2b1b5a6fd0c2b86ec64b2e752 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 25 Jan 2023 14:12:02 +0300 Subject: [PATCH] [#28] pilorama: Remove `LogMove` struct Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/tree.go | 4 ++-- pkg/local_object_storage/pilorama/batch.go | 2 +- pkg/local_object_storage/pilorama/boltdb.go | 24 +++++++++---------- pkg/local_object_storage/pilorama/forest.go | 6 ++--- .../pilorama/interface.go | 4 ++-- pkg/local_object_storage/pilorama/types.go | 3 --- pkg/local_object_storage/shard/tree.go | 4 ++-- pkg/services/tree/replicator.go | 4 ++-- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/pkg/local_object_storage/engine/tree.go b/pkg/local_object_storage/engine/tree.go index eb80e25b..c52e345f 100644 --- a/pkg/local_object_storage/engine/tree.go +++ b/pkg/local_object_storage/engine/tree.go @@ -12,7 +12,7 @@ import ( var _ pilorama.Forest = (*StorageEngine)(nil) // TreeMove implements the pilorama.Forest interface. -func (e *StorageEngine) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) { +func (e *StorageEngine) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.Move, error) { index, lst, err := e.getTreeShard(d.CID, treeID) if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) { return nil, err @@ -32,7 +32,7 @@ func (e *StorageEngine) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pil } // TreeAddByPath implements the pilorama.Forest interface. -func (e *StorageEngine) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, m []pilorama.KeyValue) ([]pilorama.LogMove, error) { +func (e *StorageEngine) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, m []pilorama.KeyValue) ([]pilorama.Move, error) { index, lst, err := e.getTreeShard(d.CID, treeID) if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) { return nil, err diff --git a/pkg/local_object_storage/pilorama/batch.go b/pkg/local_object_storage/pilorama/batch.go index 30f14ffd..59712b76 100644 --- a/pkg/local_object_storage/pilorama/batch.go +++ b/pkg/local_object_storage/pilorama/batch.go @@ -41,7 +41,7 @@ func (b *batch) run() { return err } - var lm LogMove + var lm Move return b.forest.applyOperation(bLog, bTree, b.operations, &lm) }) for i := range b.operations { diff --git a/pkg/local_object_storage/pilorama/boltdb.go b/pkg/local_object_storage/pilorama/boltdb.go index f2eda28d..4b1a5e95 100644 --- a/pkg/local_object_storage/pilorama/boltdb.go +++ b/pkg/local_object_storage/pilorama/boltdb.go @@ -142,7 +142,7 @@ func (t *boltForest) Close() error { } // TreeMove implements the Forest interface. -func (t *boltForest) TreeMove(d CIDDescriptor, treeID string, m *Move) (*LogMove, error) { +func (t *boltForest) TreeMove(d CIDDescriptor, treeID string, m *Move) (*Move, error) { if !d.checkValid() { return nil, ErrInvalidCIDDescriptor } @@ -193,7 +193,7 @@ func (t *boltForest) TreeExists(cid cidSDK.ID, treeID string) (bool, error) { } // TreeAddByPath implements the Forest interface. -func (t *boltForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]LogMove, error) { +func (t *boltForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]Move, error) { if !d.checkValid() { return nil, ErrInvalidCIDDescriptor } @@ -210,7 +210,7 @@ func (t *boltForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string, return nil, ErrReadOnlyMode } - var lm []LogMove + var lm []Move var key [17]byte fullID := bucketName(d.CID, treeID) @@ -226,7 +226,7 @@ func (t *boltForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string, } ts := t.getLatestTimestamp(bLog, d.Position, d.Size) - lm = make([]LogMove, len(path)-i+1) + lm = make([]Move, len(path)-i+1) for j := i; j < len(path); j++ { lm[j-i] = Move{ Parent: node, @@ -329,7 +329,7 @@ func (t *boltForest) TreeApply(d CIDDescriptor, treeID string, m *Move, backgrou return err } - var lm LogMove + var lm Move return t.applyOperation(bLog, bTree, []*Move{m}, &lm) }) } @@ -404,8 +404,8 @@ func (t *boltForest) getTreeBuckets(tx *bbolt.Tx, treeRoot []byte) (*bbolt.Bucke } // applyOperations applies log operations. Assumes lm are sorted by timestamp. -func (t *boltForest) applyOperation(logBucket, treeBucket *bbolt.Bucket, ms []*Move, lm *LogMove) error { - var tmp LogMove +func (t *boltForest) applyOperation(logBucket, treeBucket *bbolt.Bucket, ms []*Move, lm *Move) error { + var tmp Move var cKey [17]byte c := logBucket.Cursor() @@ -460,7 +460,7 @@ func (t *boltForest) applyOperation(logBucket, treeBucket *bbolt.Bucket, ms []*M return nil } -func (t *boltForest) do(lb *bbolt.Bucket, b *bbolt.Bucket, key []byte, op *LogMove) error { +func (t *boltForest) do(lb *bbolt.Bucket, b *bbolt.Bucket, key []byte, op *Move) error { binary.BigEndian.PutUint64(key, op.Time) rawLog := t.logToBytes(op) if err := lb.Put(key[:8], rawLog); err != nil { @@ -470,7 +470,7 @@ func (t *boltForest) do(lb *bbolt.Bucket, b *bbolt.Bucket, key []byte, op *LogMo return t.redo(b, key, op, rawLog[16:]) } -func (t *boltForest) redo(b *bbolt.Bucket, key []byte, op *LogMove, rawMeta []byte) error { +func (t *boltForest) redo(b *bbolt.Bucket, key []byte, op *Move, rawMeta []byte) error { var err error parent, ts, currMeta, inTree := t.getState(b, stateKey(key, op.Child)) @@ -555,7 +555,7 @@ func (t *boltForest) addNode(b *bbolt.Bucket, key []byte, child, parent Node, ti return nil } -func (t *boltForest) undo(m *LogMove, b *bbolt.Bucket, key []byte) error { +func (t *boltForest) undo(m *Move, b *bbolt.Bucket, key []byte) error { if err := b.Delete(childrenKey(key, m.Child, m.Parent)); err != nil { return err } @@ -834,13 +834,13 @@ func (t *boltForest) moveFromBytes(m *Move, data []byte) error { return t.logFromBytes(m, data) } -func (t *boltForest) logFromBytes(lm *LogMove, data []byte) error { +func (t *boltForest) logFromBytes(lm *Move, data []byte) error { lm.Child = binary.LittleEndian.Uint64(data) lm.Parent = binary.LittleEndian.Uint64(data[8:]) return lm.Meta.FromBytes(data[16:]) } -func (t *boltForest) logToBytes(lm *LogMove) []byte { +func (t *boltForest) logToBytes(lm *Move) []byte { w := io.NewBufBinWriter() size := 8 + 8 + lm.Meta.Size() + 1 //if lm.HasOld { diff --git a/pkg/local_object_storage/pilorama/forest.go b/pkg/local_object_storage/pilorama/forest.go index 975eb8b0..5b1896e2 100644 --- a/pkg/local_object_storage/pilorama/forest.go +++ b/pkg/local_object_storage/pilorama/forest.go @@ -25,7 +25,7 @@ func NewMemoryForest() ForestStorage { } // TreeMove implements the Forest interface. -func (f *memoryForest) TreeMove(d CIDDescriptor, treeID string, op *Move) (*LogMove, error) { +func (f *memoryForest) TreeMove(d CIDDescriptor, treeID string, op *Move) (*Move, error) { if !d.checkValid() { return nil, ErrInvalidCIDDescriptor } @@ -48,7 +48,7 @@ func (f *memoryForest) TreeMove(d CIDDescriptor, treeID string, op *Move) (*LogM } // TreeAddByPath implements the Forest interface. -func (f *memoryForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, m []KeyValue) ([]LogMove, error) { +func (f *memoryForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, m []KeyValue) ([]Move, error) { if !d.checkValid() { return nil, ErrInvalidCIDDescriptor } @@ -64,7 +64,7 @@ func (f *memoryForest) TreeAddByPath(d CIDDescriptor, treeID string, attr string } i, node := s.getPathPrefix(attr, path) - lm := make([]LogMove, len(path)-i+1) + lm := make([]Move, len(path)-i+1) for j := i; j < len(path); j++ { op := s.do(&Move{ Parent: node, diff --git a/pkg/local_object_storage/pilorama/interface.go b/pkg/local_object_storage/pilorama/interface.go index 6ddfb848..238843dd 100644 --- a/pkg/local_object_storage/pilorama/interface.go +++ b/pkg/local_object_storage/pilorama/interface.go @@ -11,11 +11,11 @@ type Forest interface { // TreeMove moves node in the tree. // If the parent of the move operation is TrashID, the node is removed. // If the child of the move operation is RootID, new ID is generated and added to a tree. - TreeMove(d CIDDescriptor, treeID string, m *Move) (*LogMove, error) + TreeMove(d CIDDescriptor, treeID string, m *Move) (*Move, error) // TreeAddByPath adds new node in the tree using provided path. // The path is constructed by descending from the root using the values of the attr in meta. // Internal nodes in path should have exactly one attribute, otherwise a new node is created. - TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]LogMove, error) + TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]Move, error) // TreeApply applies replicated operation from another node. // If background is true, TreeApply will first check whether an operation exists. TreeApply(d CIDDescriptor, treeID string, m *Move, backgroundSync bool) error diff --git a/pkg/local_object_storage/pilorama/types.go b/pkg/local_object_storage/pilorama/types.go index 4a859a7e..88369db4 100644 --- a/pkg/local_object_storage/pilorama/types.go +++ b/pkg/local_object_storage/pilorama/types.go @@ -35,9 +35,6 @@ type Move struct { Child Node } -// LogMove represents log record for a single move operation. -type LogMove = Move - const ( // RootID represents the ID of a root node. RootID = 0 diff --git a/pkg/local_object_storage/shard/tree.go b/pkg/local_object_storage/shard/tree.go index 12600fcd..12498847 100644 --- a/pkg/local_object_storage/shard/tree.go +++ b/pkg/local_object_storage/shard/tree.go @@ -12,7 +12,7 @@ var _ pilorama.Forest = (*Shard)(nil) var ErrPiloramaDisabled = logicerr.New("pilorama is disabled") // TreeMove implements the pilorama.Forest interface. -func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) { +func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.Move, error) { if s.pilorama == nil { return nil, ErrPiloramaDisabled } @@ -27,7 +27,7 @@ func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Mo } // TreeAddByPath implements the pilorama.Forest interface. -func (s *Shard) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, meta []pilorama.KeyValue) ([]pilorama.LogMove, error) { +func (s *Shard) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, meta []pilorama.KeyValue) ([]pilorama.Move, error) { if s.pilorama == nil { return nil, ErrPiloramaDisabled } diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index b07f5f21..2b558089 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -17,7 +17,7 @@ import ( type movePair struct { cid cidSDK.ID treeID string - op *pilorama.LogMove + op *pilorama.Move } type replicationTask struct { @@ -141,7 +141,7 @@ func (s *Service) replicate(op movePair) error { return nil } -func (s *Service) pushToQueue(cid cidSDK.ID, treeID string, op *pilorama.LogMove) { +func (s *Service) pushToQueue(cid cidSDK.ID, treeID string, op *pilorama.Move) { select { case s.replicateCh <- movePair{ cid: cid,