carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [13/56] [abbrv] incubator-carbondata git commit: [BUG] Zookeeper lock changes to allow exclusive locks for different tables (#688)
Date Thu, 23 Jun 2016 14:16:01 GMT
[BUG] Zookeeper lock changes to allow exclusive locks for different tables (#688)

added schema name and table name to Zookeeper lock location

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

Branch: refs/heads/master
Commit: f479e7efecfb10c16ac994a4c933d59efa6bb685
Parents: 6c2469d
Author: ravikiran23 <ravikiran.sn042@gmail.com>
Authored: Fri Jun 17 23:12:33 2016 +0530
Committer: Venkata Ramana G <g.ramana.v@gmail.com>
Committed: Fri Jun 17 23:12:33 2016 +0530

----------------------------------------------------------------------
 .../core/constants/CarbonCommonConstants.java   |  5 ++++
 .../core/locks/CarbonLockFactory.java           |  2 +-
 .../carbondata/core/locks/ZooKeeperLocking.java | 26 +++++++++++++++++---
 .../core/locks/ZooKeeperLockingTest.java        |  7 ++++--
 4 files changed, 33 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/f479e7ef/core/src/main/java/org/carbondata/core/constants/CarbonCommonConstants.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/carbondata/core/constants/CarbonCommonConstants.java b/core/src/main/java/org/carbondata/core/constants/CarbonCommonConstants.java
index bf0fd0b..6618ac0 100644
--- a/core/src/main/java/org/carbondata/core/constants/CarbonCommonConstants.java
+++ b/core/src/main/java/org/carbondata/core/constants/CarbonCommonConstants.java
@@ -1029,6 +1029,11 @@ public final class CarbonCommonConstants {
   public static final String CARBON_LOCK_TYPE_HDFS =
       "HDFSLOCK";
 
+  /**
+   * Lock file in zoo keeper will be of this name.
+   */
+  public static final String ZOOKEEPER_LOCK = "zookeeperLock";
+
   private CarbonCommonConstants() {
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/f479e7ef/core/src/main/java/org/carbondata/core/locks/CarbonLockFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/carbondata/core/locks/CarbonLockFactory.java b/core/src/main/java/org/carbondata/core/locks/CarbonLockFactory.java
index 232c2b8..99f4ab1 100644
--- a/core/src/main/java/org/carbondata/core/locks/CarbonLockFactory.java
+++ b/core/src/main/java/org/carbondata/core/locks/CarbonLockFactory.java
@@ -49,7 +49,7 @@ public class CarbonLockFactory {
         return new LocalFileLock(location, lockUsage);
 
       case CarbonCommonConstants.CARBON_LOCK_TYPE_ZOOKEEPER:
-        return new ZooKeeperLocking(lockUsage);
+        return new ZooKeeperLocking(location, lockUsage);
 
       case CarbonCommonConstants.CARBON_LOCK_TYPE_HDFS:
         return new HdfsFileLock(location, lockUsage);

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/f479e7ef/core/src/main/java/org/carbondata/core/locks/ZooKeeperLocking.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/carbondata/core/locks/ZooKeeperLocking.java b/core/src/main/java/org/carbondata/core/locks/ZooKeeperLocking.java
index f7f5d0c..8b04ac1 100644
--- a/core/src/main/java/org/carbondata/core/locks/ZooKeeperLocking.java
+++ b/core/src/main/java/org/carbondata/core/locks/ZooKeeperLocking.java
@@ -50,6 +50,11 @@ public class ZooKeeperLocking extends AbstractCarbonLock {
   private static final String zooKeeperLocation = CarbonCommonConstants.ZOOKEEPER_LOCATION;
 
   /**
+   * Unique folder for each cube with SchemaName_CubeName
+   */
+  private final String tableIdFolder;
+
+  /**
    * lockName is the name of the lock to use. This name should be same for every process
that want
    * to share the same lock
    */
@@ -65,17 +70,30 @@ public class ZooKeeperLocking extends AbstractCarbonLock {
   /**
    * @param lockUsage
    */
-  public ZooKeeperLocking(LockUsage lockUsage) {
-    this.lockName = CarbonCommonConstants.METADATA_LOCK;
+  public ZooKeeperLocking(String location, LockUsage lockUsage) {
+    this.lockName = CarbonCommonConstants.ZOOKEEPER_LOCK;
     this.lockTypeFolder = zooKeeperLocation;
+    location = location.replace("\\", "/");
+    String tempStr = location.substring(0, location.lastIndexOf('/'));
+    String schemaName = tempStr.substring(tempStr.lastIndexOf('/') + 1, tempStr.length());
+
+    String cubeName = location.substring(location.lastIndexOf('/') + 1, location.length());
+
+    this.tableIdFolder = zooKeeperLocation + CarbonCommonConstants.FILE_SEPARATOR + schemaName
+        + '.' + cubeName;
 
     zk = ZookeeperInit.getInstance().getZookeeper();
 
-    this.lockTypeFolder =
-        zooKeeperLocation + CarbonCommonConstants.FILE_SEPARATOR + lockUsage.toString();
+    this.lockTypeFolder = zooKeeperLocation + CarbonCommonConstants.FILE_SEPARATOR + schemaName
+        + '.' + cubeName + CarbonCommonConstants.FILE_SEPARATOR
+        + lockUsage.toString();
     try {
       createBaseNode();
       // if exists returns null then path doesnt exist. so creating.
+      if (null == zk.exists(this.tableIdFolder, true)) {
+        zk.create(this.tableIdFolder, new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+      }
+      // if exists returns null then path doesnt exist. so creating.
       if (null == zk.exists(this.lockTypeFolder, true)) {
         zk.create(this.lockTypeFolder, new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       }

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/f479e7ef/core/src/test/java/org/carbondata/core/locks/ZooKeeperLockingTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/carbondata/core/locks/ZooKeeperLockingTest.java b/core/src/test/java/org/carbondata/core/locks/ZooKeeperLockingTest.java
index 5b21dde..3bf3993 100644
--- a/core/src/test/java/org/carbondata/core/locks/ZooKeeperLockingTest.java
+++ b/core/src/test/java/org/carbondata/core/locks/ZooKeeperLockingTest.java
@@ -78,10 +78,13 @@ public class ZooKeeperLockingTest {
 
     ZookeeperInit zki = ZookeeperInit.getInstance("127.0.0.1:" + freePort);
 
-    ZooKeeperLocking zkl = new ZooKeeperLocking(LockUsage.METADATA_LOCK);
+    ZooKeeperLocking zkl =
+        new ZooKeeperLocking("D:/carbondata/examples/target/store/default/t3/Metadata",
+            LockUsage.METADATA_LOCK);
     Assert.assertTrue(zkl.lock());
 
-    ZooKeeperLocking zk2 = new ZooKeeperLocking(LockUsage.METADATA_LOCK);
+    ZooKeeperLocking zk2 = new ZooKeeperLocking(
+        "D:/carbondata/examples/target/store/default/t3/Metadata", LockUsage.METADATA_LOCK);
     Assert.assertTrue(!zk2.lock());
 
     Assert.assertTrue(zkl.unlock());


Mime
View raw message