1
我試圖使用新datastax蟒蛇司機python腳本自動執行某些表和索引創建的Python驅動程序。但是,似乎某些語句被跳過或不按順序執行。我甚至試圖在每個命令後面放上10秒鐘的睡眠事件,希望它能夠工作,但事實並非如此。表和索引創建使用的卡桑德拉
通常只有第二和第三索引創建。有時創建索引不會在索引創建之前發生,並且出錯。
import logging
from cassandra.cluster import Cluster
from time import sleep
log = logging.getLogger()
log.setLevel('DEBUG')
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
log.addHandler(handler)
cluster = Cluster(['128.32.xxx.xxx','128.32.xxx.xxx','128.32.xxx.xxx'])
session = cluster.connect()
session.execute("""use test;""")
#session.execute("""drop table test.devices;""")
log.info('dropped table devices.')
session.execute("""CREATE TABLE devices (
device_uuid uuid,
external_identifier text,
geohash text,
latitude float,
longitude float,
measures set<text>,
name text,
parent_device_id uuid,
tags map<text, text>,
PRIMARY KEY (device_uuid)
) WITH
compression={'sstable_compression': 'SnappyCompressor'} USING CONSISTENCY ALL;""")
session.execute("""CREATE INDEX external_id_ind ON devices (external_identifier) USING CONSISTENCY ALL;""")
session.execute("""CREATE INDEX name_ind ON devices (name) USING CONSISTENCY ALL;""")
session.execute("""CREATE INDEX geohash_ind ON devices (geohash) USING CONSISTENCY ALL;""")
session.execute("""CREATE INDEX parent_device_id_ind ON devices (parent_device_id) USING CONSISTENCY ALL;""")