accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [15/18] git commit: ACCUMULO-1909 made conditional mutations easier to create
Date Wed, 20 Nov 2013 23:33:34 GMT
ACCUMULO-1909 made conditional mutations easier to create


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/38394f83
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/38394f83
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/38394f83

Branch: refs/heads/master
Commit: 38394f830f61fe3f5230e0d93e03cdb09a1fdd01
Parents: e3b1767
Author: Keith Turner <kturner@apache.org>
Authored: Wed Nov 20 15:17:03 2013 -0500
Committer: Keith Turner <kturner@apache.org>
Committed: Wed Nov 20 16:14:44 2013 -0500

----------------------------------------------------------------------
 .../core/client/impl/ConditionalWriterImpl.java |  3 ++
 .../accumulo/core/data/ConditionalMutation.java | 29 +++++++++-----------
 .../org/apache/accumulo/proxy/ProxyServer.java  |  7 ++---
 .../test/randomwalk/conditional/Init.java       | 14 ++++------
 .../accumulo/test/ConditionalWriterIT.java      | 26 ++++++++++++++----
 5 files changed, 44 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/38394f83/core/src/main/java/org/apache/accumulo/core/client/impl/ConditionalWriterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ConditionalWriterImpl.java
b/core/src/main/java/org/apache/accumulo/core/client/impl/ConditionalWriterImpl.java
index bfbac86..6ba27b9 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ConditionalWriterImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ConditionalWriterImpl.java
@@ -405,6 +405,9 @@ class ConditionalWriterImpl implements ConditionalWriter {
       ConditionalMutation mut = mutations.next();
       count++;
       
+      if (mut.getConditions().size() == 0)
+        throw new IllegalArgumentException("ConditionalMutation had no conditions " + new
String(mut.getRow()));
+
       for (Condition cond : mut.getConditions()) {
         if (!isVisible(cond.getVisibility())) {
           resultQueue.add(new Result(Status.INVISIBLE_VISIBILITY, mut, null));

http://git-wip-us.apache.org/repos/asf/accumulo/blob/38394f83/core/src/main/java/org/apache/accumulo/core/data/ConditionalMutation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/ConditionalMutation.java b/core/src/main/java/org/apache/accumulo/core/data/ConditionalMutation.java
index c438f6d..da72493 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/ConditionalMutation.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/ConditionalMutation.java
@@ -34,30 +34,30 @@ public class ConditionalMutation extends Mutation {
   
   private List<Condition> conditions = new ArrayList<Condition>();
 
-  public ConditionalMutation(byte[] row, Condition condition, Condition... conditions) {
+  public ConditionalMutation(byte[] row, Condition... conditions) {
     super(row);
-    init(condition, conditions);
+    init(conditions);
   }
   
-  public ConditionalMutation(byte[] row, int start, int length, Condition condition, Condition...
conditions) {
+  public ConditionalMutation(byte[] row, int start, int length, Condition... conditions)
{
     super(row, start, length);
-    init(condition, conditions);
+    init(conditions);
   }
   
-  public ConditionalMutation(Text row, Condition condition, Condition... conditions) {
+  public ConditionalMutation(Text row, Condition... conditions) {
     super(row);
-    init(condition, conditions);
+    init(conditions);
   }
   
-  public ConditionalMutation(CharSequence row, Condition condition, Condition... conditions)
{
+  public ConditionalMutation(CharSequence row, Condition... conditions) {
     super(row);
-    init(condition, conditions);
+    init(conditions);
   }
   
-  public ConditionalMutation(ByteSequence row, Condition condition, Condition... conditions)
{
+  public ConditionalMutation(ByteSequence row, Condition... conditions) {
     // TODO add ByteSequence methods to mutations
     super(row.toArray());
-    init(condition, conditions);
+    init(conditions);
   }
   
   public ConditionalMutation(ConditionalMutation cm) {
@@ -65,12 +65,9 @@ public class ConditionalMutation extends Mutation {
     this.conditions = new ArrayList<Condition>(cm.conditions);
   }
 
-  private void init(Condition condition, Condition... conditions) {
-    ArgumentChecker.notNull(condition);
-    this.conditions.add(condition);
-    if (conditions.length > 0) {
-      this.conditions.addAll(Arrays.asList(conditions));
-    }
+  private void init(Condition... conditions) {
+    ArgumentChecker.notNull(conditions);
+    this.conditions.addAll(Arrays.asList(conditions));
   }
   
   public void addCondition(Condition condition) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/38394f83/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
----------------------------------------------------------------------
diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
index d979d40..9324da9 100644
--- a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
+++ b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
@@ -1567,7 +1567,7 @@ public class ProxyServer implements AccumuloProxy.Iface {
       
       ArrayList<ConditionalMutation> cmuts = new ArrayList<ConditionalMutation>(updates.size());
       for (Entry<ByteBuffer,ConditionalUpdates> cu : updates.entrySet()) {
-        ConditionalMutation cmut = null;
+        ConditionalMutation cmut = new ConditionalMutation(ByteBufferUtil.toBytes(cu.getKey()));
         
         for (Condition tcond : cu.getValue().conditions) {
           org.apache.accumulo.core.data.Condition cond = new org.apache.accumulo.core.data.Condition(tcond.column.getColFamily(),
@@ -1587,10 +1587,7 @@ public class ProxyServer implements AccumuloProxy.Iface {
             cond.setIterators(getIteratorSettings(tcond.getIterators()).toArray(new IteratorSetting[tcond.getIterators().size()]));
           }
           
-          if (cmut == null)
-            cmut = new ConditionalMutation(ByteBufferUtil.toBytes(cu.getKey()), cond);
-          else
-            cmut.addCondition(cond);
+          cmut.addCondition(cond);
         }
         
         addUpdatesToMutation(vizMap, cmut, cu.getValue().updates);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/38394f83/test/src/main/java/org/apache/accumulo/test/randomwalk/conditional/Init.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/conditional/Init.java
b/test/src/main/java/org/apache/accumulo/test/randomwalk/conditional/Init.java
index e3de7d8..bfad730 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/conditional/Init.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/conditional/Init.java
@@ -57,26 +57,22 @@ public class Init extends Test {
     ConditionalWriter cw = (ConditionalWriter) state.get("cw");
 
     for (int i : banks) {
-      ConditionalMutation m = null;
+      ConditionalMutation m = new ConditionalMutation(Utils.getBank(i));
       int acceptedCount = 0;
       for (int j = 0; j < numAccts; j++) {
         String cf = Utils.getAccount(j);
-        if (m == null) {
-          m = new ConditionalMutation(Utils.getBank(i), new Condition(cf, "seq"));
-        } else {
-          m.addCondition(new Condition(cf, "seq"));
-        }
+        m.addCondition(new Condition(cf, "seq"));
         m.put(cf, "bal", "100");
         m.put(cf, "seq", Utils.getSeq(0));
 
-        if (j % 1000 == 0) {
+        if (j % 1000 == 0 && j > 0) {
           if (cw.write(m).getStatus() == Status.ACCEPTED)
             acceptedCount++;
-          m = null;
+          m = new ConditionalMutation(Utils.getBank(i));
         }
 
       }
-      if (m != null)
+      if (m.getConditions().size() > 0)
         cw.write(m);
 
       log.debug("Added bank " + Utils.getBank(i) + " " + acceptedCount);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/38394f83/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java b/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
index cef24da..a842d6d 100644
--- a/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
@@ -48,6 +48,7 @@ import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.RowIterator;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.TableDeletedException;
+import org.apache.accumulo.core.client.TableExistsException;
 import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.client.TableOfflineException;
 import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -910,7 +911,7 @@ public class ConditionalWriterIT extends SimpleMacIT {
   public void testThreads() throws Exception {
     // test multiple threads using a single conditional writer
 
-    String table = "foo9";
+    String table = getTableNames(1)[0];
     Connector conn = getConnector();
 
     conn.tableOperations().create(table);
@@ -1032,7 +1033,7 @@ public class ConditionalWriterIT extends SimpleMacIT {
   public void testTimeout() throws Exception {
     Connector conn = getConnector();
 
-    String table = "fooT";
+    String table = getTableNames(1)[0];
 
     conn.tableOperations().create(table);
 
@@ -1079,7 +1080,7 @@ public class ConditionalWriterIT extends SimpleMacIT {
 
   @Test
   public void testDeleteTable() throws Exception {
-    String table = "foo12";
+    String table = getTableNames(1)[0];
     Connector conn = getConnector();
 
     try {
@@ -1109,7 +1110,7 @@ public class ConditionalWriterIT extends SimpleMacIT {
 
   @Test
   public void testOffline() throws Exception {
-    String table = "foo11";
+    String table = getTableNames(1)[0];
     Connector conn = getConnector();
 
     conn.tableOperations().create(table);
@@ -1141,7 +1142,7 @@ public class ConditionalWriterIT extends SimpleMacIT {
 
   @Test
   public void testError() throws Exception {
-    String table = "foo10";
+    String table = getTableNames(1)[0];
     Connector conn = getConnector();
 
     conn.tableOperations().create(table);
@@ -1166,4 +1167,19 @@ public class ConditionalWriterIT extends SimpleMacIT {
     cw.close();
   }
 
+  @Test(expected = IllegalArgumentException.class)
+  public void testNoConditions() throws AccumuloException, AccumuloSecurityException, TableExistsException,
TableNotFoundException {
+    String table = getTableNames(1)[0];
+    Connector conn = getConnector();
+
+    conn.tableOperations().create(table);
+
+    ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
+
+    ConditionalMutation cm1 = new ConditionalMutation("r1");
+    cm1.put("tx", "seq", "1");
+    cm1.put("data", "x", "a");
+
+    cw.write(cm1);
+  }
 }


Mime
View raw message