|
|
@ -240,8 +240,8 @@ func (i *isolation) closeAppend(appendID uint64) { |
|
|
|
// The transactionID ring buffer.
|
|
|
|
// The transactionID ring buffer.
|
|
|
|
type txRing struct { |
|
|
|
type txRing struct { |
|
|
|
txIDs []uint64 |
|
|
|
txIDs []uint64 |
|
|
|
txIDFirst int // Position of the first id in the ring.
|
|
|
|
txIDFirst uint32 // Position of the first id in the ring.
|
|
|
|
txIDCount int // How many ids in the ring.
|
|
|
|
txIDCount uint32 // How many ids in the ring.
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newTxRing(capacity int) *txRing { |
|
|
|
func newTxRing(capacity int) *txRing { |
|
|
@ -251,7 +251,7 @@ func newTxRing(capacity int) *txRing { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (txr *txRing) add(appendID uint64) { |
|
|
|
func (txr *txRing) add(appendID uint64) { |
|
|
|
if txr.txIDCount == len(txr.txIDs) { |
|
|
|
if int(txr.txIDCount) == len(txr.txIDs) { |
|
|
|
// Ring buffer is full, expand by doubling.
|
|
|
|
// Ring buffer is full, expand by doubling.
|
|
|
|
newRing := make([]uint64, txr.txIDCount*2) |
|
|
|
newRing := make([]uint64, txr.txIDCount*2) |
|
|
|
idx := copy(newRing, txr.txIDs[txr.txIDFirst:]) |
|
|
|
idx := copy(newRing, txr.txIDs[txr.txIDFirst:]) |
|
|
@ -260,12 +260,12 @@ func (txr *txRing) add(appendID uint64) { |
|
|
|
txr.txIDFirst = 0 |
|
|
|
txr.txIDFirst = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
txr.txIDs[(txr.txIDFirst+txr.txIDCount)%len(txr.txIDs)] = appendID |
|
|
|
txr.txIDs[int(txr.txIDFirst+txr.txIDCount)%len(txr.txIDs)] = appendID |
|
|
|
txr.txIDCount++ |
|
|
|
txr.txIDCount++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (txr *txRing) cleanupAppendIDsBelow(bound uint64) { |
|
|
|
func (txr *txRing) cleanupAppendIDsBelow(bound uint64) { |
|
|
|
pos := txr.txIDFirst |
|
|
|
pos := int(txr.txIDFirst) |
|
|
|
|
|
|
|
|
|
|
|
for txr.txIDCount > 0 { |
|
|
|
for txr.txIDCount > 0 { |
|
|
|
if txr.txIDs[pos] < bound { |
|
|
|
if txr.txIDs[pos] < bound { |
|
|
@ -281,7 +281,7 @@ func (txr *txRing) cleanupAppendIDsBelow(bound uint64) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
txr.txIDFirst %= len(txr.txIDs) |
|
|
|
txr.txIDFirst %= uint32(len(txr.txIDs)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (txr *txRing) iterator() *txRingIterator { |
|
|
|
func (txr *txRing) iterator() *txRingIterator { |
|
|
@ -296,7 +296,7 @@ func (txr *txRing) iterator() *txRingIterator { |
|
|
|
type txRingIterator struct { |
|
|
|
type txRingIterator struct { |
|
|
|
ids []uint64 |
|
|
|
ids []uint64 |
|
|
|
|
|
|
|
|
|
|
|
pos int |
|
|
|
pos uint32 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (it *txRingIterator) At() uint64 { |
|
|
|
func (it *txRingIterator) At() uint64 { |
|
|
@ -305,7 +305,7 @@ func (it *txRingIterator) At() uint64 { |
|
|
|
|
|
|
|
|
|
|
|
func (it *txRingIterator) Next() { |
|
|
|
func (it *txRingIterator) Next() { |
|
|
|
it.pos++ |
|
|
|
it.pos++ |
|
|
|
if it.pos == len(it.ids) { |
|
|
|
if int(it.pos) == len(it.ids) { |
|
|
|
it.pos = 0 |
|
|
|
it.pos = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|