You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/06/20 05:41:26 UTC

lucene-solr:master: SOLR-8995: replace SAM implementations with lambda

Repository: lucene-solr
Updated Branches:
  refs/heads/master 0179b3fb2 -> bd9005d56


SOLR-8995: replace SAM implementations with lambda


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/bd9005d5
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/bd9005d5
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/bd9005d5

Branch: refs/heads/master
Commit: bd9005d562372930b99eaa99ae45cc488c3d8a90
Parents: 0179b3f
Author: Noble Paul <no...@apache.org>
Authored: Mon Jun 20 11:11:18 2016 +0530
Committer: Noble Paul <no...@apache.org>
Committed: Mon Jun 20 11:11:18 2016 +0530

----------------------------------------------------------------------
 .../org/apache/solr/cloud/ElectionContext.java  | 50 +++++++++-----------
 .../org/apache/solr/common/util/RetryUtil.java  |  8 ++--
 .../apache/solr/common/util/TestRetryUtil.java  | 36 +++++---------
 3 files changed, 39 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bd9005d5/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
index 38f6083..d528947 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
@@ -180,35 +180,31 @@ class ShardLeaderElectionContextBase extends ElectionContext {
     zcmd.ensureExists(parent, zkClient);
 
     try {
-      RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, new RetryCmd() {
-        
-        @Override
-        public void execute() throws InterruptedException, KeeperException {
-          synchronized (lock) {
-            log.info("Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath);
-            List<Op> ops = new ArrayList<>(2);
-
-            // We use a multi operation to get the parent nodes version, which will
-            // be used to make sure we only remove our own leader registration node.
-            // The setData call used to get the parent version is also the trigger to
-            // increment the version. We also do a sanity check that our leaderSeqPath exists.
-
-            ops.add(Op.check(leaderSeqPath, -1));
-            ops.add(Op.create(leaderPath, Utils.toJSON(leaderProps), zkClient.getZkACLProvider().getACLsToAdd(leaderPath), CreateMode.EPHEMERAL));
-            ops.add(Op.setData(parent, null, -1));
-            List<OpResult> results;
-
-            results = zkClient.multi(ops, true);
-            for (OpResult result : results) {
-              if (result.getType() == ZooDefs.OpCode.setData) {
-                SetDataResult dresult = (SetDataResult) result;
-                Stat stat = dresult.getStat();
-                leaderZkNodeParentVersion = stat.getVersion();
-                return;
-              }
+      RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, () -> {
+        synchronized (lock) {
+          log.info("Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath);
+          List<Op> ops = new ArrayList<>(2);
+
+          // We use a multi operation to get the parent nodes version, which will
+          // be used to make sure we only remove our own leader registration node.
+          // The setData call used to get the parent version is also the trigger to
+          // increment the version. We also do a sanity check that our leaderSeqPath exists.
+
+          ops.add(Op.check(leaderSeqPath, -1));
+          ops.add(Op.create(leaderPath, Utils.toJSON(leaderProps), zkClient.getZkACLProvider().getACLsToAdd(leaderPath), CreateMode.EPHEMERAL));
+          ops.add(Op.setData(parent, null, -1));
+          List<OpResult> results;
+
+          results = zkClient.multi(ops, true);
+          for (OpResult result : results) {
+            if (result.getType() == ZooDefs.OpCode.setData) {
+              SetDataResult dresult = (SetDataResult) result;
+              Stat stat = dresult.getStat();
+              leaderZkNodeParentVersion = stat.getVersion();
+              return;
             }
-            assert leaderZkNodeParentVersion != null;
           }
+          assert leaderZkNodeParentVersion != null;
         }
       });
     } catch (Throwable t) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bd9005d5/solr/solrj/src/java/org/apache/solr/common/util/RetryUtil.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/RetryUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/RetryUtil.java
index 8745a54..2b9a0fd 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/RetryUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/RetryUtil.java
@@ -30,12 +30,12 @@ import org.slf4j.LoggerFactory;
 public class RetryUtil {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   
-  public static interface RetryCmd {
-    public void execute() throws Throwable;
+  public interface RetryCmd {
+    void execute() throws Throwable;
   }
   
-  public static interface BooleanRetryCmd {
-    public boolean execute();
+  public interface BooleanRetryCmd {
+    boolean execute();
   }
   
   public static void retryOnThrowable(Class clazz, long timeoutms, long intervalms, RetryCmd cmd) throws Throwable {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bd9005d5/solr/solrj/src/test/org/apache/solr/common/util/TestRetryUtil.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/TestRetryUtil.java b/solr/solrj/src/test/org/apache/solr/common/util/TestRetryUtil.java
index 05bfce1..8e099e5 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/TestRetryUtil.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/TestRetryUtil.java
@@ -28,14 +28,10 @@ public class TestRetryUtil extends SolrTestCaseJ4 {
 
   public void testRetryOnThrowable() throws Throwable {
     final AtomicInteger executes = new AtomicInteger();
-    RetryUtil.retryOnThrowable(SolrException.class, 10000, 10, new RetryCmd() {
-      
-      @Override
-      public void execute() throws Throwable {
-        int calls = executes.incrementAndGet();
-        if (calls <= 2) {
-          throw new SolrException(ErrorCode.SERVER_ERROR, "Bad Stuff Happened");
-        }
+    RetryUtil.retryOnThrowable(SolrException.class, 10000, 10, () -> {
+      int calls = executes.incrementAndGet();
+      if (calls <= 2) {
+        throw new SolrException(ErrorCode.SERVER_ERROR, "Bad Stuff Happened");
       }
     });
     
@@ -45,15 +41,11 @@ public class TestRetryUtil extends SolrTestCaseJ4 {
     boolean caughtSolrException = false;
     try {
       RetryUtil.retryOnThrowable(IllegalStateException.class, 10000, 10,
-          new RetryCmd() {
-            
-            @Override
-            public void execute() throws Throwable {
-              int calls = executes2.incrementAndGet();
-              if (calls <= 2) {
-                throw new SolrException(ErrorCode.SERVER_ERROR,
-                    "Bad Stuff Happened");
-              }
+          () -> {
+            int calls = executes2.incrementAndGet();
+            if (calls <= 2) {
+              throw new SolrException(ErrorCode.SERVER_ERROR,
+                  "Bad Stuff Happened");
             }
           });
     } catch (SolrException e) {
@@ -65,13 +57,9 @@ public class TestRetryUtil extends SolrTestCaseJ4 {
     final AtomicInteger executes3 = new AtomicInteger();
     caughtSolrException = false;
     try {
-      RetryUtil.retryOnThrowable(SolrException.class, 1000, 10, new RetryCmd() {
-        
-        @Override
-        public void execute() throws Throwable {
-          executes3.incrementAndGet();
-          throw new SolrException(ErrorCode.SERVER_ERROR, "Bad Stuff Happened");
-        }
+      RetryUtil.retryOnThrowable(SolrException.class, 1000, 10, () -> {
+        executes3.incrementAndGet();
+        throw new SolrException(ErrorCode.SERVER_ERROR, "Bad Stuff Happened");
       });
     } catch (SolrException e) {
       caughtSolrException = true;