-
Notifications
You must be signed in to change notification settings - Fork 348
/
batch_write_closer.go
32 lines (29 loc) · 1.38 KB
/
batch_write_closer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package committed
//go:generate go run github.com/golang/mock/mockgen@v1.6.0 -source=batch_write_closer.go -destination=mock/batch_write_closer.go -package=mock
// BatchWriterCloser collects Range writers and handles the asynchronous
// flushing and closing of the writers.
// Example usage:
//
// func batch(manager RangeManager, bwc BatchWriterCloser) {
// w1, _ := manager.GetWriter()
// _ = 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.WriteRecord(graveler.ValueRecord{Key: "goo1", Value: &graveler.Value{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 MetaRangeWriter 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(ResultCloser) error
// Wait returns when all Writers finished.
// Any failure to close a single MetaRangeWriter will return with a nil results slice and an error.
Wait() ([]WriteResult, error)
}