You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/24 21:20:58 UTC

[15/19] git commit: Added token calculation on startup

Added token calculation on startup


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

Branch: refs/heads/two-dot-o
Commit: 4022d99c593d4e3d6ddc7a6ac4f40cf5ae071d51
Parents: fc10597
Author: Todd Nine <tn...@apigee.com>
Authored: Mon Mar 24 10:51:17 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Mon Mar 24 10:51:17 2014 -0700

----------------------------------------------------------------------
 .../src/main/groovy/configure_cassandra.groovy  | 49 ++++++++++++++++----
 1 file changed, 41 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4022d99c/stack/awscluster/src/main/groovy/configure_cassandra.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_cassandra.groovy b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
index 7edccbe..6293686 100644
--- a/stack/awscluster/src/main/groovy/configure_cassandra.groovy
+++ b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
@@ -12,14 +12,16 @@ String accessKey = (String)System.getenv().get("AWS_ACCESS_KEY")
 String secretKey = (String)System.getenv().get("AWS_SECRET_KEY")
 String stackName = (String)System.getenv().get("STACK_NAME")
 String hostName  = (String)System.getenv().get("PUBLIC_HOSTNAME")
-def clusterName  = (String)System.getenv().get("CASSANDRA_CLUSTER_NAME")
+String clusterName  = (String)System.getenv().get("CASSANDRA_CLUSTER_NAME")
+int cassNumServers = ((String)System.getenv().get("CASSANDRA_NUM_SERVERS")).toInteger()
+
 String domain    = stackName
 
 def creds = new BasicAWSCredentials(accessKey, secretKey)
 def sdbClient = new AmazonSimpleDBClient(creds)
 
 // build seed list by listing all Cassandra nodes found in SimpleDB domain with our stackName
-def selectResult = sdbClient.select(new SelectRequest((String)"select * from ${domain}"))
+def selectResult = sdbClient.select(new SelectRequest((String)"select * from `${domain}` where itemName() is not null order by itemName()"))
 def seeds = ""
 def sep = ""
 for (item in selectResult.getItems()) {
@@ -30,7 +32,38 @@ for (item in selectResult.getItems()) {
     }
 }
 
+
+//calculate what our token should be
+selectResult = sdbClient.select(new SelectRequest((String)"select * from `${domain}` where itemName() is not null  order by itemName()"))
+
+int index = 0;
+int count = 0;
+
+for (item in selectResult.getItems()) {
+
+    def name = item.getName()
+
+    //get our index so that we know which token to get
+    if (name == hostName) {
+        index = count
+        break
+    }
+
+    count++
+}
+
+long[] tokens = new long[cassNumServers]
+
+for(int i =0; i < cassNumServers; i ++){
+    tokens[i] =  ((2**64 / cassNumServers) * i) - 2**63
+}
+
+String token = tokens[index]
+
+
 def cassandraConfig = """
+
+
 cluster_name: '${clusterName}'
 listen_address: ${hostName}
 seed_provider:
@@ -38,21 +71,21 @@ seed_provider:
       parameters:
           - seeds: "${seeds}"
 auto_bootstrap: false 
-initial_token:
+initial_token: ${token}
 hinted_handoff_enabled: true
 hinted_handoff_throttle_in_kb: 1024
 max_hints_delivery_threads: 2
 authenticator: org.apache.cassandra.auth.AllowAllAuthenticator
 authorizer: org.apache.cassandra.auth.AllowAllAuthorizer
-partitioner: org.apache.cassandra.dht.RandomPartitioner
+partitioner: org.apache.cassandra.dht.Murmur3Partitioner
 data_file_directories:
     - /mnt/data/cassandra/data
 commitlog_directory: /mnt/data/cassandra/commitlog
 disk_failure_policy: stop
-key_cache_size_in_mb:
+key_cache_size_in_mb: 2048
 key_cache_save_period: 14400
-row_cache_size_in_mb: 0
-row_cache_save_period: 0
+row_cache_size_in_mb: 2048
+row_cache_save_period: 14400
 row_cache_provider: SerializingCacheProvider
 saved_caches_directory: /mnt/data/cassandra/saved_caches
 commitlog_sync: periodic
@@ -91,7 +124,7 @@ write_request_timeout_in_ms: 10000
 truncate_request_timeout_in_ms: 60000
 request_timeout_in_ms: 10000
 cross_node_timeout: false
-endpoint_snitch: SimpleSnitch
+endpoint_snitch: EC2Snitch
 dynamic_snitch_update_interval_in_ms: 100 
 dynamic_snitch_reset_interval_in_ms: 600000
 dynamic_snitch_badness_threshold: 0.1