diff --git a/forest/sstable/sstable.go b/forest/sstable/sstable.go index 27ee44093f5..7a5235ddfc9 100644 --- a/forest/sstable/sstable.go +++ b/forest/sstable/sstable.go @@ -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) +}