You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/11/08 20:59:02 UTC
git commit: more Marmotta Cloud features (proper datacenter id
generation)
Updated Branches:
refs/heads/develop eb9308a44 -> a95a0c867
more Marmotta Cloud features (proper datacenter id generation)
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/a95a0c86
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/a95a0c86
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/a95a0c86
Branch: refs/heads/develop
Commit: a95a0c867f0f747244151680481babee5d39cbe4
Parents: eb9308a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Nov 8 20:58:57 2013 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Nov 8 20:58:57 2013 +0100
----------------------------------------------------------------------
.../services/ZookeeperServiceImpl.java | 43 +++++++++++++++-----
1 file changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a95a0c86/platform/marmotta-zookeeper/src/main/java/org/apache/marmotta/platform/zookeeper/services/ZookeeperServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-zookeeper/src/main/java/org/apache/marmotta/platform/zookeeper/services/ZookeeperServiceImpl.java b/platform/marmotta-zookeeper/src/main/java/org/apache/marmotta/platform/zookeeper/services/ZookeeperServiceImpl.java
index 90e7101..844c2d0 100644
--- a/platform/marmotta-zookeeper/src/main/java/org/apache/marmotta/platform/zookeeper/services/ZookeeperServiceImpl.java
+++ b/platform/marmotta-zookeeper/src/main/java/org/apache/marmotta/platform/zookeeper/services/ZookeeperServiceImpl.java
@@ -65,6 +65,7 @@ public class ZookeeperServiceImpl implements ZookeeperService {
private Properties properties;
+ private String datacenterIdPath;
public void initialise(@Observes ConfigurationServiceInitEvent event) throws IOException, InterruptedException {
log.warn("Activating Marmotta Zookeeper Bridge");
@@ -142,16 +143,25 @@ public class ZookeeperServiceImpl implements ZookeeperService {
}
@PreDestroy
- private void shutdown() throws InterruptedException, IOException {
- log.info("deactivating Zookeeper Bridge ...");
- if(nodeKeeper != null) {
- log.info(" - closing nodekeeper connection");
- nodeKeeper.shutdown();
- log.info(" ... closed");
- }
- if(properties != null) {
- File nkProperties = new File(configurationService.getHome() + File.separator + "nodekeeper.properties");
- properties.store(new FileOutputStream(nkProperties), "automatic nodekeeper state");
+ private void shutdown() {
+ try {
+ log.info("ZOOKEEPER: deactivating Zookeeper Bridge ...");
+ if(nodeKeeper != null) {
+ String cluster = configurationService.getStringConfiguration(ZK_CLUSTER, "default");
+
+ log.info("- removing lock on datacenter id");
+ nodeKeeper.getZooKeeper().delete(String.format(datacenterIdPath, cluster),-1);
+
+ log.info(" - closing nodekeeper connection");
+ nodeKeeper.shutdown();
+ log.info(" ... closed");
+ }
+ if(properties != null) {
+ File nkProperties = new File(configurationService.getHome() + File.separator + "nodekeeper.properties");
+ properties.store(new FileOutputStream(nkProperties), "automatic nodekeeper state");
+ }
+ } catch (InterruptedException | KeeperException | IOException e) {
+ log.error("ZOOKEEPER: exception while shutting down Zookeeper connection ({})", e.getMessage());
}
}
@@ -175,14 +185,27 @@ public class ZookeeperServiceImpl implements ZookeeperService {
createNodeIfNotExists("/marmotta/clusters");
createNodeIfNotExists(String.format("/marmotta/clusters/%s", cluster));
createNodeIfNotExists(String.format("/marmotta/clusters/%s/config", cluster));
+ createNodeIfNotExists(String.format("/marmotta/clusters/%s/snowflake", cluster));
createNodeIfNotExists(String.format("/marmotta/clusters/%s/instances", cluster));
createNodeIfNotExists(String.format("/marmotta/clusters/%s/instances/%s", cluster, uuid));
createNodeIfNotExists(String.format("/marmotta/clusters/%s/instances/%s/config", cluster, uuid));
+
+ int datacenterId = configurationService.getIntConfiguration("database.datacenter.id",0);
+
+ // configure datacenter id using a sequential ephemeral node
+ while (datacenterIdPath == null || nodeKeeper.getZooKeeper().exists(String.format("/marmotta/clusters/%s/snowflake/id-%010d", cluster,datacenterId), false) != null) {
+ datacenterIdPath = nodeKeeper.getZooKeeper().create(String.format("/marmotta/clusters/%s/snowflake/id-", cluster),new String("creator:"+uuid).getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
+ datacenterId = Integer.parseInt(datacenterIdPath.substring(datacenterIdPath.lastIndexOf("id-")+3)) % 4096;
+ }
+ log.info("ZOOKEEPER: generated datacenter ID {}", datacenterId);
+ configurationService.setIntConfiguration("database.datacenter.id", datacenterId);
}
}
+
+
private void createNodeIfNotExists(String path) throws KeeperException, InterruptedException {
if (nodeKeeper.getZooKeeper().exists(path,false) == null) {
String uuid = configurationService.getStringConfiguration(ZK_INSTANCE, UUID.randomUUID().toString());