accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [31/54] git commit: ACCUMULO-802 added the proper namespace locks during table fate operations
Date Fri, 01 Nov 2013 02:00:32 GMT
ACCUMULO-802 added the proper namespace locks during table fate operations


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

Branch: refs/heads/ACCUMULO-802
Commit: dabf6b41b265d2f25a31556a7944529f3c6d6b51
Parents: 1665c84
Author: Sean Hickey <tallirishllama@gmail.com>
Authored: Tue Aug 6 14:15:39 2013 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Thu Oct 31 21:30:39 2013 -0400

----------------------------------------------------------------------
 .../client/admin/TableNamespaceOperations.java  |  9 +++++--
 .../admin/TableNamespaceOperationsImpl.java     | 15 ++++++------
 .../mock/MockTableNamespaceOperations.java      | 10 +++-----
 .../accumulo/master/tableOps/CloneTable.java    | 25 +++++++++++++++-----
 .../accumulo/master/tableOps/CreateTable.java   | 13 +++++-----
 .../accumulo/master/tableOps/DeleteTable.java   | 15 ++++++++----
 .../accumulo/master/tableOps/RenameTable.java   | 11 +++++++--
 7 files changed, 63 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
index 314d007..33f9dc0 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
@@ -29,6 +29,7 @@ import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.TableNamespaceExistsException;
 import org.apache.accumulo.core.client.TableNamespaceNotEmptyException;
 import org.apache.accumulo.core.client.TableNamespaceNotFoundException;
+import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
 
 /**
@@ -112,8 +113,10 @@ public interface TableNamespaceOperations {
    *           if the table namespace does not exist
    * @throws TableNamespaceNotEmptyException
    *           if the table namespaces still contains tables
+   * @throws TableNotFoundException 
+   *           if table not found while deleting
    */
-  public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException, TableNamespaceNotEmptyException;
+  public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException, TableNamespaceNotEmptyException, TableNotFoundException;
   
   /**
    * Delete a table namespace
@@ -130,9 +133,11 @@ public interface TableNamespaceOperations {
    *           if the table namespace does not exist
    * @throws TableNamespaceNotEmptyException
    *           if the table namespaces still contains tables
+   * @throws TableNotFoundException 
+   *           if table not found while deleting
    */
   public void delete(String namespace, boolean deleteTables) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException,
-      TableNamespaceNotEmptyException;
+      TableNamespaceNotEmptyException, TableNotFoundException;
   
   /**
    * Rename a table namespace

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
index 90d59af..d4a1d1c 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
@@ -297,9 +297,11 @@ public class TableNamespaceOperationsImpl extends TableNamespaceOperationsHelper
    *           if the table namespace does not exist
    * @throws TableNamespaceNotEmptyException
    *           if the table namespaces still contains tables
+   * @throws TableNotFoundException 
+   *           if table not found while deleting
    */
   @Override
-  public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException, TableNamespaceNotEmptyException {
+  public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException, TableNamespaceNotEmptyException, TableNotFoundException {
     delete(namespace, false);
   }
 
@@ -317,10 +319,13 @@ public class TableNamespaceOperationsImpl extends TableNamespaceOperationsHelper
    * @throws TableNamespaceNotFoundException
    *           if the table namespace does not exist
    * @throws TableNamespaceNotEmptyException
+   *           if the table namespaces still contains tables
+   * @throws TableNotFoundException 
+   *           if table not found while deleting
    */
   @Override
   public void delete(String namespace, boolean deleteTables) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException,
-      TableNamespaceNotEmptyException {
+      TableNamespaceNotEmptyException, TableNotFoundException {
     ArgumentChecker.notNull(namespace);
     String namespaceId = TableNamespaces.getNamespaceId(instance, namespace);
 
@@ -334,11 +339,7 @@ public class TableNamespaceOperationsImpl extends TableNamespaceOperationsHelper
         throw new TableNamespaceNotEmptyException(namespaceId, namespace, null);
       }
       for (String table : TableNamespaces.getTableNames(instance, namespaceId)) {
-        try {
-          getTableOperations().delete(table);
-        } catch (TableNotFoundException e) {
-          throw new RuntimeException("Table (" + table + ") was found in ZooKeeper, but now
doesn't exist. (while deleting namespace)");
-        }
+        getTableOperations().delete(table);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
index 28f2edc..5b53fbd 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
@@ -88,13 +88,13 @@ public class MockTableNamespaceOperations extends TableNamespaceOperationsHelper
   }
 
   @Override
-  public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException, TableNamespaceNotEmptyException {
+  public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException, TableNamespaceNotEmptyException, TableNotFoundException {
     delete(namespace, false);
   }
 
   @Override
   public void delete(String namespace, boolean deleteTables) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException,
-      TableNamespaceNotEmptyException {
+      TableNamespaceNotEmptyException, TableNotFoundException {
     if (!exists(namespace))
       throw new TableNamespaceNotFoundException(namespace, namespace, "");
 
@@ -105,11 +105,7 @@ public class MockTableNamespaceOperations extends TableNamespaceOperationsHelper
       }
     } else {
       for (String t : n.getTables(acu)) {
-        try {
-          new MockTableOperations(acu, username).delete(t);
-        } catch (TableNotFoundException e) {
-          System.err.println("Table (" + e.getTableName() + ") not found while deleting namespace
(" + namespace + ")");
-        }
+        new MockTableOperations(acu, username).delete(t);
       }
     }
     acu.namespaces.remove(namespace);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTable.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTable.java
b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTable.java
index 3841463..31e5e3e 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTable.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTable.java
@@ -44,6 +44,8 @@ class CloneInfo implements Serializable {
   String srcTableId;
   String tableName;
   String tableId;
+  String namespaceId;
+  String srcNamespaceId;
   Map<String,String> propertiesToSet;
   Set<String> propertiesToExclude;
   
@@ -75,6 +77,9 @@ class FinishCloneTable extends MasterRepo {
     
     Utils.unreserveTable(cloneInfo.srcTableId, tid, false);
     Utils.unreserveTable(cloneInfo.tableId, tid, true);
+    Utils.unreserveTableNamespace(cloneInfo.srcNamespaceId, tid, false);
+    if (!cloneInfo.namespaceId.equals(cloneInfo.srcNamespaceId))
+      Utils.unreserveTableNamespace(cloneInfo.namespaceId, tid, false);
     
     environment.getEventCoordinator().event("Cloned table %s from %s", cloneInfo.tableName,
cloneInfo.srcTableId);
     
@@ -133,7 +138,11 @@ class CloneZookeeper extends MasterRepo {
   
   @Override
   public long isReady(long tid, Master environment) throws Exception {
-    return Utils.reserveTable(cloneInfo.tableId, tid, true, false, TableOperation.CLONE);
+    cloneInfo.namespaceId = TableNamespaces.getNamespaceId(environment.getInstance(), Tables.extractNamespace(cloneInfo.tableName));
+    long val = Utils.reserveTable(cloneInfo.tableId, tid, true, false, TableOperation.CLONE);
+    if (!cloneInfo.srcNamespaceId.equals(cloneInfo.namespaceId)) 
+      val += Utils.reserveTableNamespace(cloneInfo.namespaceId, tid, false, true, TableOperation.CLONE);
+    return val;
   }
   
   @Override
@@ -148,10 +157,8 @@ class CloneZookeeper extends MasterRepo {
       TableManager.getInstance().cloneTable(cloneInfo.srcTableId, cloneInfo.tableId, cloneInfo.tableName,
cloneInfo.propertiesToSet,
           cloneInfo.propertiesToExclude, NodeExistsPolicy.OVERWRITE);
       Tables.clearCache(instance);
-      
-      String namespace = Tables.extractNamespace(cloneInfo.tableName);
-      String namespaceId = TableNamespaces.getNamespaceId(instance, namespace);
-      TableManager.getInstance().addNamespaceToTable(cloneInfo.tableId, namespaceId);
+
+      TableManager.getInstance().addNamespaceToTable(cloneInfo.tableId, cloneInfo.namespaceId);
       
       return new CloneMetadata(cloneInfo);
     } finally {
@@ -164,6 +171,8 @@ class CloneZookeeper extends MasterRepo {
     Instance instance = HdfsZooInstance.getInstance();
     TableManager.getInstance().removeTable(cloneInfo.tableId);
     Utils.unreserveTable(cloneInfo.tableId, tid, true);
+    if (!cloneInfo.namespaceId.equals(cloneInfo.srcNamespaceId)) 
+      Utils.unreserveTableNamespace(cloneInfo.namespaceId, tid, false);
     Tables.clearCache(instance);
   }
   
@@ -225,7 +234,10 @@ public class CloneTable extends MasterRepo {
   
   @Override
   public long isReady(long tid, Master environment) throws Exception {
-    return Utils.reserveTable(cloneInfo.srcTableId, tid, false, true, TableOperation.CLONE);
+    cloneInfo.srcNamespaceId = Tables.getNamespace(environment.getInstance(), cloneInfo.srcTableId);
+    long val = Utils.reserveTable(cloneInfo.srcTableId, tid, false, true, TableOperation.CLONE);
+    val += Utils.reserveTableNamespace(cloneInfo.srcNamespaceId, tid, false, true, TableOperation.CLONE);
+    return val;
   }
   
   @Override
@@ -244,6 +256,7 @@ public class CloneTable extends MasterRepo {
   @Override
   public void undo(long tid, Master environment) throws Exception {
     Utils.unreserveTable(cloneInfo.srcTableId, tid, false);
+    Utils.unreserveTableNamespace(cloneInfo.srcNamespaceId, tid, false);
   }
   
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateTable.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateTable.java
b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateTable.java
index d425fe8..a2c0344 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateTable.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateTable.java
@@ -52,6 +52,7 @@ class TableInfo implements Serializable {
   
   String tableName;
   String tableId;
+  String namespaceId;
   char timeType;
   String user;
   
@@ -80,6 +81,7 @@ class FinishCreateTable extends MasterRepo {
     TableManager.getInstance().transitionTableState(tableInfo.tableId, TableState.ONLINE);
     
     Utils.unreserveTable(tableInfo.tableId, tid, true);
+    Utils.unreserveTableNamespace(tableInfo.namespaceId, tid, false);
     
     env.getEventCoordinator().event("Created table %s ", tableInfo.tableName);
     
@@ -213,10 +215,7 @@ class PopulateZookeeper extends MasterRepo {
       
       TableManager.getInstance().addTable(tableInfo.tableId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE);
       
-      String namespace = Tables.extractNamespace(tableInfo.tableName);
-      String namespaceId = TableNamespaces.getNamespaceId(instance, namespace);
-      
-      TableManager.getInstance().addNamespaceToTable(tableInfo.tableId, namespaceId);
+      TableManager.getInstance().addNamespaceToTable(tableInfo.tableId, tableInfo.namespaceId);
       
       for (Entry<String,String> entry : tableInfo.props.entrySet())
         TablePropUtil.setTableProperty(tableInfo.tableId, entry.getKey(), entry.getValue());
@@ -290,7 +289,9 @@ public class CreateTable extends MasterRepo {
   
   @Override
   public long isReady(long tid, Master environment) throws Exception {
-    return 0;
+    // reserve the table's namespace to make sure it doesn't change while the table is created
+    tableInfo.namespaceId = TableNamespaces.getNamespaceId(environment.getInstance(), Tables.extractNamespace(tableInfo.tableName));
+    return Utils.reserveTableNamespace(tableInfo.namespaceId, tid, false, false, TableOperation.CREATE);
   }
   
   @Override
@@ -313,7 +314,7 @@ public class CreateTable extends MasterRepo {
   
   @Override
   public void undo(long tid, Master env) throws Exception {
-    // nothing to do, the table id was allocated!
+    Utils.unreserveTableNamespace(tableInfo.namespaceId, tid, false);
   }
   
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/server/master/src/main/java/org/apache/accumulo/master/tableOps/DeleteTable.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/DeleteTable.java
b/server/master/src/main/java/org/apache/accumulo/master/tableOps/DeleteTable.java
index 4271257..439d0c2 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/DeleteTable.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/DeleteTable.java
@@ -59,7 +59,7 @@ class CleanUp extends MasterRepo {
   
   private static final long serialVersionUID = 1L;
   
-  private String tableId;
+  private String tableId, namespaceId;
   
   private long creationTime;
   
@@ -77,8 +77,9 @@ class CleanUp extends MasterRepo {
     
   }
   
-  public CleanUp(String tableId) {
+  public CleanUp(String tableId, String namespaceId) {
     this.tableId = tableId;
+    this.namespaceId = namespaceId;
     creationTime = System.currentTimeMillis();
   }
   
@@ -199,6 +200,7 @@ class CleanUp extends MasterRepo {
     }
     
     Utils.unreserveTable(tableId, tid, true);
+    Utils.unreserveTableNamespace(namespaceId, tid, false);
     
     Logger.getLogger(CleanUp.class).debug("Deleted table " + tableId);
     
@@ -216,7 +218,7 @@ public class DeleteTable extends MasterRepo {
   
   private static final long serialVersionUID = 1L;
   
-  private String tableId;
+  private String tableId, namespaceId;
   
   public DeleteTable(String tableId) {
     this.tableId = tableId;
@@ -224,19 +226,22 @@ public class DeleteTable extends MasterRepo {
   
   @Override
   public long isReady(long tid, Master environment) throws Exception {
-    return Utils.reserveTable(tableId, tid, true, true, TableOperation.DELETE);
+    this.namespaceId = Tables.getNamespace(environment.getInstance(), tableId);
+    return Utils.reserveTable(tableId, tid, true, true, TableOperation.DELETE)
+        + Utils.reserveTableNamespace(namespaceId, tid, false, false, TableOperation.CREATE);
   }
   
   @Override
   public Repo<Master> call(long tid, Master environment) throws Exception {
     TableManager.getInstance().transitionTableState(tableId, TableState.DELETING);
     environment.getEventCoordinator().event("deleting table %s ", tableId);
-    return new CleanUp(tableId);
+    return new CleanUp(tableId, namespaceId);
   }
   
   @Override
   public void undo(long tid, Master environment) throws Exception {
     Utils.unreserveTable(tableId, tid, true);
+    Utils.unreserveTableNamespace(namespaceId, tid, false);
   }
   
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dabf6b41/server/master/src/main/java/org/apache/accumulo/master/tableOps/RenameTable.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/RenameTable.java
b/server/master/src/main/java/org/apache/accumulo/master/tableOps/RenameTable.java
index aa0886b..a58b847 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/RenameTable.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/RenameTable.java
@@ -38,10 +38,13 @@ public class RenameTable extends MasterRepo {
   private String tableId;
   private String oldTableName;
   private String newTableName;
+  private String namespaceId;
 
   @Override
   public long isReady(long tid, Master environment) throws Exception {
-    return Utils.reserveTable(tableId, tid, true, true, TableOperation.RENAME);
+    this.namespaceId = Tables.getNamespace(environment.getInstance(), tableId);
+    return Utils.reserveTable(tableId, tid, true, true, TableOperation.RENAME)
+        + Utils.reserveTableNamespace(namespaceId, tid, false, true, TableOperation.RENAME);
   }
 
   public RenameTable(String tableId, String oldTableName, String newTableName) {
@@ -63,12 +66,14 @@ public class RenameTable extends MasterRepo {
     if (!namespaceId.equals(oldNamespaceId)) {
       TableManager tm = TableManager.getInstance();
       tm.addNamespaceToTable(tableId, namespaceId);
-      // TODO change parent of table's configuration to new namespace...somehow...
     }
 
     newTableName = Tables.extractTableName(newTableName);
     oldTableName = Tables.extractTableName(oldTableName);
 
+    // TODO ACCUMULO-802 renaming a table to a new namespace does not change it's parent
configuration to be the new namespace
+    // ...it should...somehow...
+
     IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
 
     Utils.tableNameLock.lock();
@@ -94,6 +99,7 @@ public class RenameTable extends MasterRepo {
     } finally {
       Utils.tableNameLock.unlock();
       Utils.unreserveTable(tableId, tid, true);
+      Utils.unreserveTableNamespace(namespaceId, tid, false);
     }
 
     Logger.getLogger(RenameTable.class).debug("Renamed table " + tableId + " " + oldTableName
+ " " + newTableName);
@@ -104,6 +110,7 @@ public class RenameTable extends MasterRepo {
   @Override
   public void undo(long tid, Master env) throws Exception {
     Utils.unreserveTable(tableId, tid, true);
+    Utils.unreserveTableNamespace(namespaceId, tid, false);
   }
 
 }


Mime
View raw message