cockroachdb / pebble

RocksDB/LevelDB inspired key-value database in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make Batch.release public?

mitar opened this issue · comments

Currently release() is not public, so one cannot implement something similar to DB.Set using current public API. In particular, it would be great to have something like Batch.Discard() to discard the batch and return it to the pool if some other (unrelated to Pebble) error happened which makes no point in continuing with the batch. Currently the only way is to leave it to GC to reclaim it, but it might be beneficial to return it to the pool?

Even in the case of successful Commit/Apply it might be useful to be able to return it back to the pool but it seems this is not possible if you construct batch using the public API.

Batch.Close releases the batch to the pool.

Oh, I missed that. Thanks But I am also confused by the docstring. It currently states:

Close closes the batch without committing it.

But my understanding is that you first call batch.Commit() and then batch.Close() to return it to the pool? I could not find anywhere that batch.Commit() would return it to the pool by itself. But reading docstring makes me think that I should call or batch.Commit() or batch.Close(). Also DB.Set calls release on success.

Also currently DB.Set returns batch to the pool only on success. That makes it trickier if one wants to use batch.Close in defer just after making the batch:

batch := db.NewIndexedBatch()
defer batch.Close()

The problem is that function might be returning early because of some other error, not related to the batch itself, and then it is useful to close it and return it.

So I think:

  • Docstring should be made clear that one should call batch.Close() always.
  • Maybe batch.Close() should be made so that it is a noop if batch failed? It is easier to track this inside batch itself than outside.