Changing the location of the layout information so that when the table is 
removed from Blur the layout is automatically removed.


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

Branch: refs/heads/apache-blur-0.2
Commit: c47af820ebcb0a3de0012a471e3b0058f06b7db5
Parents: a7311fc
Author: Aaron McCurry <[email protected]>
Authored: Sun Feb 16 08:46:13 2014 -0500
Committer: Aaron McCurry <[email protected]>
Committed: Sun Feb 16 08:46:13 2014 -0500

----------------------------------------------------------------------
 .../clusterstatus/ZookeeperClusterStatus.java   |  4 ---
 .../indexserver/DistributedIndexServer.java     |  9 +++---
 .../MasterBasedDistributedLayoutFactory.java    | 32 +++++++-------------
 .../org/apache/blur/server/TableContext.java    |  5 +++
 .../java/org/apache/blur/thrift/TableAdmin.java |  8 ++---
 5 files changed, 24 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c47af820/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
----------------------------------------------------------------------
diff --git 
a/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
 
b/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
index 64ee9a0..c55f174 100644
--- 
a/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
+++ 
b/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
@@ -35,7 +35,6 @@ import org.apache.blur.BlurConfiguration;
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
 import org.apache.blur.lucene.search.FairSimilarity;
-import org.apache.blur.manager.indexserver.MasterBasedDistributedLayoutFactory;
 import org.apache.blur.thirdparty.thrift_0_9_0.TDeserializer;
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thirdparty.thrift_0_9_0.TSerializer;
@@ -635,12 +634,9 @@ public class ZookeeperClusterStatus extends ClusterStatus {
       }
       String uri = tableDescriptor.getTableUri();
       BlurUtil.removeAll(_zk, blurTablePath);
-      MasterBasedDistributedLayoutFactory.removeTable(_zk,
-          ZookeeperPathConstants.getShardLayoutPathTableLayout(cluster), 
table);
       if (deleteIndexFiles) {
         BlurUtil.removeIndexFiles(uri);
       }
-
     } catch (IOException e) {
       throw new RuntimeException(e);
     } catch (InterruptedException e) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c47af820/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java
----------------------------------------------------------------------
diff --git 
a/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java
 
b/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java
index 53528bc..9f4fd20 100644
--- 
a/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java
+++ 
b/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java
@@ -184,7 +184,7 @@ public class DistributedIndexServer extends 
AbstractDistributedIndexServer {
       closeAllIndexes();
       _timerCacheFlush.purge();
       _timerCacheFlush.cancel();
-
+      _watchOnlineShards.close();
       _timerTableWarmer.purge();
       _timerTableWarmer.cancel();
     }
@@ -405,9 +405,9 @@ public class DistributedIndexServer extends 
AbstractDistributedIndexServer {
               closed = true;
             }
           }
-        }
-        if (closed) {
-          TableContext.clear();
+          if (closed) {
+            TableContext.clear(table);
+          }
         }
       }
     }, _delay, _delay);
@@ -482,7 +482,6 @@ public class DistributedIndexServer extends 
AbstractDistributedIndexServer {
 
     ShardContext shardContext = ShardContext.create(tableContext, shard);
 
-
     TableDescriptor descriptor = tableContext.getDescriptor();
     boolean blockCacheEnabled = descriptor.isBlockCaching();
     if (blockCacheEnabled) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c47af820/blur-core/src/main/java/org/apache/blur/manager/indexserver/MasterBasedDistributedLayoutFactory.java
----------------------------------------------------------------------
diff --git 
a/blur-core/src/main/java/org/apache/blur/manager/indexserver/MasterBasedDistributedLayoutFactory.java
 
b/blur-core/src/main/java/org/apache/blur/manager/indexserver/MasterBasedDistributedLayoutFactory.java
index b9528b9..7a44173 100644
--- 
a/blur-core/src/main/java/org/apache/blur/manager/indexserver/MasterBasedDistributedLayoutFactory.java
+++ 
b/blur-core/src/main/java/org/apache/blur/manager/indexserver/MasterBasedDistributedLayoutFactory.java
@@ -56,7 +56,6 @@ public class MasterBasedDistributedLayoutFactory implements 
DistributedLayoutFac
   private final ZooKeeper _zooKeeper;
   private final String _storagePath;
   private final ZooKeeperLockManager _zooKeeperLockManager;
-  private final String _tableStoragePath;
   private final String _locksStoragePath;
   private final ThreadLocal<Random> _random = new ThreadLocal<Random>() {
     @Override
@@ -64,14 +63,14 @@ public class MasterBasedDistributedLayoutFactory implements 
DistributedLayoutFac
       return new Random();
     }
   };
+  private final String _cluster;
 
   public MasterBasedDistributedLayoutFactory(ZooKeeper zooKeeper, String 
cluster) {
     _zooKeeper = zooKeeper;
+    _cluster = cluster;
     _storagePath = ZookeeperPathConstants.getShardLayoutPath(cluster);
-    _tableStoragePath = 
ZookeeperPathConstants.getShardLayoutPathTableLayout(cluster);
     _locksStoragePath = 
ZookeeperPathConstants.getShardLayoutPathLocks(cluster);
     ZkUtils.mkNodesStr(_zooKeeper, _storagePath);
-    ZkUtils.mkNodesStr(_zooKeeper, _tableStoragePath);
     ZkUtils.mkNodesStr(_zooKeeper, _locksStoragePath);
     _zooKeeperLockManager = new ZooKeeperLockManager(_zooKeeper, 
_locksStoragePath);
   }
@@ -175,26 +174,14 @@ public class MasterBasedDistributedLayoutFactory 
implements DistributedLayoutFac
     }
   }
 
-  public static void removeTable(ZooKeeper zooKeeper, String tableStoragePath, 
String table) throws InterruptedException, KeeperException {
-    List<String> children = new 
ArrayList<String>(zooKeeper.getChildren(tableStoragePath, false));
-    for (String child : children) {
-      int index = child.lastIndexOf(SEP);
-      if (index >= 0) {
-        if (child.substring(0, index).equals(table)) {
-          String oldPath = tableStoragePath + "/" + child;
-          zooKeeper.delete(oldPath, -1);
-        }
-      }
-    }
-  }
-
   private void cleanupOldTableLayouts(String table, String newPath) throws 
KeeperException, InterruptedException {
-    List<String> children = new 
ArrayList<String>(_zooKeeper.getChildren(_tableStoragePath, false));
+    String tableStoragePath = ZookeeperPathConstants.getTablePath(_cluster, 
table);
+    List<String> children = new 
ArrayList<String>(_zooKeeper.getChildren(tableStoragePath, false));
     for (String child : children) {
       int index = child.lastIndexOf(SEP);
       if (index >= 0) {
         if (child.substring(0, index).equals(table)) {
-          String oldPath = _tableStoragePath + "/" + child;
+          String oldPath = tableStoragePath + "/" + child;
           if (!oldPath.equals(newPath)) {
             LOG.info("Cleaning up old layouts for table [{0}]", table);
             _zooKeeper.delete(oldPath, -1);
@@ -205,7 +192,9 @@ public class MasterBasedDistributedLayoutFactory implements 
DistributedLayoutFac
   }
 
   private String findExistingStoragePath(String table) throws KeeperException, 
InterruptedException {
-    List<String> children = new 
ArrayList<String>(_zooKeeper.getChildren(_tableStoragePath, false));
+    String tableStoragePath = ZookeeperPathConstants.getTablePath(_cluster, 
table);
+    ZkUtils.mkNodesStr(_zooKeeper, tableStoragePath);
+    List<String> children = new 
ArrayList<String>(_zooKeeper.getChildren(tableStoragePath, false));
     String path = null;
     for (String child : children) {
       int index = child.lastIndexOf(SEP);
@@ -217,7 +206,7 @@ public class MasterBasedDistributedLayoutFactory implements 
DistributedLayoutFac
         }
       }
     }
-    return _tableStoragePath + "/" + path;
+    return tableStoragePath + "/" + path;
   }
 
   private Map<String, String> calculateNewLayout(String table, 
MasterBasedDistributedLayout existingLayout,
@@ -326,7 +315,8 @@ public class MasterBasedDistributedLayoutFactory implements 
DistributedLayoutFac
   }
 
   private String getStoragePath(String table) {
-    return _tableStoragePath + "/" + table;
+    String tableStoragePath = ZookeeperPathConstants.getTablePath(_cluster, 
table);
+    return tableStoragePath + "/" + table;
   }
 
   @SuppressWarnings("serial")

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c47af820/blur-core/src/main/java/org/apache/blur/server/TableContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/server/TableContext.java 
b/blur-core/src/main/java/org/apache/blur/server/TableContext.java
index 12dd316..3ec68f4 100644
--- a/blur-core/src/main/java/org/apache/blur/server/TableContext.java
+++ b/blur-core/src/main/java/org/apache/blur/server/TableContext.java
@@ -108,6 +108,10 @@ public class TableContext {
     _cache.clear();
   }
 
+  public static void clear(String table) {
+    _cache.remove(table);
+  }
+
   public static TableContext create(TableDescriptor tableDescriptor) {
     if (tableDescriptor == null) {
       throw new NullPointerException("TableDescriptor can not be null.");
@@ -364,4 +368,5 @@ public class TableContext {
   public ReadInterceptor getReadInterceptor() {
     return _readInterceptor;
   }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c47af820/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java 
b/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
index 4ed5e5a..4165013 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
@@ -100,7 +100,7 @@ public abstract class TableAdmin implements Iface {
   @Override
   public final void createTable(TableDescriptor tableDescriptor) throws 
BlurException, TException {
     try {
-      TableContext.clear();
+      TableContext.clear(tableDescriptor.getName());
       BlurUtil.validateTableName(tableDescriptor.getName());
       assignClusterIfNull(tableDescriptor);
       _clusterStatus.createTable(tableDescriptor);
@@ -128,7 +128,7 @@ public abstract class TableAdmin implements Iface {
   @Override
   public final void disableTable(String table) throws BlurException, 
TException {
     try {
-      TableContext.clear();
+      TableContext.clear(table);
       String cluster = _clusterStatus.getCluster(false, table);
       if (cluster == null) {
         throw new BException("Table [" + table + "] not found.");
@@ -145,7 +145,7 @@ public abstract class TableAdmin implements Iface {
   @Override
   public final void enableTable(String table) throws BlurException, TException 
{
     try {
-      TableContext.clear();
+      TableContext.clear(table);
       String cluster = _clusterStatus.getCluster(false, table);
       if (cluster == null) {
         throw new BException("Table [" + table + "] not found.");
@@ -282,7 +282,7 @@ public abstract class TableAdmin implements Iface {
   @Override
   public final void removeTable(String table, boolean deleteIndexFiles) throws 
BlurException, TException {
     try {
-      TableContext.clear();
+      TableContext.clear(table);
       String cluster = _clusterStatus.getCluster(false, table);
       if (cluster == null) {
         throw new BException("Table [" + table + "] not found.");

Reply via email to