forked from TrueCloudLab/frostfs-node
[#288] pilorama: Use more descriptive names for memory tree
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
f856ad7480
commit
0045f1bcd4
2 changed files with 22 additions and 25 deletions
|
@ -14,21 +14,23 @@ type move struct {
|
|||
Old nodeInfo
|
||||
}
|
||||
|
||||
// state represents state being replicated.
|
||||
type state struct {
|
||||
// memoryTree represents memoryTree being replicated.
|
||||
type memoryTree struct {
|
||||
operations []move
|
||||
tree
|
||||
}
|
||||
|
||||
// newState constructs new empty tree.
|
||||
func newState() *state {
|
||||
return &state{
|
||||
tree: *newTree(),
|
||||
// newMemoryTree constructs new empty tree.
|
||||
func newMemoryTree() *memoryTree {
|
||||
return &memoryTree{
|
||||
tree: tree{
|
||||
infoMap: make(map[Node]nodeInfo),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// undo un-does op and changes s in-place.
|
||||
func (s *state) undo(op *move) {
|
||||
func (s *memoryTree) undo(op *move) {
|
||||
if op.HasOld {
|
||||
s.tree.infoMap[op.Child] = op.Old
|
||||
} else {
|
||||
|
@ -38,7 +40,7 @@ func (s *state) undo(op *move) {
|
|||
|
||||
// Apply puts op in log at a proper position, re-applies all subsequent operations
|
||||
// from log and changes s in-place.
|
||||
func (s *state) Apply(op *Move) error {
|
||||
func (s *memoryTree) Apply(op *Move) error {
|
||||
var index int
|
||||
for index = len(s.operations); index > 0; index-- {
|
||||
if s.operations[index-1].Time <= op.Time {
|
||||
|
@ -65,7 +67,7 @@ func (s *state) Apply(op *Move) error {
|
|||
}
|
||||
|
||||
// do performs a single move operation on a tree.
|
||||
func (s *state) do(op *Move) move {
|
||||
func (s *memoryTree) do(op *Move) move {
|
||||
lm := move{
|
||||
Move: Move{
|
||||
Parent: op.Parent,
|
||||
|
@ -96,14 +98,14 @@ func (s *state) do(op *Move) move {
|
|||
return lm
|
||||
}
|
||||
|
||||
func (s *state) timestamp(pos, size int) Timestamp {
|
||||
func (s *memoryTree) timestamp(pos, size int) Timestamp {
|
||||
if len(s.operations) == 0 {
|
||||
return nextTimestamp(0, uint64(pos), uint64(size))
|
||||
}
|
||||
return nextTimestamp(s.operations[len(s.operations)-1].Time, uint64(pos), uint64(size))
|
||||
}
|
||||
|
||||
func (s *state) findSpareID() Node {
|
||||
func (s *memoryTree) findSpareID() Node {
|
||||
id := uint64(1)
|
||||
for _, ok := s.infoMap[id]; ok; _, ok = s.infoMap[id] {
|
||||
id++
|
||||
|
@ -117,12 +119,6 @@ type tree struct {
|
|||
infoMap map[Node]nodeInfo
|
||||
}
|
||||
|
||||
func newTree() *tree {
|
||||
return &tree{
|
||||
infoMap: make(map[Node]nodeInfo),
|
||||
}
|
||||
}
|
||||
|
||||
func (t tree) getChildren(parent Node) []Node {
|
||||
var children []Node
|
||||
for c, info := range t.infoMap {
|
||||
|
@ -175,9 +171,10 @@ loop:
|
|||
return len(path), curNode
|
||||
}
|
||||
|
||||
// get returns list of nodes which have the specified path from root
|
||||
// getByPath returns list of nodes which have the specified path from root
|
||||
// descending by values of attr from meta.
|
||||
func (t tree) get(attr string, path []string, latest bool) []Node {
|
||||
// If latest is true, only the latest node is returned.
|
||||
func (t tree) getByPath(attr string, path []string, latest bool) []Node {
|
||||
if len(path) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue