You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/05/21 09:16:59 UTC

[GitHub] [shardingsphere] totalo commented on a change in pull request #10391: Add etcd lock

totalo commented on a change in pull request #10391:
URL: https://github.com/apache/shardingsphere/pull/10391#discussion_r636767505



##########
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 +129,36 @@ 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
+            return false;

Review comment:
       ok ~




-- 
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:
users@infra.apache.org