Source File
managed_db.go
Belonging Package
github.com/dgraph-io/badger/v4
/** SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.* SPDX-License-Identifier: Apache-2.0*/package badger// OpenManaged returns a new DB, which allows more control over setting// transaction timestamps, aka managed mode.//// This is only useful for databases built on top of Badger (like Dgraph), and// can be ignored by most users.func ( Options) (*DB, error) {.managedTxns = truereturn Open()}// NewTransactionAt follows the same logic as DB.NewTransaction(), but uses the// provided read timestamp.//// This is only useful for databases built on top of Badger (like Dgraph), and// can be ignored by most users.func ( *DB) ( uint64, bool) *Txn {if !.opt.managedTxns {panic("Cannot use NewTransactionAt with managedDB=false. Use NewTransaction instead.")}:= .newTransaction(, true).readTs =return}// NewWriteBatchAt is similar to NewWriteBatch but it allows user to set the commit timestamp.// NewWriteBatchAt is supposed to be used only in the managed mode.func ( *DB) ( uint64) *WriteBatch {if !.opt.managedTxns {panic("cannot use NewWriteBatchAt with managedDB=false. Use NewWriteBatch instead")}:= .newWriteBatch(true).commitTs =.txn.commitTs =return}func ( *DB) () *WriteBatch {if !.opt.managedTxns {panic("cannot use NewManagedWriteBatch with managedDB=false. Use NewWriteBatch instead")}:= .newWriteBatch(true)return}// CommitAt commits the transaction, following the same logic as Commit(), but// at the given commit timestamp. This will panic if not used with managed transactions.//// This is only useful for databases built on top of Badger (like Dgraph), and// can be ignored by most users.func ( *Txn) ( uint64, func(error)) error {if !.db.opt.managedTxns {panic("Cannot use CommitAt with managedDB=false. Use Commit instead.")}.commitTs =if == nil {return .Commit()}.CommitWith()return nil}// SetDiscardTs sets a timestamp at or below which, any invalid or deleted// versions can be discarded from the LSM tree, and thence from the value log to// reclaim disk space. Can only be used with managed transactions.func ( *DB) ( uint64) {if !.opt.managedTxns {panic("Cannot use SetDiscardTs with managedDB=false.")}.orc.setDiscardTs()}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |