Create table for keeping track of allocated IDs
@@ -158,6 +158,27 @@ def create_transactions_table(session):
raise
+def create_entity_ids_table(session):
+ create_table = """
+ CREATE TABLE IF NOT EXISTS reserved_ids (
+ project text,
+ scattered boolean,
+ last_reserved bigint,
+ op_id uuid,
+ PRIMARY KEY ((project, scattered))
+ )
+ """
+ statement = SimpleStatement(create_table, retry_policy=NO_RETRIES)
+ try:
+ session.execute(statement, timeout=SCHEMA_CHANGE_TIMEOUT)
+ except cassandra.OperationTimedOut:
+ logging.warning(
+ 'Encountered an operation timeout while creating entity_ids table. '
+ 'Waiting {} seconds for schema to settle.'.format(SCHEMA_CHANGE_TIMEOUT))
+ time.sleep(SCHEMA_CHANGE_TIMEOUT)
+ raise
+
+
def prime_cassandra(replication):
""" Create Cassandra keyspace and initial tables.
@@ -228,6 +249,7 @@ def prime_cassandra(replication):
create_groups_table(session)
create_transactions_table(session)
create_pull_queue_tables(cluster, session)
+ create_entity_ids_table(session)
first_entity = session.execute(
'SELECT * FROM "{}" LIMIT 1'.format(dbconstants.APP_ENTITY_TABLE))
