@@ -16,12 +16,23 @@ import (
1616// An error will be returned if you try to use Put or Delete method.
1717//
1818// If readonly is false, you can use Put and Delete method to write data to the batch.
19- // The data will be written to the database when you call Commit method.
19+ // The data will be written to the database permanently after you call Commit method.
20+ //
21+ // NB. There can only one write batch and multi read-only batches at the same time.
22+ // And the db method is not allowed to use before the batch commit/rollback.
23+ // So a typical usage of Batch is like:
24+ //
25+ // batch := db.NewBatch(rosedb.DefaultBatchOptions)
26+ // batch.Put/batch.Get (and other methods)
27+ // /* 1. a new write batch is not allowed */
28+ // /* 2. invoke DB method is not allowed, like db.Put */
29+ // batch.Commit() or batch.Rollback()
2030//
2131// Batch is not a transaction, it does not guarantee isolation.
2232// But it can guarantee atomicity, consistency and durability(if the Sync options is true).
2333//
24- // You must call Commit method to commit the batch, otherwise the DB will be locked.
34+ // You must call Commit or Rollback method after using the batch,
35+ // otherwise the DB will be locked in an unexpected way.
2536type Batch struct {
2637 db * DB
2738 pendingWrites []* LogRecord // save the data to be written
@@ -68,12 +79,11 @@ func newRecord() interface{} {
6879 return & LogRecord {}
6980}
7081
71- func (b * Batch ) init (rdonly , sync bool , db * DB ) * Batch {
82+ func (b * Batch ) init (rdonly , sync bool , db * DB ) {
7283 b .options .ReadOnly = rdonly
7384 b .options .Sync = sync
7485 b .db = db
7586 b .lock ()
76- return b
7787}
7888
7989func (b * Batch ) reset () {
0 commit comments