Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sstable interface to match new graveler package #1003

Merged
merged 1 commit into from
Dec 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions forest/sstable/sstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ import (
"github.com/treeverse/lakefs/graveler"
)

// SSTableID is an identifier for an SSTable
type SSTableID string
// ID is an identifier for an SSTable
type ID string

type Manager interface {
// GetEntry returns the entry matching the path in the SSTable referenced by the id.
// GetValue returns the value matching the key in the SSTable referenced by the id.
// If path not found, (nil, ErrPathNotFound) is returned.
GetEntry(path graveler.Key, tid SSTableID) (*graveler.Value, error)
GetValue(key graveler.Key, tid ID) (*graveler.Value, error)

// NewSSTableIterator takes a given SSTable and returns an ValueIterator seeked to >= "from" path
NewSSTableIterator(tid SSTableID, from graveler.Key) (graveler.ValueIterator, error)
// NewSSTableIterator takes a given SSTable and returns an ValueIterator seeked to >= "from" value
NewSSTableIterator(tid ID, from graveler.Key) (graveler.ValueIterator, error)

// GetWriter returns a new SSTable writer instance
GetWriter() (Writer, error)
}

// WriteResult is the result of a completed write of an SSTable
type WriteResult struct {
// SSTableID is the identifier for the written SSTable.
// Calculated by an hash function to all paths and entries.
SSTableID SSTableID
// ID is the identifier for the written SSTable.
// Calculated by an hash function to all keys and values' identity.
SSTableID ID

// First is the Key of the first entry in the SSTable.
// First is the first key in the SSTable.
First graveler.Key

// Last is the Key of the last entry in the SSTable.
// Last is the last key in the SSTable.
Last graveler.Key

// Count is the number of entries in the SSTable.
// Count is the number of records in the SSTable.
Count int
}

// Writer is an abstraction for writing SSTables.
// Written entries must be sorted by path.
// Written records must be sorted by key.
type Writer interface {
// WriteEntry appends the given entry to the SSTable
WriteEntry(entry graveler.ValueRecord) error
// WriteRecord appends the given record to the SSTable
WriteRecord(record graveler.ValueRecord) error

// Close flushes all entries to the disk and returns the WriteResult.
// Close flushes all records to the disk and returns the WriteResult.
Close() (*WriteResult, error)
}

Expand All @@ -50,12 +50,12 @@ type Writer interface {
// Example usage:
// func batch(manager Manager, bwc BatchWriterCloser) {
// w1, _ := manager.GetWriter()
// _ = w1.WriteEntry(rocks.ValueRecord{Key: "foo1", Value: &rocks.Value{Address: "bar1"}})
// _ = w1.WriteEntry(rocks.ValueRecord{Key: "foo2", Value: &rocks.Value{Address: "bar2"}})
// _ = w1.WriteRecord(graveler.ValueRecord{Key: "foo1", Value: &graveler.Value{Address: "bar1"}})
// _ = w1.WriteRecord(graveler.ValueRecord{Key: "foo2", Value: &graveler.Value{Address: "bar2"}})
// _ = bwc.CloseWriterAsync(w1)

// w2, _ := manager.GetWriter()
// _ = w2.WriteEntry(rocks.ValueRecord{Key: "goo1", Value: &rocks.Value{Address: "baz1"}})
// _ = w2.WriteRecord(graveler.ValueRecord{Key: "goo1", Value: &graveler.Value{Address: "baz1"}})
// _ = bwc.CloseWriterAsync(w2)

// // blocks until all writers finished or any writer failed
Expand Down