accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [2/8] git commit: ACCUMULO-2094 Consolidate namespaceId addition with creating table
Date Thu, 26 Dec 2013 21:48:12 GMT
ACCUMULO-2094 Consolidate namespaceId addition with creating table

  Also clean up related initialize and upgrade code, and consolidate
  duplicate code.


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

Branch: refs/heads/master
Commit: 86f5927f1177730ab09e9e9c1df055639adadee3
Parents: 3cddee9
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Tue Dec 24 18:25:08 2013 -0500
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Tue Dec 24 18:25:08 2013 -0500

----------------------------------------------------------------------
 .../accumulo/core/client/impl/Namespaces.java   |  6 ++
 .../apache/accumulo/server/init/Initialize.java | 24 ++---
 .../accumulo/server/tables/TableManager.java    | 95 +++++---------------
 .../java/org/apache/accumulo/master/Master.java | 62 +++++--------
 .../master/tableOps/CreateNamespace.java        |  2 +-
 .../accumulo/master/tableOps/CreateTable.java   |  4 +-
 .../accumulo/master/tableOps/ImportTable.java   |  4 +-
 7 files changed, 58 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java
index 2480f68..64a6441 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java
@@ -58,6 +58,12 @@ public class Namespaces {
     return namespaceMap;
   }
 
+  public static boolean exists(Instance instance, String namespaceId) {
+    ZooCache zc = getZooCache(instance);
+    List<String> namespaceIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES);
+    return namespaceIds.contains(namespaceId);
+  }
+
   public static String getNamespaceId(Instance instance, String namespace) throws NamespaceNotFoundException
{
     String id = getNameToIdMap(instance).get(namespace);
     if (id == null)

http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
index a120dbd..7f5e44e 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
@@ -394,8 +394,11 @@ public class Initialize {
     String zkInstanceRoot = Constants.ZROOT + "/" + uuid;
     zoo.putPersistentData(zkInstanceRoot, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZTABLES, Constants.ZTABLES_INITIAL_ID,
NodeExistsPolicy.FAIL);
-    TableManager.prepareNewTableState(uuid, RootTable.ID, RootTable.NAME, TableState.ONLINE,
NodeExistsPolicy.FAIL);
-    TableManager.prepareNewTableState(uuid, MetadataTable.ID, MetadataTable.NAME, TableState.ONLINE,
NodeExistsPolicy.FAIL);
+    zoo.putPersistentData(zkInstanceRoot + Constants.ZNAMESPACES, new byte[0], NodeExistsPolicy.FAIL);
+    TableManager.prepareNewNamespaceState(uuid, Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_NAMESPACE,
NodeExistsPolicy.FAIL);
+    TableManager.prepareNewNamespaceState(uuid, Constants.ACCUMULO_NAMESPACE_ID, Constants.ACCUMULO_NAMESPACE,
NodeExistsPolicy.FAIL);
+    TableManager.prepareNewTableState(uuid, RootTable.ID, Constants.ACCUMULO_NAMESPACE_ID,
RootTable.NAME, TableState.ONLINE, NodeExistsPolicy.FAIL);
+    TableManager.prepareNewTableState(uuid, MetadataTable.ID, Constants.ACCUMULO_NAMESPACE_ID,
MetadataTable.NAME, TableState.ONLINE, NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZTSERVERS, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZPROBLEMS, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + RootTable.ZROOT_TABLET, new byte[0], NodeExistsPolicy.FAIL);
@@ -412,23 +415,6 @@ public class Initialize {
     zoo.putPersistentData(zkInstanceRoot + Constants.ZHDFS_RESERVATIONS, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZNEXT_FILE, new byte[] {'0'}, NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZRECOVERY, new byte[] {'0'}, NodeExistsPolicy.FAIL);
-    zoo.putPersistentData(zkInstanceRoot + Constants.ZNAMESPACES, new byte[0], NodeExistsPolicy.FAIL);
-    
-    createInitialNamespace(zoo, zkInstanceRoot, Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_NAMESPACE);
-    createInitialNamespace(zoo, zkInstanceRoot, Constants.ACCUMULO_NAMESPACE_ID, Constants.ACCUMULO_NAMESPACE);
-    
-    zoo.putPersistentData(zkInstanceRoot + Constants.ZTABLES + "/" + MetadataTable.ID + Constants.ZTABLE_NAMESPACE,
-        Constants.ACCUMULO_NAMESPACE_ID.getBytes(Constants.UTF8), NodeExistsPolicy.OVERWRITE);
-    zoo.putPersistentData(zkInstanceRoot + Constants.ZTABLES + "/" + RootTable.ID + Constants.ZTABLE_NAMESPACE,
-        Constants.ACCUMULO_NAMESPACE_ID.getBytes(Constants.UTF8), NodeExistsPolicy.OVERWRITE);
-  }
-  
-  private static void createInitialNamespace(IZooReaderWriter zoo, String root, String id,
String namespace) throws KeeperException,
-      InterruptedException {
-    String zPath = root + Constants.ZNAMESPACES + "/" + id;
-    zoo.putPersistentData(zPath, new byte[0], NodeExistsPolicy.FAIL);
-    zoo.putPersistentData(zPath + Constants.ZNAMESPACE_NAME, namespace.getBytes(Constants.UTF8),
NodeExistsPolicy.FAIL);
-    zoo.putPersistentData(zPath + Constants.ZNAMESPACE_CONF, new byte[0], NodeExistsPolicy.FAIL);
   }
 
   private static String getInstanceNamePath(Opts opts) throws IOException, KeeperException,
InterruptedException {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
b/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
index 8a5a682..0766a17 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
@@ -26,6 +26,7 @@ import java.util.Set;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.NamespaceNotFoundException;
 import org.apache.accumulo.core.client.impl.Tables;
 import org.apache.accumulo.core.master.state.tables.TableState;
 import org.apache.accumulo.core.util.Pair;
@@ -35,7 +36,6 @@ import org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
 import org.apache.accumulo.server.client.HdfsZooInstance;
-import org.apache.accumulo.server.util.NamespacePropUtil;
 import org.apache.accumulo.server.util.TablePropUtil;
 import org.apache.accumulo.server.zookeeper.ZooCache;
 import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
@@ -57,8 +57,19 @@ public class TableManager {
   private final Instance instance;
   private ZooCache zooStateCache;
 
-  public static void prepareNewTableState(String instanceId, String tableId, String tableName,
TableState state, NodeExistsPolicy existsPolicy)
-      throws KeeperException, InterruptedException {
+  public static void prepareNewNamespaceState(String instanceId, String namespaceId, String
namespace, NodeExistsPolicy existsPolicy) throws KeeperException,
+      InterruptedException {
+    // state gets created last
+    String zPath = Constants.ZROOT + "/" + instanceId + Constants.ZNAMESPACES + "/" + namespaceId;
+
+    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
+    zoo.putPersistentData(zPath, new byte[0], existsPolicy);
+    zoo.putPersistentData(zPath + Constants.ZNAMESPACE_NAME, namespace.getBytes(Constants.UTF8),
existsPolicy);
+    zoo.putPersistentData(zPath + Constants.ZNAMESPACE_CONF, new byte[0], existsPolicy);
+  }
+
+  public static void prepareNewTableState(String instanceId, String tableId, String namespaceId,
String tableName, TableState state,
+      NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException {
     // state gets created last
     Pair<String,String> qualifiedTableName = Tables.qualify(tableName);
     tableName = qualifiedTableName.getSecond();
@@ -66,12 +77,12 @@ public class TableManager {
     IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
     zoo.putPersistentData(zTablePath, new byte[0], existsPolicy);
     zoo.putPersistentData(zTablePath + Constants.ZTABLE_CONF, new byte[0], existsPolicy);
+    zoo.putPersistentData(zTablePath + Constants.ZTABLE_NAMESPACE, namespaceId.getBytes(Constants.UTF8),
existsPolicy);
     zoo.putPersistentData(zTablePath + Constants.ZTABLE_NAME, tableName.getBytes(Constants.UTF8),
existsPolicy);
     zoo.putPersistentData(zTablePath + Constants.ZTABLE_STATE, state.name().getBytes(Constants.UTF8),
existsPolicy);
     zoo.putPersistentData(zTablePath + Constants.ZTABLE_FLUSH_ID, "0".getBytes(Constants.UTF8),
existsPolicy);
     zoo.putPersistentData(zTablePath + Constants.ZTABLE_COMPACT_ID, "0".getBytes(Constants.UTF8),
existsPolicy);
     zoo.putPersistentData(zTablePath + Constants.ZTABLE_COMPACT_CANCEL_ID, "0".getBytes(Constants.UTF8),
existsPolicy);
-    zoo.putPersistentData(zTablePath + Constants.ZTABLE_NAMESPACE, qualifiedTableName.getFirst().getBytes(Constants.UTF8),
existsPolicy);
   }
 
   public synchronized static TableManager getInstance() {
@@ -180,17 +191,16 @@ public class TableManager {
     }
   }
 
-  public void addTable(String tableId, String tableName, NodeExistsPolicy existsPolicy) throws
KeeperException, InterruptedException {
-    prepareNewTableState(instance.getInstanceID(), tableId, tableName, TableState.NEW, existsPolicy);
+  public void addTable(String tableId, String namespaceId, String tableName, NodeExistsPolicy
existsPolicy) throws KeeperException, InterruptedException,
+      NamespaceNotFoundException {
+    prepareNewTableState(instance.getInstanceID(), tableId, namespaceId, tableName, TableState.NEW,
existsPolicy);
     updateTableStateCache(tableId);
   }
 
-  public void cloneTable(String srcTable, String tableId, String tableName, String namespaceId,
Map<String,String> propertiesToSet, Set<String> propertiesToExclude,
-      NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException {
-    prepareNewTableState(instance.getInstanceID(), tableId, tableName, TableState.NEW, existsPolicy);
-    
-    addNamespaceToTable(tableId, namespaceId);
-    
+  public void cloneTable(String srcTable, String tableId, String tableName, String namespaceId,
Map<String,String> propertiesToSet,
+      Set<String> propertiesToExclude, NodeExistsPolicy existsPolicy) throws KeeperException,
InterruptedException {
+    prepareNewTableState(instance.getInstanceID(), tableId, namespaceId, tableName, TableState.NEW,
existsPolicy);
+
     String srcTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES
+ "/" + srcTable + Constants.ZTABLE_CONF;
     String newTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES
+ "/" + tableId + Constants.ZTABLE_CONF;
     ZooReaderWriter.getRetryingInstance().recursiveCopyPersistent(srcTablePath, newTablePath,
NodeExistsPolicy.OVERWRITE);
@@ -299,69 +309,8 @@ public class TableManager {
     }
   }
 
-  public void addNamespace(String namespaceId, String namespace, NodeExistsPolicy existsPolicy)
throws KeeperException, InterruptedException {
-    // state gets created last
-    String zPath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZNAMESPACES
+ "/" + namespaceId;
-
-    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
-
-    zoo.putPersistentData(zPath, new byte[0], existsPolicy);
-    zoo.putPersistentData(zPath + Constants.ZNAMESPACE_NAME, namespace.getBytes(Constants.UTF8),
existsPolicy);
-    zoo.putPersistentData(zPath + Constants.ZNAMESPACE_CONF, new byte[0], existsPolicy);
-  }
-
   public void removeNamespace(String namespaceId) throws KeeperException, InterruptedException
{
     ZooReaderWriter.getRetryingInstance().recursiveDelete(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES
+ "/" + namespaceId, NodeMissingPolicy.SKIP);
   }
 
-  public void addNamespaceToTable(String tableId, String namespaceId) throws KeeperException,
InterruptedException {
-    String zPath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES +
"/" + tableId + Constants.ZTABLE_NAMESPACE;
-    ZooReaderWriter.getRetryingInstance().putPersistentData(zPath, namespaceId.getBytes(Constants.UTF8),
NodeExistsPolicy.OVERWRITE);
-  }
-
-  public void removeNamespaceFromTable(String tableId, String namespaceId) throws KeeperException,
InterruptedException {
-    // actually, revert it to the default namespace.
-    String zPath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES +
"/" + tableId + Constants.ZTABLE_NAMESPACE;
-    ZooReaderWriter.getRetryingInstance().putPersistentData(zPath, Constants.DEFAULT_NAMESPACE_ID.getBytes(Constants.UTF8),
NodeExistsPolicy.OVERWRITE);
-  }
-
-  public void cloneNamespace(String srcId, String newId, String namespaceName, Map<String,String>
propertiesToSet, Set<String> propertiesToExclude,
-      NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException {
-    String srcPath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZNAMESPACES
+ "/" + srcId + Constants.ZNAMESPACE_CONF;
-    String newPath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZNAMESPACES
+ "/" + newId + Constants.ZNAMESPACE_CONF;
-    ZooReaderWriter.getRetryingInstance().recursiveCopyPersistent(srcPath, newPath, NodeExistsPolicy.OVERWRITE);
-
-    for (Entry<String,String> entry : propertiesToSet.entrySet())
-      NamespacePropUtil.setNamespaceProperty(newId, entry.getKey(), entry.getValue());
-
-    for (String prop : propertiesToExclude)
-      ZooReaderWriter.getRetryingInstance().recursiveDelete(
-          Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZNAMESPACES + "/"
+ newId + Constants.ZNAMESPACE_CONF + "/" + prop,
-          NodeMissingPolicy.SKIP);
-  }
-
-  /*
-   * private static boolean verifyTabletAssignments(String tableId) { log.info( "Sending
message to load balancer to verify assignment of tablets with tableId="
-   * + tableId); // Return true only if transitions to other states did not interrupt //
this process. (like deleting the table) return true; }
-   * 
-   * private static synchronized boolean unloadTable(String tableId) { int loadedTabletCount
= 0; while (loadedTabletCount > 0) { // wait for tables to be
-   * unloaded } log.info("Table unloaded. tableId=" + tableId); return true; }
-   * 
-   * private static void cleanupDeletedTable(String tableId) { log.info("Sending message
to cleanup the deleted table with tableId=" + tableId); }
-   * 
-   * switch (tState) { case NEW: // this should really only happen before the watcher //
knows about the table log.error("Unexpected transition to " + tState +
-   * " @ " + event); break;
-   * 
-   * case LOADING: // a table has started coming online or has pending // migrations (maybe?)
if (verifyTabletAssignments(tableId))
-   * TableState.transition(instance, tableId, TableState.ONLINE); break; case ONLINE: log.trace("Table
online with tableId=" + tableId); break;
-   * 
-   * case DISABLING: if (unloadTable(tableId)) TableState.transition(instance, tableId, TableState.DISABLED);
break; case DISABLED:
-   * log.trace("Table disabled with tableId=" + tableId); break;
-   * 
-   * case UNLOADING: unloadTable(tableId); TableState.transition(instance, tableId, TableState.OFFLINE);
case OFFLINE: break;
-   * 
-   * case DELETING: unloadTable(tableId); cleanupDeletedTable(tableId); break;
-   * 
-   * default: log.error("Unrecognized transition to " + tState + " @ " + event); }
-   */
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/server/master/src/main/java/org/apache/accumulo/master/Master.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/Master.java b/server/master/src/main/java/org/apache/accumulo/master/Master.java
index bd6ee27..65d6030 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/Master.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/Master.java
@@ -316,56 +316,38 @@ public class Master implements LiveTServerSet.Listener, TableObserver,
CurrentSt
 
         IZooReaderWriter zoo = ZooReaderWriter.getInstance();
 
+        // create initial namespaces
+        String namespaces = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES;
+        zoo.putPersistentData(namespaces, new byte[0], NodeExistsPolicy.SKIP);
+        if (!Namespaces.exists(instance, Constants.ACCUMULO_NAMESPACE_ID))
+          TableManager.prepareNewNamespaceState(instance.getInstanceID(), Constants.ACCUMULO_NAMESPACE_ID,
Constants.ACCUMULO_NAMESPACE, NodeExistsPolicy.SKIP);
+        if (!Namespaces.exists(instance, Constants.DEFAULT_NAMESPACE_ID))
+          TableManager.prepareNewNamespaceState(instance.getInstanceID(), Constants.DEFAULT_NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE, NodeExistsPolicy.SKIP);
+
+        // create root table
         if (!Tables.exists(instance, RootTable.ID)) {
-          TableManager.prepareNewTableState(instance.getInstanceID(), RootTable.ID, RootTable.NAME,
TableState.ONLINE, NodeExistsPolicy.SKIP);
+          TableManager.prepareNewTableState(instance.getInstanceID(), RootTable.ID, Constants.ACCUMULO_NAMESPACE_ID,
RootTable.NAME, TableState.ONLINE,
+              NodeExistsPolicy.SKIP);
           Initialize.initMetadataConfig(RootTable.ID);
           // ensure root user can flush root table
           security.grantTablePermission(SystemCredentials.get().toThrift(instance), security.getRootUsername(),
RootTable.ID, TablePermission.ALTER_TABLE);
         }
 
-        moveRootTabletToRootTable(zoo);
-
-        zoo.recursiveDelete(ZooUtil.getRoot(instance) + "/loggers", NodeMissingPolicy.SKIP);
-        zoo.recursiveDelete(ZooUtil.getRoot(instance) + "/dead/loggers", NodeMissingPolicy.SKIP);
-        zoo.putPersistentData(ZooUtil.getRoot(instance) + Constants.ZRECOVERY, new byte[]
{'0'}, NodeExistsPolicy.SKIP);
-
-        for (String id : Tables.getIdToNameMap(instance).keySet()) {
-
-          zoo.putPersistentData(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + id
+ Constants.ZTABLE_COMPACT_CANCEL_ID, "0".getBytes(),
-              NodeExistsPolicy.SKIP);
-        }
-
-        // setup default and system namespaces if not already there
-        String namespaces = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES;
-        String defaultNamespace = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/"
+ Constants.DEFAULT_NAMESPACE_ID;
-        String systemNamespace = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/"
+ Constants.ACCUMULO_NAMESPACE_ID;
+        // put existing tables in the correct namespaces
         String tables = ZooUtil.getRoot(instance) + Constants.ZTABLES;
-        zoo.putPersistentData(namespaces, new byte[0], NodeExistsPolicy.SKIP);
-
-        zoo.putPersistentData(defaultNamespace, new byte[0], NodeExistsPolicy.SKIP);
-        zoo.putPersistentData(defaultNamespace + Constants.ZNAMESPACE_CONF, new byte[0],
NodeExistsPolicy.SKIP);
-        zoo.putPersistentData(defaultNamespace + Constants.ZNAMESPACE_NAME, Constants.DEFAULT_NAMESPACE.getBytes(Constants.UTF8),
NodeExistsPolicy.SKIP);
-
-        zoo.putPersistentData(systemNamespace, new byte[0], NodeExistsPolicy.SKIP);
-        zoo.putPersistentData(systemNamespace + Constants.ZNAMESPACE_CONF, new byte[0], NodeExistsPolicy.SKIP);
-        zoo.putPersistentData(systemNamespace + Constants.ZNAMESPACE_NAME, Constants.ACCUMULO_NAMESPACE.getBytes(Constants.UTF8),
NodeExistsPolicy.SKIP);
-
-        Map<String,String> opts = IteratorUtil.generateInitialTableProperties(true);
-        for (Entry<String,String> e : opts.entrySet()) {
-          zoo.putPersistentData(defaultNamespace + Constants.ZNAMESPACE_CONF + "/" + e.getKey(),
e.getValue().getBytes(Constants.UTF8), NodeExistsPolicy.SKIP);
-        }
-
         for (Entry<String,String> table : Tables.getIdToNameMap(instance).entrySet())
{
-          if (table.getValue().equals(MetadataTable.NAME) || table.getValue().equals(RootTable.NAME))
{
-            zoo.putPersistentData(tables + "/" + table.getKey() + Constants.ZTABLE_NAMESPACE,
Constants.ACCUMULO_NAMESPACE_ID.getBytes(Constants.UTF8),
-                NodeExistsPolicy.SKIP);
-          } else {
-            zoo.putPersistentData(tables + "/" + table.getKey() + Constants.ZTABLE_NAMESPACE,
Constants.DEFAULT_NAMESPACE_ID.getBytes(Constants.UTF8),
-                NodeExistsPolicy.SKIP);
-          }
+          String targetNamespace = (MetadataTable.ID.equals(table.getKey()) || RootTable.ID.equals(table.getKey()))
? Constants.ACCUMULO_NAMESPACE_ID
+              : Constants.DEFAULT_NAMESPACE_ID;
+          zoo.putPersistentData(tables + "/" + table.getKey() + Constants.ZTABLE_NAMESPACE,
targetNamespace.getBytes(Constants.UTF8), NodeExistsPolicy.SKIP);
         }
 
-        // add namespace permissions to existing users
+        // rename metadata table
+        zoo.putPersistentData(tables + "/" + MetadataTable.ID + Constants.ZTABLE_NAME, Tables.qualify(MetadataTable.NAME).getSecond().getBytes(Constants.UTF8),
+            NodeExistsPolicy.OVERWRITE);
+
+        moveRootTabletToRootTable(zoo);
+
+        // add system namespace permissions to existing users
         ZKPermHandler perm = new ZKPermHandler();
         perm.initialize(instance.getInstanceID(), true);
         String users = ZooUtil.getRoot(instance) + "/users";

http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateNamespace.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateNamespace.java
b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateNamespace.java
index fac0cb2..8d0aa26 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateNamespace.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateNamespace.java
@@ -107,7 +107,7 @@ class PopulateZookeeperWithNamespace extends MasterRepo {
 
       Utils.checkNamespaceDoesNotExist(instance, namespaceInfo.namespaceName, namespaceInfo.namespaceId,
TableOperation.CREATE);
 
-      TableManager.getInstance().addNamespace(namespaceInfo.namespaceId, namespaceInfo.namespaceName,
NodeExistsPolicy.OVERWRITE);
+      TableManager.prepareNewNamespaceState(instance.getInstanceID(), namespaceInfo.namespaceId,
namespaceInfo.namespaceName, NodeExistsPolicy.OVERWRITE);
 
       for (Entry<String,String> entry : namespaceInfo.props.entrySet())
         NamespacePropUtil.setNamespaceProperty(namespaceInfo.namespaceId, entry.getKey(),
entry.getValue());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/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 671bf23..9535781 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
@@ -215,9 +215,7 @@ class PopulateZookeeper extends MasterRepo {
 
       Utils.checkTableDoesNotExist(instance, tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE);
 
-      TableManager.getInstance().addTable(tableInfo.tableId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE);
-
-      TableManager.getInstance().addNamespaceToTable(tableInfo.tableId, tableInfo.namespaceId);
+      TableManager.getInstance().addTable(tableInfo.tableId, tableInfo.namespaceId, tableInfo.tableName,
NodeExistsPolicy.OVERWRITE);
 
       for (Entry<String,String> entry : tableInfo.props.entrySet())
         TablePropUtil.setTableProperty(tableInfo.tableId, entry.getKey(), entry.getValue());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/86f5927f/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java
b/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java
index 5ddf129..9f35628 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java
@@ -447,11 +447,9 @@ class ImportPopulateZookeeper extends MasterRepo {
 
       Utils.checkTableDoesNotExist(instance, tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE);
 
-      TableManager.getInstance().addTable(tableInfo.tableId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE);
-
       String namespace = Tables.qualify(tableInfo.tableName).getFirst();
       String namespaceId = Namespaces.getNamespaceId(instance, namespace);
-      TableManager.getInstance().addNamespaceToTable(tableInfo.tableId, namespaceId);
+      TableManager.getInstance().addTable(tableInfo.tableId, namespaceId, tableInfo.tableName,
NodeExistsPolicy.OVERWRITE);
 
       Tables.clearCache(instance);
     } finally {


Mime
View raw message