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 2014/09/22 23:43:46 UTC

git commit: more efficient counting, no receipts

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o 2703af757 -> 6c8e70157


more efficient counting, no receipts


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

Branch: refs/heads/two-dot-o
Commit: 6c8e701574b556e97e78a1ea4232b2009fa07632
Parents: 2703af7
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Sep 22 15:43:31 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Sep 22 15:43:31 2014 -0600

----------------------------------------------------------------------
 .../notifications/SingleQueueTaskManager.java   | 109 +++++++++----------
 .../AbstractServiceNotificationIT.java          |  22 ++--
 2 files changed, 69 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6c8e7015/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
index 4b11974..6341042 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
@@ -123,7 +123,7 @@ public class SingleQueueTaskManager implements NotificationsTaskManager {
             receipt.setUuid(savedReceipt.getUuid());
 
             List<EntityRef> entities = Arrays.asList(notification, device);
-            em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, savedReceipt);
+//            em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, savedReceipt);
         } else {
             em.update(receipt);
         }
@@ -145,65 +145,64 @@ public class SingleQueueTaskManager implements NotificationsTaskManager {
     }
 
     public void finishedBatch() throws Exception {
-        //synchronized (this) { //avoid issues with counting
-            long successes = this.successes.getAndSet(0); //reset counters
-            long failures = this.failures.getAndSet(0); //reset counters
-            this.hasFinished = true;
-
-            // refresh notification
-            Notification notification = em.get(this.notification.getUuid(), Notification.class);
-            notification.setModified(System.currentTimeMillis());
-
-            Map<String, Object> properties;
-            Map<String, Long> stats;
-            String statsKey = "statistics_batch";
-
-            //write out current results to a set so no overlap in multiple writes will occur
-            if (successes + failures > 0) {
-                properties = new HashMap<String, Object>(4);
-                stats = new HashMap<String, Long>(2);
-                stats.put("sent", successes);
-                stats.put("errors", failures);
-                properties.put(statsKey + "_" + System.currentTimeMillis(), stats);
-                properties.put("modified", notification.getModified());
-                em.updateProperties(notification, properties);
-            }
+        long successes = this.successes.getAndSet(0); //reset counters
+        long failures = this.failures.getAndSet(0); //reset counters
+        this.hasFinished = true;
+
+        // refresh notification
+        Notification notification = em.get(this.notification.getUuid(), Notification.class);
+        notification.setModified(System.currentTimeMillis());
+
+        Map<String, Long> stats;
+        String statsKey = "statistics_batch";
+        Map<String, Object> properties;
+        //write out current results to a set so no overlap in multiple writes will occur
+        if (successes + failures > 0) {
+            properties = new HashMap<String, Object>(4);
+            stats = new HashMap<String, Long>(2);
+            stats.put("sent", successes);
+            stats.put("errors", failures);
+            properties.put(statsKey + "_" + System.currentTimeMillis(), stats);
+            properties.put("modified", notification.getModified());
+            notification.addProperties(properties);
+            em.update(notification);
+        }
 
-            //resum the stats
-            properties = em.getProperties(notification); // re-read
-            long sent = 0;
-            long errors = 0;
-            for (String key : properties.keySet()) {
-                if (key.contains(statsKey)) {
-                    stats = (Map<String, Long>) properties.get(key);
-                    sent += stats.get("sent");
-                    errors += stats.get("errors");
-                }
+        //resum the stats
+        notification = em.get(this.notification.getUuid(), Notification.class); // re-read
+        properties = notification.getProperties();
+        long sent = 0;
+        long errors = 0;
+        for (String key : properties.keySet()) {
+            if (key.contains(statsKey)) {
+                stats = (Map<String, Long>) properties.get(key);
+                sent += stats.get("sent");
+                errors += stats.get("errors");
             }
+        }
 
-            //and write them out again, this will produce the most accurate count
-            stats = new HashMap<String, Long>(2);
-            stats.put("sent", sent);
-            stats.put("errors", errors);
-            notification.setStatistics(stats);
-
-            LOG.info("notification {} sending to {}", notification.getUuid(), sent + errors);
-
-            //none of this is known and should you ever do this
-            if (notification.getExpectedCount() <= (errors + sent)) {
-                notification.setFinished(notification.getModified());
-                properties.put("finished", notification.getModified());
-                properties.put("state", notification.getState());
-                LOG.info("done sending to devices in {} ms", notification.getFinished() - notification.getStarted());
-            }
+        //and write them out again, this will produce the most accurate count
+        stats = new HashMap<String, Long>(2);
+        stats.put("sent", sent);
+        stats.put("errors", errors);
+        notification.setStatistics(stats);
+
+        LOG.info("notification {} sending to {}", notification.getUuid(), sent + errors);
+
+        //none of this is known and should you ever do this
+        if (notification.getExpectedCount() <= (errors + sent)) {
+            notification.setFinished(notification.getModified());
+            properties.put("finished", notification.getModified());
+            properties.put("state", notification.getState());
+            LOG.info("done sending to devices in {} ms", notification.getFinished() - notification.getStarted());
+            notification.addProperties(properties);
+        }
 
-            LOG.info("notification finished batch: {}", notification.getUuid());
-            em.updateProperties(notification, properties);
-            em.update(notification);
-       // }
+        LOG.info("notification finished batch: {}", notification.getUuid());
+        em.update(notification);
 
-        //Set<Notifier> notifiers = new HashSet<Notifier>(proxy.getNotifierMap().values()); // remove dups
-       // proxy.asyncCheckForInactiveDevices(notifiers);
+        Set<Notifier> notifiers = new HashSet<Notifier>(proxy.getNotifierMap().values()); // remove dups
+        proxy.asyncCheckForInactiveDevices(notifiers);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6c8e7015/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index 8dcbdaf..8acb0f1 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -27,6 +27,7 @@ import org.junit.Rule;
 import org.junit.rules.TestName;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -68,8 +69,7 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
         while (System.currentTimeMillis() < timeout) {
             Thread.sleep(200);
             app.getEm().refreshIndex();
-            notification = app.getEm().get(notification.getUuid(),
-                    Notification.class);
+            notification = app.getEm().get(notification.getUuid(), Notification.class);
             if (notification.getFinished() != null) {
                 return notification;
             }
@@ -80,13 +80,21 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
 
     protected List<EntityRef> getNotificationReceipts(EntityRef notification)
             throws Exception {
-        Results r = app.getEm().getCollection(notification,
-                Notification.RECEIPTS_COLLECTION, null, 1000000,
-                Query.Level.REFS, false);
+        Query query = new Query();
+        query.setCollection("receipts");
+        query.setLimit(100);
+        PathQuery<Receipt> pathQuery = new PathQuery<Receipt>(
+                new SimpleEntityRef(app.getEm().getApplicationRef()),
+                query
+        );
+        Iterator<Receipt> it = pathQuery.iterator(app.getEm());
         List<EntityRef> list =new ArrayList<EntityRef>();//get all
-        PagingResultsIterator it = new PagingResultsIterator(r);
         while(it.hasNext()){
-            list.add((EntityRef)it.next());
+            Receipt receipt =it.next();
+
+            if(receipt.getNotificationUUID().equals(notification.getUuid())) {
+                list.add(receipt);
+            }
         }
         return list;
     }