Documentation ¶
Index ¶
- Constants
- Variables
- func InstanceDir(dataDir, instanceId string) string
- func Open(instancePath string) (*badger.DB, error)
- type BatchedWriter
- type DirectoryLockGuard
- type WriteBatch
- func (wb *WriteBatch) Cancel()
- func (wb *WriteBatch) Delete(k []byte, cb WriteBatchCommitCB) error
- func (wb *WriteBatch) Error() error
- func (wb *WriteBatch) Flush() error
- func (wb *WriteBatch) Set(k, v []byte, cb WriteBatchCommitCB) error
- func (wb *WriteBatch) SetEntry(e *badger.Entry, cb WriteBatchCommitCB) error
- func (wb *WriteBatch) SetMaxPendingTxns(max int)
- type WriteBatchCommitCB
Constants ¶
const (
LockFile = "LOCK"
)
Variables ¶
var InitCommitCBsCapacity = 2000
Functions ¶
func InstanceDir ¶
Types ¶
type BatchedWriter ¶
type BatchedWriter struct {
// contains filtered or unexported fields
}
func NewBatchedWriter ¶
func NewBatchedWriter(db *badger.DB, d time.Duration) *BatchedWriter
func (*BatchedWriter) Close ¶
func (bw *BatchedWriter) Close()
func (*BatchedWriter) Set ¶
func (bw *BatchedWriter) Set(k, v []byte, cb WriteBatchCommitCB) error
func (*BatchedWriter) SetEntry ¶
func (bw *BatchedWriter) SetEntry(e *badger.Entry, cb WriteBatchCommitCB) error
func (*BatchedWriter) WriteKVList ¶
func (bw *BatchedWriter) WriteKVList(kvList *pb.KVList, cb WriteBatchCommitCB) error
type DirectoryLockGuard ¶
type DirectoryLockGuard struct {
// contains filtered or unexported fields
}
DirectoryLockGuard holds a lock on a directory and a pid file inside. The pid file isn't part of the locking mechanism, it's just advisory.
func AcquireDirectoryLock ¶
func AcquireDirectoryLock(dirPath string, pidFileName string, readOnly bool) ( *DirectoryLockGuard, error)
AcquireDirectoryLock gets a lock on the directory (using flock). If this is not read-only, it will also write our pid to dirPath/pidFileName for convenience.
func (*DirectoryLockGuard) Release ¶
func (guard *DirectoryLockGuard) Release() error
Release deletes the pid file and releases our lock on the directory.
type WriteBatch ¶
WriteBatch holds the necessary info to perform batched writes.
func NewWriteBatch ¶
func NewWriteBatch(db *badger.DB) *WriteBatch
NewWriteBatch creates a new WriteBatch. This provides a way to conveniently do a lot of writes, batching them up as tightly as possible in a single transaction and using callbacks to avoid waiting for them to commit, thus achieving good performance. This API hides away the logic of creating and committing transactions. Due to the nature of SSI guaratees provided by Badger, blind writes can never encounter transaction conflicts (ErrConflict).
func (*WriteBatch) Cancel ¶
func (wb *WriteBatch) Cancel()
Cancel function must be called if there's a chance that Flush might not get called. If neither Flush or Cancel is called, the transaction oracle would never get a chance to clear out the row commit timestamp map, thus causing an unbounded memory consumption. Typically, you can call Cancel as a defer statement right after NewWriteBatch is called.
Note that any committed writes would still go through despite calling Cancel.
func (*WriteBatch) Delete ¶
func (wb *WriteBatch) Delete(k []byte, cb WriteBatchCommitCB) error
Delete is equivalent of Txn.Delete.
func (*WriteBatch) Error ¶
func (wb *WriteBatch) Error() error
Error returns any errors encountered so far. No commits would be run once an error is detected.
func (*WriteBatch) Flush ¶
func (wb *WriteBatch) Flush() error
Flush must be called at the end to ensure that any pending writes get committed to Badger. Flush returns any error stored by WriteBatch.
func (*WriteBatch) Set ¶
func (wb *WriteBatch) Set(k, v []byte, cb WriteBatchCommitCB) error
Set is equivalent of Txn.Set().
func (*WriteBatch) SetEntry ¶
func (wb *WriteBatch) SetEntry(e *badger.Entry, cb WriteBatchCommitCB) error
SetEntry is the equivalent of Txn.SetEntry.
func (*WriteBatch) SetMaxPendingTxns ¶
func (wb *WriteBatch) SetMaxPendingTxns(max int)
SetMaxPendingTxns sets a limit on maximum number of pending transactions while writing batches. This function should be called before using WriteBatch. Default value of MaxPendingTxns is 16 to minimise memory usage.
type WriteBatchCommitCB ¶
type WriteBatchCommitCB func(error)