25 Star 108 Fork 61

SOFAStack / sofa-jraft

 / 详情

DistributedLock中getFencingToken如何使用?

Backlog
Opened this issue  
2021-10-11 17:35

public static void lockAndAutoKeepLease(final RheaKVStore rheaKVStore) {
final ScheduledExecutorService watchdog = Executors.newSingleThreadScheduledExecutor();
final String lockKey = "lock_example1";
final DistributedLock<byte[]> lock = rheaKVStore.getDistributedLock(lockKey, 3, TimeUnit.SECONDS, watchdog);
long old = lock.getFencingToken();
if (lock.tryLock()) {
try {
long current = lock.getFencingToken();
if (old == current) {
LOG.info("Lock success with: {}", lockKey);
} else {
// error
}
} finally {
lock.unlock();
}
} else {
LOG.info("Fail to lock with: {}", lockKey);
}
ExecutorServiceHelper.shutdownAndAwaitTermination(watchdog);
}

// 以上使用方法是否正确?

Comments (2)

胶布小子 created任务
胶布小子 set related repository to SOFAStack/sofa-jraft
Expand operation logs

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(1)
Java
1
https://git.oschina.net/sofastack/sofa-jraft.git
git@git.oschina.net:sofastack/sofa-jraft.git
sofastack
sofa-jraft
sofa-jraft

Search