Commit 5e218ac9 authored by Carsten Orthbandt's avatar Carsten Orthbandt
Browse files

TXID alloc fix

parent e9e076aa
Showing with 15 additions and 4 deletions
+15 -4
......@@ -77,10 +77,9 @@ func (u *UUID) Set(s string) bool {
if t.IsValid() {
*u = t
return true
} else {
u.Clear()
return false
}
u.Clear()
return false
}
// Generate overwrites a UUID with a new RFC4122 version 4 ID
......
......@@ -7,6 +7,7 @@ import (
"reflect"
"sort"
"sync"
"time"
"git.pixeltamer.net/gopub/logfunk"
"github.com/jackc/pgconn"
......@@ -211,7 +212,10 @@ func (env *Env) newTxID() int {
if env.nxttxid > 99 {
env.nxttxid = 0
}
rep := 0
for {
env.nxttxlock.Unlock()
env.nxttxlock.Lock()
_, ok := env.nxttxmap[env.nxttxid]
if !ok {
id := env.nxttxid
......@@ -219,6 +223,14 @@ func (env *Env) newTxID() int {
env.nxttxlock.Unlock()
return id
}
env.nxttxid++
if env.nxttxid > 99 {
env.nxttxid = 0
rep++
if rep > 2 {
time.Sleep(time.Millisecond)
}
}
}
}
......
......@@ -112,6 +112,7 @@ func (tx *Tx) closePending() {
tx.pendingRows = nil
}
// ResetErr sets the transaction last-error to nil
func (tx *Tx) ResetErr() {
tx.Err = nil
tx.Collision = false
......@@ -145,7 +146,6 @@ func (tx *Tx) Commit(options ...OpOpt) error {
// Rollback cancels the transaction
func (tx *Tx) Rollback(options ...OpOpt) error {
defer tx.freeTx()
tx.TxID += 1000
ov, err := tx.ovInit(otRollback, options...)
if tx.Tx == nil {
return ErrNoTx
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment