incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/3] git commit: BLUR-ID:58 validation added to check existing table path
Date Tue, 05 Mar 2013 02:35:25 GMT
BLUR-ID:58 validation added to check existing table path

Signed-off-by: Aaron McCurry <amccurry@gmail.com>


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

Branch: refs/heads/0.2-dev
Commit: fd44874a57da386e9ee784e8e31221fd67cb6717
Parents: 1a0b35f
Author: Gagan <gagandeepjuneja@gmail.com>
Authored: Sun Mar 3 22:38:46 2013 +0530
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Mar 4 21:30:56 2013 -0500

----------------------------------------------------------------------
 .../manager/clusterstatus/BaseClusterStatus.java   |    9 ++
 .../clusterstatus/SimpleZKClusterStatusTest.java   |  112 +++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/fd44874a/src/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/BaseClusterStatus.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/BaseClusterStatus.java
b/src/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/BaseClusterStatus.java
index 13c2e35..cf93550 100644
--- a/src/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/BaseClusterStatus.java
+++ b/src/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/BaseClusterStatus.java
@@ -75,6 +75,15 @@ public abstract class BaseClusterStatus extends ClusterStatus {
       if (getZooKeeper().exists(tablePath, false) != null) {
         throw new IOException("Table [" + table + "] already exists.");
       }
+      //checking if table is referring to same index path.	
+      List<String> tables = getTableList(false);
+      for(String tableName : tables){
+        TableDescriptor tableDesc = getTableDescriptor(false, tableName);
+        if(tableDesc.getStoragePath().equals(tableDescriptor.getStoragePath())){
+          throw new IOException("Table [" + table + "]" + " can not be created because ["
+ tableName + "] is already referring to " 
+              + "[" +tableDescriptor.getStoragePath() + "]" +" index path.");
+        }
+      }
       BlurUtil.setupFileSystem(uri, shardCount);
       BlurUtil.createPath(getZooKeeper(), tablePath, BlurUtil.read(tableDescriptor));
     } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/fd44874a/src/blur-core/src/test/java/org/apache/blur/manager/clusterstatus/SimpleZKClusterStatusTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/manager/clusterstatus/SimpleZKClusterStatusTest.java
b/src/blur-core/src/test/java/org/apache/blur/manager/clusterstatus/SimpleZKClusterStatusTest.java
new file mode 100644
index 0000000..ddc610a
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/manager/clusterstatus/SimpleZKClusterStatusTest.java
@@ -0,0 +1,112 @@
+package org.apache.blur.manager.clusterstatus;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.blur.MiniCluster;
+import org.apache.blur.log.Log;
+import org.apache.blur.log.LogFactory;
+import org.apache.blur.thrift.generated.Analyzer;
+import org.apache.blur.thrift.generated.TableDescriptor;
+import org.apache.blur.utils.BlurUtil;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
+import org.apache.zookeeper.server.quorum.QuorumPeerMain;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class SimpleZKClusterStatusTest {
+
+  private static final String TEST_TABLE = "test";
+  private static final String TEST_TABLE1 = "test1";
+  private static final String TEST_TABLE2 = "test2";
+  private static final String DEFAULT = "default";
+
+  private static final File TMPDIR = new File(System.getProperty("blur.tmp.dir", "/tmp"));
+
+  private static final Log LOG = LogFactory.getLog(SimpleZKClusterStatusTest.class);
+  private ZooKeeper zooKeeper;
+  private SimpleZKClusterStatus clusterStatus;
+
+  public static class QuorumPeerMainRun extends QuorumPeerMain {
+    @Override
+    public void initializeAndRun(String[] args) throws ConfigException, IOException {
+      super.initializeAndRun(args);
+    }
+  }
+
+  @BeforeClass
+  public static void setupOnce() throws InterruptedException, IOException, KeeperException
{
+    MiniCluster.startZooKeeper("zk_test");
+  }
+
+  @AfterClass
+  public static void teardownOnce() {
+    MiniCluster.shutdownZooKeeper();
+  }
+
+  @Before
+  public void setup() throws KeeperException, InterruptedException, IOException {
+    zooKeeper = new ZooKeeper(MiniCluster.getZkConnectionString(), 30000, new Watcher() {
+      @Override
+      public void process(WatchedEvent event) {
+
+      }
+    });
+    BlurUtil.setupZookeeper(zooKeeper, DEFAULT);
+    clusterStatus = new SimpleZKClusterStatus(DEFAULT, zooKeeper);
+  }
+
+  @After
+  public void teardown() throws InterruptedException {
+    clusterStatus.close();
+    zooKeeper.close();
+  }
+  
+  @Test(expected = RuntimeException.class)
+  public void createTableShouldFailForSameStotagePath() throws KeeperException, InterruptedException
{
+    LOG.warn(" Test createTableShouldFailForSameStotagePath ");
+    createTable(TEST_TABLE1, new File(TMPDIR, "zk_test1_hdfs").getAbsolutePath(), true);
+    createTable(TEST_TABLE2, new File(TMPDIR, "zk_test1_hdfs").getAbsolutePath(), true);
+  }
+
+ @Test
+   public void createTable() throws KeeperException, InterruptedException {
+   LOG.warn("Test createTable");
+   createTable(TEST_TABLE, new File(TMPDIR, "zk_test_hdfs").getAbsolutePath(), true);
+ }
+ private void createTable(String name, String storagePath, boolean enabled ) throws KeeperException,
InterruptedException {
+   TableDescriptor tableDescriptor = new TableDescriptor();
+   tableDescriptor.setName(name);
+   tableDescriptor.setAnalyzer(new Analyzer());
+   tableDescriptor.setStoragePath(storagePath);
+   tableDescriptor.setEnabled(enabled);
+   clusterStatus.createTable(tableDescriptor);
+   if (enabled) {
+     clusterStatus.enableTable(name);
+   }
+ }
+}


Mime
View raw message