accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [accumulo] branch 1.9 updated: fix #1309 prevent cloning accumulo.metadata (#1311)
Date Wed, 14 Aug 2019 20:06:31 GMT
This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch 1.9
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/1.9 by this push:
     new fa1d893  fix #1309 prevent cloning accumulo.metadata (#1311)
fa1d893 is described below

commit fa1d893f26f1f5e7974e02fc5757c5e2ff0a29df
Author: Keith Turner <kturner@apache.org>
AuthorDate: Wed Aug 14 16:06:26 2019 -0400

    fix #1309 prevent cloning accumulo.metadata (#1311)
---
 .../apache/accumulo/master/FateServiceHandler.java |  3 ++-
 .../accumulo/master/util/TableValidators.java      | 22 ++++++++++++++++++++++
 .../accumulo/test/functional/CloneTestIT.java      | 13 +++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
b/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
index c9b20cf..7949ac2 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.master;
 
+import static org.apache.accumulo.master.util.TableValidators.CAN_CLONE;
 import static org.apache.accumulo.master.util.TableValidators.NOT_METADATA;
 import static org.apache.accumulo.master.util.TableValidators.NOT_ROOT_ID;
 import static org.apache.accumulo.master.util.TableValidators.NOT_SYSTEM;
@@ -224,7 +225,7 @@ class FateServiceHandler implements FateService.Iface {
       case TABLE_CLONE: {
         TableOperation tableOp = TableOperation.CLONE;
         validateArgumentCount(arguments, tableOp, 2);
-        String srcTableId = validateTableIdArgument(arguments.get(0), tableOp, NOT_ROOT_ID);
+        String srcTableId = validateTableIdArgument(arguments.get(0), tableOp, CAN_CLONE);
         String tableName = validateTableNameArgument(arguments.get(1), tableOp, NOT_SYSTEM);
         String namespaceId;
         try {
diff --git a/server/master/src/main/java/org/apache/accumulo/master/util/TableValidators.java
b/server/master/src/main/java/org/apache/accumulo/master/util/TableValidators.java
index c6ef8c5..a9d3edb 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/util/TableValidators.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/util/TableValidators.java
@@ -79,6 +79,28 @@ public class TableValidators {
     }
   };
 
+  public static final Validator<String> CAN_CLONE = new Validator<String>() {
+
+    private List<String> metaIDs = Arrays.asList(RootTable.ID, MetadataTable.ID);
+
+    @Override
+    public boolean apply(String tableId) {
+      return !metaIDs.contains(tableId);
+    }
+
+    @Override
+    public String invalidMessage(String tableId) {
+      String msg;
+      if (tableId.equals(MetadataTable.ID)) {
+        msg = " Cloning " + MetadataTable.NAME
+            + " is dangerous and no longer supported, see https://github.com/apache/accumulo/issues/1309.";
+      } else {
+        msg = "Can not clone " + RootTable.NAME;
+      }
+      return msg;
+    }
+  };
+
   public static final Validator<String> NOT_SYSTEM = new Validator<String>()
{
 
     @Override
diff --git a/test/src/main/java/org/apache/accumulo/test/functional/CloneTestIT.java b/test/src/main/java/org/apache/accumulo/test/functional/CloneTestIT.java
index 74c6885..d76a28a 100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/CloneTestIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/CloneTestIT.java
@@ -33,6 +33,7 @@ import java.util.Set;
 import java.util.TreeSet;
 
 import org.apache.accumulo.cluster.AccumuloCluster;
+import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
 import org.apache.accumulo.core.client.Connector;
@@ -46,6 +47,7 @@ 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.metadata.MetadataTable;
+import org.apache.accumulo.core.metadata.RootTable;
 import org.apache.accumulo.core.metadata.schema.MetadataSchema;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.harness.AccumuloClusterHarness;
@@ -301,4 +303,15 @@ public class CloneTestIT extends AccumuloClusterHarness {
     assertEquals(rows, actualRows);
   }
 
+  @Test(expected = AccumuloException.class)
+  public void testCloneRootTable() throws Exception {
+    Connector conn = getConnector();
+    conn.tableOperations().clone(RootTable.NAME, "rc1", true, null, null);
+  }
+
+  @Test(expected = AccumuloException.class)
+  public void testCloneMetadataTable() throws Exception {
+    Connector conn = getConnector();
+    conn.tableOperations().clone(MetadataTable.NAME, "mc1", true, null, null);
+  }
 }


Mime
View raw message