MCPcopy
hub / github.com/etcd-io/bbolt / Begin

Method Begin

db.go:767–783  ·  view source on GitHub ↗

Begin starts a new transaction. Multiple read-only transactions can be used concurrently but only one write transaction can be used at a time. Starting multiple write transactions will cause the calls to block and be serialized until the current write transaction finishes. Transactions should not b

(writable bool)

Source from the content-addressed store, hash-verified

765// IMPORTANT: You must close read-only transactions after you are finished or
766// else the database will not reclaim old pages.
767func (db *DB) Begin(writable bool) (t *Tx, err error) {
768 if lg := db.Logger(); lg != discardLogger {
769 lg.Debugf("Starting a new transaction [writable: %t]", writable)
770 defer func() {
771 if err != nil {
772 lg.Errorf("Starting a new transaction [writable: %t] failed: %v", writable, err)
773 } else {
774 lg.Debugf("Starting a new transaction [writable: %t] successfully", writable)
775 }
776 }()
777 }
778
779 if writable {
780 return db.beginRWTx()
781 }
782 return db.beginTx()
783}
784
785func (db *DB) Logger() Logger {
786 if db == nil || db.logger == nil {

Callers 15

UpdateMethod · 0.95
ViewMethod · 0.95
TestDB_BeginRW_ClosedFunction · 0.95
TestCursor_Iterate_LeafFunction · 0.80
TestCursor_RestartFunction · 0.80
TestCursor_QuickCheckFunction · 0.80
TestMethodPageFunction · 0.80
TestBucket_Put_ClosedFunction · 0.80
TestBucket_Delete_ClosedFunction · 0.80

Calls 5

LoggerMethod · 0.95
beginRWTxMethod · 0.95
beginTxMethod · 0.95
DebugfMethod · 0.65
ErrorfMethod · 0.65

Tested by 15

TestDB_BeginRW_ClosedFunction · 0.76
TestCursor_Iterate_LeafFunction · 0.64
TestCursor_RestartFunction · 0.64
TestCursor_QuickCheckFunction · 0.64
TestMethodPageFunction · 0.64
TestBucket_Put_ClosedFunction · 0.64
TestBucket_Delete_ClosedFunction · 0.64