| 84 | } |
| 85 | |
| 86 | func (batch *Batch) commit(w *WriteOptions) error { |
| 87 | if w == nil { |
| 88 | w = &WriteOptions{ |
| 89 | Sync: false, |
| 90 | DisableWal: false, |
| 91 | } |
| 92 | } |
| 93 | defer batch.unLock() |
| 94 | if batch.db.Closed { |
| 95 | return _const.ErrorDBClosed |
| 96 | } |
| 97 | |
| 98 | if batch.options.ReadOnly || len(batch.pendingWrites) == 0 { |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | batch.m.Lock() |
| 103 | defer batch.m.Unlock() |
| 104 | if batch.commited { |
| 105 | return _const.ErrorBatchCommited |
| 106 | } |
| 107 | |
| 108 | if err := batch.db.waitMemTableSpace(); err != nil { |
| 109 | return err |
| 110 | } |
| 111 | |
| 112 | batchId := batch.batchId.Generate() |
| 113 | if err := batch.db.activeMem.putBatch(batch.pendingWrites, batchId, w); err != nil { |
| 114 | return err |
| 115 | } |
| 116 | batch.commited = true |
| 117 | return nil |
| 118 | } |
| 119 | |
| 120 | func (batch *Batch) Get(key []byte) ([]byte, error) { |
| 121 | if len(key) == 0 { |