@@ -16,10 +16,18 @@ type ReaderBatchWriter struct {
1616
1717var _ storage.ReaderBatchWriter = (* ReaderBatchWriter )(nil )
1818
19+ // GlobalReader returns a database-backed reader which reads the latest committed global database state ("read-committed isolation").
20+ // This reader will not read writes written to ReaderBatchWriter.Writer until the write batch is committed.
21+ // This reader may observe different values for the same key on subsequent reads.
1922func (b * ReaderBatchWriter ) GlobalReader () storage.Reader {
2023 return b .globalReader
2124}
2225
26+ // Writer returns a writer associated with a batch of writes. The batch is pending until it is committed.
27+ // When we `Write` into the batch, that write operation is added to the pending batch, but not committed.
28+ // The commit operation is atomic w.r.t. the batch; either all writes are applied to the database, or no writes are.
29+ // Note:
30+ // - The writer cannot be used concurrently for writing.
2331func (b * ReaderBatchWriter ) Writer () storage.Writer {
2432 return b
2533}
@@ -28,10 +36,15 @@ func (b *ReaderBatchWriter) PebbleWriterBatch() *pebble.Batch {
2836 return b .batch
2937}
3038
39+ // AddCallback adds a callback to execute after the batch has been flush
40+ // regardless the batch update is succeeded or failed.
41+ // The error parameter is the error returned by the batch update.
3142func (b * ReaderBatchWriter ) AddCallback (callback func (error )) {
3243 b .callbacks .AddCallback (callback )
3344}
3445
46+ // Commit flushes the batch to the database.
47+ // No errors expected during normal operation
3548func (b * ReaderBatchWriter ) Commit () error {
3649 err := b .batch .Commit (pebble .Sync )
3750
@@ -66,15 +79,27 @@ func NewReaderBatchWriter(db *pebble.DB) *ReaderBatchWriter {
6679
6780var _ storage.Writer = (* ReaderBatchWriter )(nil )
6881
82+ // Set sets the value for the given key. It overwrites any previous value
83+ // for that key; a DB is not a multi-map.
84+ //
85+ // It is safe to modify the contents of the arguments after Set returns.
86+ // No errors expected during normal operation
6987func (b * ReaderBatchWriter ) Set (key , value []byte ) error {
7088 return b .batch .Set (key , value , pebble .Sync )
7189}
7290
91+ // Delete deletes the value for the given key. Deletes are blind all will
92+ // succeed even if the given key does not exist.
93+ //
94+ // It is safe to modify the contents of the arguments after Delete returns.
95+ // No errors expected during normal operation
7396func (b * ReaderBatchWriter ) Delete (key []byte ) error {
7497 return b .batch .Delete (key , pebble .Sync )
7598}
7699
77- // DeleteByRange deletes all keys with a prefix in the range [startPrefix, endPrefix] (both inclusive).
100+ // DeleteByRange removes all keys with a prefix that falls within the
101+ // range [start, end], both inclusive.
102+ // No errors expected during normal operation
78103func (b * ReaderBatchWriter ) DeleteByRange (_ storage.Reader , startPrefix , endPrefix []byte ) error {
79104 // DeleteRange takes the prefix range with start (inclusive) and end (exclusive, note: not inclusive).
80105 // therefore, we need to increment the endPrefix to make it inclusive.
0 commit comments