|
@ -75,7 +75,7 @@ func (impl *ETCDLockClientImplement) Lock() (err error) { |
|
|
txn clientv3.Txn |
|
|
txn clientv3.Txn |
|
|
txnRes *clientv3.TxnResponse |
|
|
txnRes *clientv3.TxnResponse |
|
|
) |
|
|
) |
|
|
lockKey := fmt.Sprintf("lock/%s/%s/%s/mutex", impl.Addr, impl.Database, impl.Table) |
|
|
|
|
|
|
|
|
lockKey := fmt.Sprintf("/lock/%s/%s/%s/mutex", impl.Addr, impl.Database, impl.Table) |
|
|
//创建上下文
|
|
|
//创建上下文
|
|
|
ctx, cancelFunc = context.WithCancel(context.TODO()) |
|
|
ctx, cancelFunc = context.WithCancel(context.TODO()) |
|
|
//创建续租
|
|
|
//创建续租
|
|
@ -96,7 +96,7 @@ func (impl *ETCDLockClientImplement) Lock() (err error) { |
|
|
txn = impl.KV.Txn(context.TODO()) |
|
|
txn = impl.KV.Txn(context.TODO()) |
|
|
//事务枪锁
|
|
|
//事务枪锁
|
|
|
txn.If(clientv3.Compare(clientv3.CreateRevision(lockKey), "=", 0)). |
|
|
txn.If(clientv3.Compare(clientv3.CreateRevision(lockKey), "=", 0)). |
|
|
Then(clientv3.OpPut(lockKey, "", clientv3.WithLease(leaseId))). |
|
|
|
|
|
|
|
|
Then(clientv3.OpPut(lockKey, "mutex", clientv3.WithLease(leaseId))). |
|
|
Else(clientv3.OpGet(lockKey)) |
|
|
Else(clientv3.OpGet(lockKey)) |
|
|
|
|
|
|
|
|
//提交事务
|
|
|
//提交事务
|
|
@ -147,8 +147,8 @@ func (impl *ETCDLockClientImplement) RLock() (err error) { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
keyId := uid.String() |
|
|
keyId := uid.String() |
|
|
rLockKey := fmt.Sprintf("lock/%s/%s/%s/rwmutex/read/%s", impl.Addr, impl.Database, impl.Table, keyId) |
|
|
|
|
|
wLockKey := fmt.Sprintf("lock/%s/%s/%s/rwmutex/write", impl.Addr, impl.Database, impl.Table) |
|
|
|
|
|
|
|
|
rLockKey := fmt.Sprintf("/lock/%s/%s/%s/rwmutex/read/%s", impl.Addr, impl.Database, impl.Table, keyId) |
|
|
|
|
|
wLockKey := fmt.Sprintf("/lock/%s/%s/%s/rwmutex/write", impl.Addr, impl.Database, impl.Table) |
|
|
//创建上下文
|
|
|
//创建上下文
|
|
|
ctx, cancelFunc = context.WithCancel(context.TODO()) |
|
|
ctx, cancelFunc = context.WithCancel(context.TODO()) |
|
|
//创建续租
|
|
|
//创建续租
|
|
@ -208,8 +208,8 @@ func (impl *ETCDLockClientImplement) WLock() (err error) { |
|
|
txn clientv3.Txn |
|
|
txn clientv3.Txn |
|
|
txnRes *clientv3.TxnResponse |
|
|
txnRes *clientv3.TxnResponse |
|
|
) |
|
|
) |
|
|
rLockKey := fmt.Sprintf("lock/%s/%s/%s/rwmutex/read", impl.Addr, impl.Database, impl.Table) |
|
|
|
|
|
wLockKey := fmt.Sprintf("lock/%s/%s/%s/rwmutex/write", impl.Addr, impl.Database, impl.Table) |
|
|
|
|
|
|
|
|
rLockKey := fmt.Sprintf("/lock/%s/%s/%s/rwmutex/read", impl.Addr, impl.Database, impl.Table) |
|
|
|
|
|
wLockKey := fmt.Sprintf("/lock/%s/%s/%s/rwmutex/write", impl.Addr, impl.Database, impl.Table) |
|
|
//创建上下文
|
|
|
//创建上下文
|
|
|
ctx, cancelFunc = context.WithCancel(context.TODO()) |
|
|
ctx, cancelFunc = context.WithCancel(context.TODO()) |
|
|
//创建续租
|
|
|
//创建续租
|
|
|