(bm sorted.BatchMutation)
| 142 | } |
| 143 | |
| 144 | func (kv *KeyValue) CommitBatch(bm sorted.BatchMutation) error { |
| 145 | kv.mu.RLock() |
| 146 | defer kv.mu.RUnlock() |
| 147 | b, ok := bm.(*batch) |
| 148 | if !ok { |
| 149 | return fmt.Errorf("unexpected BatchMutation type %T", bm) |
| 150 | } |
| 151 | var ( |
| 152 | // A batch mutation for applying this mutation to the buffer. |
| 153 | bmbuf = kv.buf.BeginBatch() |
| 154 | // A lazily created batch mutation for deleting from the backing |
| 155 | // storage; this should be rare. (See Delete above.) |
| 156 | bmback sorted.BatchMutation |
| 157 | ) |
| 158 | for _, m := range b.mods { |
| 159 | if m.isDelete { |
| 160 | bmbuf.Delete(m.key) |
| 161 | if bmback == nil { |
| 162 | bmback = kv.back.BeginBatch() |
| 163 | } |
| 164 | bmback.Delete(m.key) |
| 165 | continue |
| 166 | } else { |
| 167 | if err := sorted.CheckSizes(m.key, m.value); err != nil { |
| 168 | log.Printf("Skipping storing (%q:%q): %v", m.key, m.value, err) |
| 169 | continue |
| 170 | } |
| 171 | } |
| 172 | bmbuf.Set(m.key, m.value) |
| 173 | } |
| 174 | if err := kv.buf.CommitBatch(bmbuf); err != nil { |
| 175 | return err |
| 176 | } |
| 177 | if bmback != nil { |
| 178 | return kv.back.CommitBatch(bmback) |
| 179 | } |
| 180 | return nil |
| 181 | } |
| 182 | |
| 183 | func (kv *KeyValue) Close() error { |
| 184 | if err := kv.Flush(); err != nil { |
nothing calls this directly
no test coverage detected