aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-01-25 14:00:01 -0300
committerEuAndreh <eu@euandre.org>2025-01-25 14:00:01 -0300
commit007c65e2f6ec5de6be7df127fcfaaf8e58086ba8 (patch)
tree54ce78d6b8f3e5e273cd33af608a38f05be39c0a /src
parenttests/dedo.go: Swallow error log from g.Assert() (diff)
downloaddedo-007c65e2f6ec5de6be7df127fcfaaf8e58086ba8.tar.gz
dedo-007c65e2f6ec5de6be7df127fcfaaf8e58086ba8.tar.xz
src/dedo.go: Remove public API for manually managing transactions
Diffstat (limited to 'src')
-rw-r--r--src/dedo.go46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/dedo.go b/src/dedo.go
index 2dde5eb..a96f8ef 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -1862,7 +1862,7 @@ func (db *DB) close() error {
return nil
}
-/// DB.Begin() starts a new transaction. Multiple read-only transactions can be
+/// DB.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.
@@ -1878,7 +1878,7 @@ func (db *DB) close() error {
///
/// IMPORTANT: You must close read-only transactions after you are finished or
/// else the database will not reclaim old pages.
-func (db *DB) Begin(writable bool) (*Tx, error) {
+func (db *DB) begin(writable bool) (*Tx, error) {
if writable {
return db.beginRWTx()
} else {
@@ -1984,7 +1984,7 @@ func (db *DB) removeTx(tx *Tx) {
/// Attempting to manually commit or rollback within the function will cause a
/// panic.
func (db *DB) Update(fn func(*Tx) error) error {
- t, err := db.Begin(true)
+ t, err := db.begin(true)
if err != nil {
return err
}
@@ -1992,7 +1992,7 @@ func (db *DB) Update(fn func(*Tx) error) error {
// Make sure the transaction rolls back in the event of a panic.
defer func() {
if t.db != nil {
- t.rollback()
+ t.doRollback()
}
}()
@@ -2005,11 +2005,11 @@ func (db *DB) Update(fn func(*Tx) error) error {
err = fn(t)
t.managed = false
if err != nil {
- _ = t.Rollback()
+ _ = t.rollback()
return err
}
- return t.Commit()
+ return t.commit()
}
/// DB.View() executes a function within the context of a managed read-only
@@ -2018,7 +2018,7 @@ func (db *DB) Update(fn func(*Tx) error) error {
///
/// Attempting to manually rollback within the function will cause a panic.
func (db *DB) View(fn func(*Tx) error) error {
- t, err := db.Begin(false)
+ t, err := db.begin(false)
if err != nil {
return err
}
@@ -2026,7 +2026,7 @@ func (db *DB) View(fn func(*Tx) error) error {
// Make sure the transaction rolls back in the event of a panic.
defer func() {
if t.db != nil {
- t.rollback()
+ t.doRollback()
}
}()
@@ -2038,11 +2038,11 @@ func (db *DB) View(fn func(*Tx) error) error {
err = fn(t)
t.managed = false
if err != nil {
- _ = t.Rollback()
+ _ = t.rollback()
return err
}
- err = t.Rollback()
+ err = t.rollback()
if err != nil {
return err
}
@@ -3443,10 +3443,10 @@ func (tx *Tx) OnCommit(fn func()) {
tx.commitHandlers = append(tx.commitHandlers, fn)
}
-/// Tx.Commit() writes all changes to disk and updates the meta page. Returns
-/// an error if a disk write error occurs, or if Tx.Commiti() is called on a
+/// Tx.commit() writes all changes to disk and updates the meta page. Returns
+/// an error if a disk write error occurs, or if Tx.commiti() is called on a
/// read-only transaction.
-func (tx *Tx) Commit() error {
+func (tx *Tx) commit() error {
g.Assert(!tx.managed, "managed tx commit not allowed")
if tx.db == nil {
return ErrTxClosed
@@ -3462,7 +3462,7 @@ func (tx *Tx) Commit() error {
// spill data onto dirty pages.
err := tx.root.spill()
if err != nil {
- tx.rollback()
+ tx.doRollback()
return err
}
@@ -3477,13 +3477,13 @@ func (tx *Tx) Commit() error {
tx.db.freelist.free(tx.meta.txid, tx.db.page(tx.meta.freelist))
p, err := tx.allocate((tx.db.freelist.size() / tx.db.pageSize) + 1)
if err != nil {
- tx.rollback()
+ tx.doRollback()
return err
}
err = tx.db.freelist.write(p)
if err != nil {
- tx.rollback()
+ tx.doRollback()
return err
}
tx.meta.freelist = p.id
@@ -3493,7 +3493,7 @@ func (tx *Tx) Commit() error {
if tx.meta.pgid > opgid {
err := tx.db.grow(int(tx.meta.pgid + 1) * tx.db.pageSize)
if err != nil {
- tx.rollback()
+ tx.doRollback()
return err
}
}
@@ -3501,7 +3501,7 @@ func (tx *Tx) Commit() error {
// Write dirty pages to disk.
err = tx.write()
if err != nil {
- tx.rollback()
+ tx.doRollback()
return err
}
@@ -3525,7 +3525,7 @@ func (tx *Tx) Commit() error {
// Write meta to disk.
err = tx.writeMeta()
if err != nil {
- tx.rollback()
+ tx.doRollback()
return err
}
@@ -3540,18 +3540,18 @@ func (tx *Tx) Commit() error {
return nil
}
-/// Tx.Rollback() closes the transaction and ignores all previous updates.
+/// Tx.rollback() closes the transaction and ignores all previous updates.
/// Read-only transactions must be rolled back and not committed.
-func (tx *Tx) Rollback() error {
+func (tx *Tx) rollback() error {
g.Assert(!tx.managed, "managed tx rollback not allowed")
if tx.db == nil {
return ErrTxClosed
}
- tx.rollback()
+ tx.doRollback()
return nil
}
-func (tx *Tx) rollback() {
+func (tx *Tx) doRollback() {
if tx.db == nil {
return
}