fix/355-increase-tree-service-client-cache-size #359

Closed
ale64bit wants to merge 156 commits from ale64bit/frostfs-node:fix/355-increase-tree-service-client-cache-size into support/v0.36
2 changed files with 22 additions and 25 deletions
Showing only changes of commit 0045f1bcd4 - Show all commits

View file

@ -12,7 +12,7 @@ import (
// memoryForest represents multiple replicating trees sharing a single storage.
type memoryForest struct {
// treeMap maps tree identifier (container ID + name) to the replicated log.
treeMap map[string]*state
treeMap map[string]*memoryTree
}
var _ Forest = (*memoryForest)(nil)
@ -21,7 +21,7 @@ var _ Forest = (*memoryForest)(nil)
// TODO: this function will eventually be removed and is here for debugging.
func NewMemoryForest() ForestStorage {
return &memoryForest{
treeMap: make(map[string]*state),
treeMap: make(map[string]*memoryTree),
}
}
@ -34,7 +34,7 @@ func (f *memoryForest) TreeMove(_ context.Context, d CIDDescriptor, treeID strin
fullID := d.CID.String() + "/" + treeID
s, ok := f.treeMap[fullID]
if !ok {
s = newState()
s = newMemoryTree()
f.treeMap[fullID] = s
}
@ -60,7 +60,7 @@ func (f *memoryForest) TreeAddByPath(_ context.Context, d CIDDescriptor, treeID
fullID := d.CID.String() + "/" + treeID
s, ok := f.treeMap[fullID]
if !ok {
s = newState()
s = newMemoryTree()
f.treeMap[fullID] = s
}
@ -98,7 +98,7 @@ func (f *memoryForest) TreeApply(_ context.Context, cnr cid.ID, treeID string, o
fullID := cnr.String() + "/" + treeID
s, ok := f.treeMap[fullID]
if !ok {
s = newState()
s = newMemoryTree()
f.treeMap[fullID] = s
}
@ -131,7 +131,7 @@ func (f *memoryForest) TreeGetByPath(_ context.Context, cid cid.ID, treeID strin
return nil, ErrTreeNotFound
}
return s.get(attr, path, latest), nil
return s.getByPath(attr, path, latest), nil
}
// TreeGetMeta implements the Forest interface.

View file

@ -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
}