You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/02/18 18:06:13 UTC

incubator-usergrid git commit: remove synchronization

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-273-indexbuffer f86b62b4b -> 83744b35d


remove synchronization


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/83744b35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/83744b35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/83744b35

Branch: refs/heads/USERGRID-273-indexbuffer
Commit: 83744b35d5a842ddcc6447d6fc209722ed0a42a2
Parents: f86b62b
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Feb 18 09:06:05 2015 -0800
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Feb 18 09:06:05 2015 -0800

----------------------------------------------------------------------
 .../index/impl/IndexBatchBufferImpl.java        | 71 +++++++++++---------
 1 file changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/83744b35/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBatchBufferImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBatchBufferImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBatchBufferImpl.java
index 380499b..17380b3 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBatchBufferImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBatchBufferImpl.java
@@ -129,22 +129,26 @@ public class IndexBatchBufferImpl implements IndexBatchBuffer {
     /**
      * Execute the request, check for errors, then re-init the batch for future use
      */
-    private synchronized void execute(boolean refresh ) {
-            if(blockingQueue.size()==0){
-                return;
-            }
-            BulkRequestBuilder bulkRequest = client.prepareBulk();
-            bulkRequest.setRefresh(refresh);
-            int count = bufferSize;
-            //clear the queue or proceed to buffersize
-            while (blockingQueue.size() > 0 && count-- > 0) {
-                RequestBuilderContainer container;
-                try{
-                    container = (RequestBuilderContainer)blockingQueue.take();
-                }catch (InterruptedException ie){
-                    log.error("Problem taking messages off of queue",ie);
-                    throw new RuntimeException(ie);
+    private void execute(boolean refresh ) {
+        if (blockingQueue.size() == 0) {
+            return;
+        }
+        BulkRequestBuilder bulkRequest = client.prepareBulk();
+        bulkRequest.setRefresh(refresh);
+        int count = bufferSize;
+        //clear the queue or proceed to buffersize
+        while (blockingQueue.size() > 0 && count-- > 0) {
+            RequestBuilderContainer container = null;
+            try {
+                Object o =   blockingQueue.take();
+                if (o != null) {
+                    container = (RequestBuilderContainer) o;
                 }
+            } catch (InterruptedException ie) {
+                log.error("Problem taking messages off of queue", ie);
+                throw new RuntimeException(ie);
+            }
+            if(container != null) {
                 ShardReplicationOperationRequestBuilder builder = container.getBuilder();
                 //only handle two types of requests for now, annoyingly there is no base class implementation on BulkRequest
                 if (builder instanceof IndexRequestBuilder) {
@@ -154,29 +158,30 @@ public class IndexBatchBufferImpl implements IndexBatchBuffer {
                     bulkRequest.add((DeleteRequestBuilder) builder);
                 }
             }
-            //nothing to do, we haven't added anthing to the index
-            if (bulkRequest.numberOfActions() == 0) {
-                return;
-            }
+        }
+        //nothing to do, we haven't added anthing to the index
+        if (bulkRequest.numberOfActions() == 0) {
+            return;
+        }
 
-            final BulkResponse responses;
+        final BulkResponse responses;
 
-            try {
-                responses = bulkRequest.execute().actionGet();
-            } catch (Throwable t) {
-                log.error("Unable to communicate with elasticsearch");
-                failureMonitor.fail("Unable to execute batch", t);
-                throw t;
-            }
+        try {
+            responses = bulkRequest.execute().actionGet();
+        } catch (Throwable t) {
+            log.error("Unable to communicate with elasticsearch");
+            failureMonitor.fail("Unable to execute batch", t);
+            throw t;
+        }
 
-            failureMonitor.success();
+        failureMonitor.success();
 
-            for (BulkItemResponse response : responses) {
-                if (response.isFailed()) {
-                    throw new RuntimeException("Unable to index documents.  Errors are :"
-                            + response.getFailure().getMessage());
-                }
+        for (BulkItemResponse response : responses) {
+            if (response.isFailed()) {
+                throw new RuntimeException("Unable to index documents.  Errors are :"
+                        + response.getFailure().getMessage());
             }
+        }
     }
 
     private static class Producer implements Observable.OnSubscribe<RequestBuilderContainer> {