Skip to content

Commit

Permalink
make HASH_TYPE configurable in carbon.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
slackhappy committed Mar 3, 2014
1 parent 1f29f08 commit 4ce986b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion conf/carbon.conf.example
Expand Up @@ -184,6 +184,11 @@ PICKLE_RECEIVER_PORT = 2014
# RELAY_METHOD = consistent-hashing
RELAY_METHOD = rules

# If using consistent-hashing, you can choose your hashring function
# md5 is the default function. crc32 uses less CPU, but will have
# choose different destinations for a given metric
# HASH_TYPE = md5

# If you use consistent-hashing you may want to add redundancy
# of your data by replicating every datapoint to more than
# one machine.
Expand Down Expand Up @@ -243,7 +248,7 @@ PICKLE_RECEIVER_PORT = 2024
# use multiple carbon-cache instances then it would look like this:
#
# DESTINATIONS = 127.0.0.1:2004:a, 127.0.0.1:2104:b
#
#
# The format is comma-delimited IP:PORT:INSTANCE where the :INSTANCE part is
# optional and refers to the "None" instance if omitted.
#
Expand Down
10 changes: 5 additions & 5 deletions lib/carbon/conf.py
Expand Up @@ -60,6 +60,7 @@
MANHOLE_USER="",
MANHOLE_PUBLIC_KEY="",
RELAY_METHOD='rules',
HASH_TYPE='md5',
REPLICATION_FACTOR=1,
DESTINATIONS=[],
USE_FLOW_CONTROL=True,
Expand Down Expand Up @@ -342,7 +343,6 @@ class CarbonAggregatorOptions(CarbonCacheOptions):
optParameters = [
["rules", "", None, "Use the given aggregation rules file."],
["rewrite-rules", "", None, "Use the given rewrite rules file."],
["hash-type", "", None, "Type of hashing to use for consistent hashing"],
] + CarbonCacheOptions.optParameters

def postOptions(self):
Expand All @@ -362,7 +362,6 @@ class CarbonRelayOptions(CarbonCacheOptions):
optParameters = [
["rules", "", None, "Use the given relay rules file."],
["aggregation-rules", "", None, "Use the given aggregation rules file."],
["hash-type", "", None, "Type of hashing to use for consistent hashing"],
] + CarbonCacheOptions.optParameters

def postOptions(self):
Expand All @@ -371,9 +370,10 @@ def postOptions(self):
self["rules"] = join(settings["CONF_DIR"], "relay-rules.conf")
settings["relay-rules"] = self["rules"]

if self["hash-type"] is None:
self["hash-type"] = "md5"
settings["hash-type"] = self["hash-type"]
if settings["HASH_TYPE"] not in ("md5", "crc32"):
print ("In carbon.conf, HASH_TYPE must be either 'md5' 'crc32'. Invalid value: '%s'" %
settings.HASH_TYPE)
sys.exit(1)

if self["aggregation-rules"] is None:
self["aggregation-rules"] = join(settings["CONF_DIR"], "aggregation-rules.conf")
Expand Down
2 changes: 1 addition & 1 deletion lib/carbon/service.py
Expand Up @@ -177,7 +177,7 @@ def createRelayService(config):
root_service = createBaseService(config)

# Configure application components
hash_type = settings["hash-type"]
hash_type = settings.HASH_TYPE
if settings.RELAY_METHOD == 'rules':
router = RelayRulesRouter(settings["relay-rules"])
elif settings.RELAY_METHOD == 'consistent-hashing':
Expand Down

0 comments on commit 4ce986b

Please sign in to comment.