Skip to content

Commit

Permalink
added tree interface (#1043)
Browse files Browse the repository at this point in the history
* added tree interface

* Update forest/tree/tree.go

Co-authored-by: itaiad200 <[email protected]>

* correct after review

* correct after review - push again

* fix review comments

* had to make some identifiers global because of linter errors. will change once integrated with rest of tree package

* had to make some identifiers global because of linter errors. will change once integrated with rest of tree package

* simplied SaveTree interface by splitting it to two interfaces

Co-authored-by: itaiad200 <[email protected]>
  • Loading branch information
tzahij and itaiad200 authored Dec 13, 2020
1 parent 11a13f8 commit 8aada34
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions forest/tree/tree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package tree

import (
// cache "github.com/treeverse/lakefs/forest/cache_map"
"github.com/treeverse/lakefs/graveler"
"github.com/treeverse/lakefs/graveler/committed/sstable"
)

type TreePart struct {
PartName sstable.ID `json:"part_name"`
MaxKey graveler.Key `json:"max_path"`
}
type TreeSlice struct {
TreeSlice []TreePart
}
type DummyMap map[string]string // place holder for cache_map package that will be merged soon

type TreesRepo struct {
TreesMap DummyMap
PartManger sstable.Manager
}

// InitTreeRepository creates the tree cache, and stores part Manager for operations of parts (currently implemented as sstables).
// should be called at process init.
// decisions on who calls it and how to get a treesRepository will be taken later
type InitTreesRepository func(manager sstable.Manager) TreeRepo

type TreeRepo interface {
// NewTreeWriter returns a writer that uses the part manager to create a new tree
NewTreeWriter(splitFactor int, // average number of keys that we want to stored in a part
// for more detail, look at "IsSplitKey"
closeAsync sstable.BatchWriterCloser, // component used to close part asynchronously, and wait for all part
// completions when tree writing completes
) TreeWriter
// NewScannerFromTreeID accepts a tree ID, and returns an iterator over the tree
NewIteratorFromTreeID(treeID graveler.TreeID, start graveler.Key) (graveler.ValueIterator, error)
// NewIteratorFromTreeParts accept a tree in memory, returns iterator over the tree
NewIteratorFromTreeSlice(treeSlice TreeSlice, start graveler.Key) (graveler.ValueIterator, error)
// GetPartManager give components of tree package to the configured part manager.
// will probably change later
// GetPartManger() sstable.Manager
}

type TreeWriter interface {
WriteEntry(record graveler.ValueRecord) error
// FlushIterToTree writes the content of an iterator to the tree.
FlushIterToTree(iter graveler.ValueIterator) error
// SaveTree stores the tree to tierFS. During tree writing, parts are closed asynchronously and copied by tierFS
// while writing continues. SaveTree waits until closing and copying all parts
SaveTree() (graveler.TreeID, error)
SaveTreeWithReusedParts(reuseTree TreeSlice, // A tree may be saved with additional parts that are "reused" from a base tree.
// these are parts that exist in a source tree, and are merged into the destination tree.
// an example of using it is in the apply process, which creates a new tree from a base tree and an input iterator.
// those parts of the base tree that were not modified by it input iterator will be merged into the resulting tree
// by passing them in the reuseTree parameter.
) (graveler.TreeID, error)
}

0 comments on commit 8aada34

Please sign in to comment.