mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 10:06:14 +00:00
feat(meta): Enhance the allocation and validation of txId to avoid potential duplicates.
Signed-off-by: Victor1319 <834863182@qq.com>
This commit is contained in:
parent
5076a34844
commit
152dca0fa2
@ -666,6 +666,11 @@ func (tm *TransactionManager) registerTransaction(txInfo *proto.TransactionInfo)
|
||||
dentry.SetTimeout(txInfo.Timeout)
|
||||
dentry.SetTxId(txInfo.TxID)
|
||||
}
|
||||
|
||||
if info := tm.getTransaction(txInfo.TxID); info != nil {
|
||||
log.LogWarnf("tx is already exist, txId %s, info %v", txInfo.TxID, info.String())
|
||||
return fmt.Errorf("tx is already exist, txId %s", txInfo.TxID)
|
||||
}
|
||||
}
|
||||
|
||||
if info := tm.getTransaction(txInfo.TxID); info != nil {
|
||||
|
||||
@ -32,21 +32,30 @@ func newTxIDAllocator() (alloc *TxIDAllocator) {
|
||||
}
|
||||
|
||||
func (alloc *TxIDAllocator) Reset() {
|
||||
alloc.txIDLock.Lock()
|
||||
defer alloc.txIDLock.Unlock()
|
||||
|
||||
atomic.StoreUint64(&alloc.mpTxID, 0)
|
||||
}
|
||||
|
||||
func (alloc *TxIDAllocator) setTransactionID(id uint64) {
|
||||
alloc.txIDLock.Lock()
|
||||
defer alloc.txIDLock.Unlock()
|
||||
|
||||
atomic.StoreUint64(&alloc.mpTxID, id)
|
||||
}
|
||||
|
||||
func (alloc *TxIDAllocator) getTransactionID() uint64 {
|
||||
return atomic.LoadUint64(&alloc.mpTxID)
|
||||
alloc.txIDLock.RLock()
|
||||
defer alloc.txIDLock.RUnlock()
|
||||
|
||||
return alloc.mpTxID
|
||||
}
|
||||
|
||||
func (alloc *TxIDAllocator) allocateTransactionID() (mpTxID uint64) {
|
||||
alloc.txIDLock.Lock()
|
||||
defer alloc.txIDLock.Unlock()
|
||||
mpTxID = atomic.LoadUint64(&alloc.mpTxID) + 1
|
||||
alloc.setTransactionID(mpTxID)
|
||||
return
|
||||
|
||||
alloc.mpTxID++
|
||||
return alloc.mpTxID
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user