Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from MaxIV-KitsControls/change-consistency-level
Browse files Browse the repository at this point in the history
Make cassandra consistency level configurable.
  • Loading branch information
13bscsaamjad authored Jan 18, 2021
2 parents ef248db + 2512ad3 commit 24ca375
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 2 additions & 4 deletions hdbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class HDBPlusPlusConnection(object):
"A very simple direct interface to the HDB++ cassandra backend"

def __init__(self, nodes=None, keyspace="hdb", address_map=None,
fetch_size=50000, cache_size=1e9):
fetch_size=50000, cache_size=1e9, consistency_level="ONE"):
self.nodes = nodes if nodes else ["localhost"]
if address_map:
translator = LocalNetworkAdressTranslator(address_map)
Expand All @@ -121,9 +121,7 @@ def __init__(self, nodes=None, keyspace="hdb", address_map=None,
self.cluster = Cluster(self.nodes)

s = self.cluster.connect(keyspace)
# TODO: Might be useful to be able to set the consistency
# level in the configuration
s.default_consistency_level = ConsistencyLevel.LOCAL_QUORUM
s.default_consistency_level = getattr(ConsistencyLevel, consistency_level)
self.session = aiosession(s) # asyncio wrapper
self.session.default_fetch_size = fetch_size

Expand Down
4 changes: 4 additions & 0 deletions hdbppviewer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ data_cache_size=1000000000
nodes=b-kirk13-cas-3,b-kirk13-cas-4,b-kirk13-cas-5,b-picard13-cas-0,b-picard13-cas-1,b-picard13-cas-2
# name of the keyspace to use
keyspace=hdb
# Consistency level for reading data. Must be one of the levels listed on
# https://docs.datastax.com/en/cassandra-oss/3.0/cassandra/dml/dmlConfigConsistency.html
# Defaults to ONE
consistency_level=ONE

# [hdbpp:cassandra_address_translation]
# # This is a driver feature which allows a mapping between cassandra
Expand Down
8 changes: 5 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ async def post_raw_search(hdbpp, request):
config = configparser.RawConfigParser()
config.read(args.config)
PORT = config.getint("server", "port")
CASSANDRA_NODES = config.get("hdbpp:cassandra", "nodes").split(",")
CASSANDRA_KEYSPACE = config.get("hdbpp:cassandra", "keyspace")
CASSANDRA_NODES = config["hdbpp:cassandra"].get("nodes").split(",")
CASSANDRA_KEYSPACE = config["hdbpp:cassandra"].get("keyspace")
CASSANDRA_CONSISTENCY_LEVEL = config["hdbpp:cassandra"].get("consistency_level", "ONE")
if config.has_section("hdbpp:cassandra_address_translation"):
CASSANDRA_ADDRESS_TRANSLATION = dict(
config.items("hdbpp:cassandra_address_translation"))
Expand All @@ -253,7 +254,8 @@ async def post_raw_search(hdbpp, request):
hdbpp = HDBPlusPlusConnection(nodes=CASSANDRA_NODES,
keyspace=CASSANDRA_KEYSPACE,
address_map=CASSANDRA_ADDRESS_TRANSLATION,
cache_size=DATA_CACHE_SIZE)
cache_size=DATA_CACHE_SIZE,
consistency_level=CASSANDRA_CONSISTENCY_LEVEL)

app.router.add_route('GET', '/controlsystems',
partial(get_controlsystems, hdbpp))
Expand Down

0 comments on commit 24ca375

Please sign in to comment.