totalo commented on a change in pull request #10391:
URL: https://github.com/apache/shardingsphere/pull/10391#discussion_r636915885
##########
File path:
shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-etcd/src/main/java/org/apache/shardingsphere/governance/repository/etcd/EtcdRepository.java
##########
@@ -129,23 +131,37 @@ private Type getEventChangedType(final WatchEvent event) {
return Type.IGNORED;
}
}
-
+
@Override
public boolean tryLock(final String key, final long time, final TimeUnit
unit) {
- // TODO
- return false;
+ try {
+ long leaseId =
client.getLeaseClient().grant(etcdProperties.getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS)).get().getID();
+ client.getLockClient().lock(ByteSequence.from(key,
StandardCharsets.UTF_8), leaseId).get(time, unit);
+ return true;
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ log.error("etcdRepository tryLock error, key = {}, time = {}, unit
= {}", key, time, unit, ex);
+ return false;
+ }
}
-
+
@Override
public void releaseLock(final String key) {
- // TODO
+ try {
+ client.getLockClient().unlock(ByteSequence.from(key,
StandardCharsets.UTF_8)).get(etcdProperties.getValue(EtcdPropertyKey.CONNECTION_TIMEOUT_SECONDS),
TimeUnit.SECONDS);
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ log.error("etcdRepository releaseLock error, key = {}", key, ex);
Review comment:
ok i have fixed it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]