accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1397936 - in /accumulo/trunk: ./ core/ core/src/main/java/org/apache/accumulo/core/client/admin/ core/src/main/java/org/apache/accumulo/core/client/mock/ core/src/main/java/org/apache/accumulo/core/iterators/ core/src/main/java/org/apache/...
Date Sat, 13 Oct 2012 19:43:31 GMT
Author: kturner
Date: Sat Oct 13 19:43:30 2012
New Revision: 1397936

URL: http://svn.apache.org/viewvc?rev=1397936&view=rev
Log:
ACCUMULO-795 Applied patch from Drew Farris that allows mock to create tables w/o versioning
(merged from 1.4)

Modified:
    accumulo/trunk/   (props changed)
    accumulo/trunk/core/   (props changed)
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
    accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java   (props changed)
    accumulo/trunk/server/   (props changed)
    accumulo/trunk/src/   (props changed)

Propchange: accumulo/trunk/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/src:r1397921
  Merged /accumulo/branches/1.4:r1397921

Propchange: accumulo/trunk/core/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/core:r1397921
  Merged /accumulo/branches/1.4/src/core:r1397921

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java?rev=1397936&r1=1397935&r2=1397936&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
Sat Oct 13 19:43:30 2012
@@ -190,11 +190,7 @@ public class TableOperationsImpl extends
     
     List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(timeType.name().getBytes()));
     
-    Map<String,String> opts;
-    if (limitVersion) {
-      opts = IteratorUtil.generateInitialTableProperties();
-    } else
-      opts = Collections.emptyMap();
+    Map<String,String> opts = IteratorUtil.generateInitialTableProperties(limitVersion);
     
     try {
       doTableOperation(TableOperation.CREATE, args, opts);

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java?rev=1397936&r1=1397935&r2=1397936&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
Sat Oct 13 19:43:30 2012
@@ -88,9 +88,9 @@ public class MockTable {
   private TimeType timeType;
   SortedSet<Text> splits = new TreeSet<Text>();
   
-  MockTable(boolean useVersions, TimeType timeType) {
+  MockTable(boolean limitVersion, TimeType timeType) {
     this.timeType = timeType;
-    settings = IteratorUtil.generateInitialTableProperties();
+    settings = IteratorUtil.generateInitialTableProperties(limitVersion);
     for (Entry<String,String> entry : AccumuloConfiguration.getDefaultConfiguration())
{
       String key = entry.getKey();
       if (key.startsWith(Property.TABLE_PREFIX.getKey()))

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java?rev=1397936&r1=1397935&r2=1397936&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
Sat Oct 13 19:43:30 2012
@@ -63,13 +63,22 @@ public class IteratorUtil {
     
   }
   
-  public static Map<String,String> generateInitialTableProperties() {
+  /**
+   * Generate the initial (default) properties for a table
+   * @param limitVersion
+   *   include a VersioningIterator at priority 20 that retains a single version of a given
K/V pair.
+   * @return A map of Table properties
+   */
+  public static Map<String,String> generateInitialTableProperties(boolean limitVersion)
{
     TreeMap<String,String> props = new TreeMap<String,String>();
     
-    for (IteratorScope iterScope : IteratorScope.values()) {
-      props.put(Property.TABLE_ITERATOR_PREFIX + iterScope.name() + ".vers", "20," + VersioningIterator.class.getName());
-      props.put(Property.TABLE_ITERATOR_PREFIX + iterScope.name() + ".vers.opt.maxVersions",
"1");
+    if (limitVersion) {
+        for (IteratorScope iterScope : IteratorScope.values()) {
+          props.put(Property.TABLE_ITERATOR_PREFIX + iterScope.name() + ".vers", "20," +
VersioningIterator.class.getName());
+          props.put(Property.TABLE_ITERATOR_PREFIX + iterScope.name() + ".vers.opt.maxVersions",
"1");
+        }
     }
+    
     return props;
   }
   

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java?rev=1397936&r1=1397935&r2=1397936&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
Sat Oct 13 19:43:30 2012
@@ -110,7 +110,7 @@ public class CreateTableCommand extends 
     // context
     
     if (cl.hasOption(createTableNoDefaultIters.getOpt())) {
-      for (String key : IteratorUtil.generateInitialTableProperties().keySet()) {
+      for (String key : IteratorUtil.generateInitialTableProperties(true).keySet()) {
         shellState.getConnector().tableOperations().removeProperty(tableName, key);
       }
     }

Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java?rev=1397936&r1=1397935&r2=1397936&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
(original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
Sat Oct 13 19:43:30 2012
@@ -20,25 +20,36 @@ import java.io.IOException;
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.MutationsRejectedException;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.TableExistsException;
 import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.client.admin.TimeType;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.file.FileOperations;
 import org.apache.accumulo.core.file.FileSKVWriter;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.iterators.user.VersioningIterator;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.security.ColumnVisibility;
 import org.apache.accumulo.core.security.thrift.AuthInfo;
@@ -50,6 +61,69 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class MockTableOperationsTest {
+
+    @Test
+    public void testCreateUseVersions() throws AccumuloException, AccumuloSecurityException,
TableExistsException, TableNotFoundException {
+        Instance instance = new MockInstance("topstest");
+        Connector conn = instance.getConnector("user", "pass");
+        String t = "tableName1";
+        
+        {
+            conn.tableOperations().create(t, false, TimeType.LOGICAL);
+            
+            writeVersionable(conn, t, 3);
+            assertVersionable(conn, t, 3);
+            
+            IteratorSetting settings = new IteratorSetting(20,VersioningIterator.class);
+            conn.tableOperations().attachIterator(t, settings);
+            
+            assertVersionable(conn, t, 1);
+            
+            conn.tableOperations().delete(t);
+        }
+        
+        {
+            conn.tableOperations().create(t, true, TimeType.MILLIS);
+            
+            try {
+                IteratorSetting settings = new IteratorSetting(20,VersioningIterator.class);
+                conn.tableOperations().attachIterator(t, settings);
+                Assert.fail();
+            }
+            catch (IllegalArgumentException ex) {}
+            
+            writeVersionable(conn, t, 3);
+            assertVersionable(conn, t, 1);
+            
+            conn.tableOperations().delete(t);
+        }
+    }
+    
+    protected void writeVersionable(Connector c, String tableName, int size) throws TableNotFoundException,
MutationsRejectedException {
+        for (int i=0; i < size; i++) {
+            BatchWriter w = c.createBatchWriter(tableName, 100, 100, 1);
+            Mutation m = new Mutation("row1");
+            m.put("cf", "cq", String.valueOf(i));
+            w.addMutation(m);
+            w.close();
+        }
+    }
+    
+    protected void assertVersionable(Connector c, String tableName, int size) throws TableNotFoundException
{
+        BatchScanner s = c.createBatchScanner(tableName, Constants.NO_AUTHS, 1);
+        s.setRanges(Collections.singleton(Range.exact("row1", "cf", "cq")));
+        int count = 0;
+        for (Map.Entry<Key, Value> e: s) {
+            Assert.assertEquals("row1", e.getKey().getRow().toString());
+            Assert.assertEquals("cf", e.getKey().getColumnFamily().toString());
+            Assert.assertEquals("cq", e.getKey().getColumnQualifier().toString());
+            count++;
+            
+        }
+        Assert.assertEquals(size, count);
+        s.close();
+    }
+    
   @Test
   public void testTableNotFound() throws AccumuloException, AccumuloSecurityException, TableExistsException,
TableNotFoundException {
     Instance instance = new MockInstance("topstest");

Propchange: accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java:r1397921
  Merged /accumulo/branches/1.4/src/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java:r1397921

Propchange: accumulo/trunk/server/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/server:r1397921
  Merged /accumulo/branches/1.4/src/server:r1397921

Propchange: accumulo/trunk/src/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/src:r1397921
  Merged /accumulo/branches/1.4/src/src:r1397921



Mime
View raw message