You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/12/19 23:39:02 UTC

[GitHub] milleruntime closed pull request #843: Remove extra loop in InMemoryMap

milleruntime closed pull request #843: Remove extra loop in InMemoryMap
URL: https://github.com/apache/accumulo/pull/843
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java
index e93e7f60b8..b9e2167251 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/InMemoryMap.java
@@ -528,11 +528,7 @@ public void mutate(List<Mutation> mutations, int kvCount) {
    * Applies changes to a row in the InMemoryMap
    *
    */
-  public void mutate(List<Mutation> mutations) {
-    int numKVs = 0;
-    for (Mutation mutation : mutations)
-      numKVs += mutation.size();
-
+  public void mutate(List<Mutation> mutations, int numKVs) {
     // Can not update mutationCount while writes that started before
     // are in progress, this would cause partial mutations to be seen.
     // Also, can not continue until mutation count is updated, because
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CommitSession.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CommitSession.java
index 885b349182..247f0c8ef4 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CommitSession.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/CommitSession.java
@@ -111,7 +111,7 @@ public long getMaxCommittedTime() {
     return maxCommittedTime;
   }
 
-  public void mutate(List<Mutation> mutations) {
-    memTable.mutate(mutations);
+  public void mutate(List<Mutation> mutations, int count) {
+    memTable.mutate(mutations, count);
   }
 }
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java
index facf55d0b2..7eb0434a50 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java
@@ -445,7 +445,7 @@ public void receive(Mutation m) {
                     maxTime.set(Math.max(maxTime.get(), columnUpdate.getTimestamp()));
                   }
                 }
-                getTabletMemory().mutate(commitSession, Collections.singletonList(m));
+                getTabletMemory().mutate(commitSession, Collections.singletonList(m), 1);
                 entriesUsedOnTablet.incrementAndGet();
               }
             });
@@ -1284,7 +1284,7 @@ public void commit(CommitSession commitSession, List<Mutation> mutations) {
       totalBytes += mutation.numBytes();
     }
 
-    getTabletMemory().mutate(commitSession, mutations);
+    getTabletMemory().mutate(commitSession, mutations, totalCount);
 
     synchronized (this) {
       if (writesInProgress < 1) {
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/TabletMemory.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/TabletMemory.java
index cf1d1ebe7f..284d912504 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/TabletMemory.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/TabletMemory.java
@@ -147,8 +147,8 @@ public void waitForMinC() {
     }
   }
 
-  public void mutate(CommitSession cm, List<Mutation> mutations) {
-    cm.mutate(mutations);
+  public void mutate(CommitSession cm, List<Mutation> mutations, int count) {
+    cm.mutate(mutations, count);
   }
 
   public void updateMemoryUsageStats() {
diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java
index 1b828876a9..74203f6a3f 100644
--- a/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java
+++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java
@@ -127,7 +127,7 @@ public void mutate(InMemoryMap imm, String row, String column, long ts) {
     String[] sa = column.split(":");
     m.putDelete(new Text(sa[0]), new Text(sa[1]), ts);
 
-    imm.mutate(Collections.singletonList(m));
+    imm.mutate(Collections.singletonList(m), 1);
   }
 
   public void mutate(InMemoryMap imm, String row, String column, long ts, String value) {
@@ -135,7 +135,7 @@ public void mutate(InMemoryMap imm, String row, String column, long ts, String v
     String[] sa = column.split(":");
     m.put(new Text(sa[0]), new Text(sa[1]), ts, new Value(value.getBytes()));
 
-    imm.mutate(Collections.singletonList(m));
+    imm.mutate(Collections.singletonList(m), 1);
   }
 
   static Key newKey(String row, String column, long ts) {
@@ -492,7 +492,7 @@ public void testDuplicateKey() throws Exception {
     Mutation m = new Mutation(new Text("r1"));
     m.put(new Text("foo"), new Text("cq"), 3, new Value("v1".getBytes()));
     m.put(new Text("foo"), new Text("cq"), 3, new Value("v2".getBytes()));
-    imm.mutate(Collections.singletonList(m));
+    imm.mutate(Collections.singletonList(m), 2);
 
     MemoryIterator skvi1 = imm.skvIterator(null);
     skvi1.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
@@ -529,7 +529,7 @@ public void run() {
                 Mutation m = new Mutation("row");
                 m.put("cf", "cq", new Value("v".getBytes()));
                 List<Mutation> mutations = Collections.singletonList(m);
-                imm.mutate(mutations);
+                imm.mutate(mutations, 1);
                 counts[threadId]++;
               }
             }
@@ -583,7 +583,7 @@ public void testLocalityGroups() throws Exception {
     m5.put("cf3", "z", 6, "A");
     m5.put("cf4", "z", 6, "B");
 
-    imm.mutate(Arrays.asList(m1, m2, m3, m4, m5));
+    imm.mutate(Arrays.asList(m1, m2, m3, m4, m5), 10);
 
     MemoryIterator iter1 = imm.skvIterator(null);
 
diff --git a/test/src/main/java/org/apache/accumulo/test/InMemoryMapIT.java b/test/src/main/java/org/apache/accumulo/test/InMemoryMapIT.java
index 99aa185fc8..c0a1ba1b74 100644
--- a/test/src/main/java/org/apache/accumulo/test/InMemoryMapIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/InMemoryMapIT.java
@@ -267,10 +267,13 @@ private void assertEquivalentMutate(List<Mutation> mutations) {
     assertEquals("Not a LocalityGroupMap with native", InMemoryMap.TYPE_LOCALITY_GROUP_MAP_NATIVE,
         localityGroupMapWithNative.getMapType());
 
-    defaultMap.mutate(mutations);
-    nativeMapWrapper.mutate(mutations);
-    localityGroupMap.mutate(mutations);
-    localityGroupMapWithNative.mutate(mutations);
+    int count = 0;
+    for (Mutation m : mutations)
+      count += m.size();
+    defaultMap.mutate(mutations, count);
+    nativeMapWrapper.mutate(mutations, count);
+    localityGroupMap.mutate(mutations, count);
+    localityGroupMapWithNative.mutate(mutations, count);
 
     // let's use the transitive property to assert all four are equivalent
     assertMutatesEquivalent(mutations, defaultMap, nativeMapWrapper);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services