Skip to content

Commit

Permalink
Add interface for async handling of sstable writer flushing and closi…
Browse files Browse the repository at this point in the history
…ng (#978)
  • Loading branch information
itaiad200 authored Dec 1, 2020
1 parent 9623170 commit 4f89db9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions forest/sstable/sstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,31 @@ type Writer interface {
// Close flushes all entries to the disk and returns the WriteResult.
Close() (*WriteResult, error)
}

// BatchWriterCloser collects sstable writers and handles the asynchronous
// flushing and closing of the writers.
// Example usage:
// func batch(manager Manager, bwc BatchWriterCloser) {
// w1, _ := manager.GetWriter()
// _ = w1.WriteEntry(rocks.EntryRecord{Path: "foo1", Entry: &rocks.Entry{Address: "bar1"}})
// _ = w1.WriteEntry(rocks.EntryRecord{Path: "foo2", Entry: &rocks.Entry{Address: "bar2"}})
// _ = bwc.CloseWriterAsync(w1)

// w2, _ := manager.GetWriter()
// _ = w2.WriteEntry(rocks.EntryRecord{Path: "goo1", Entry: &rocks.Entry{Address: "baz1"}})
// _ = bwc.CloseWriterAsync(w2)

// // blocks until all writers finished or any writer failed
// res, err := bwc.Wait()
// // handle err, results, etc..
// }
type BatchWriterCloser interface {
// CloseWriterAsync adds Writer instance for the BatchWriterCloser to handle.
// Any writes executed to the writer after this call are not guaranteed to succeed.
// If Wait() has already been called, returns an error.
CloseWriterAsync(Writer) error

// Wait returns when all Writers finished.
// Any failure to close a single Writer will return with a nil results slice and an error.
Wait() ([]WriteResult, error)
}

0 comments on commit 4f89db9

Please sign in to comment.