def build(cls, length, shard_id = None, pool_id = None): if length < cls.MIN_LENGTH: raise Exception("Random token needs to be at least " + str(cls.MIN_LENGTH) + " chars long") """ Returns a random alphanumeric string with """ r = ''.join(random.SystemRandom().choice( (string.ascii_letters + string.digits) ) for _ in range(length)) if shard_id is not None: if pool_id is None: pool_id = MySQLPool.MAIN num_shards = MySQL.get_pool(pool_id).get_num_shards() shard_id = shard_id % num_shards r = cls._apply_shard_info(r, shard_id, pool_id) elif pool_id is not None: r = cls._apply_shard_info(r, None, pool_id) return r
def build(cls, length, shard_id=None, pool_id=None): if length < cls.MIN_LENGTH: raise Exception("Random token needs to be at least " + str(cls.MIN_LENGTH) + " chars long") """ Returns a random alphanumeric string with """ r = ''.join(random.SystemRandom().choice((string.ascii_letters + string.digits)) for _ in range(length)) if shard_id is not None: if pool_id is None: pool_id = MySQLPool.MAIN num_shards = MySQL.get_pool(pool_id).get_num_shards() shard_id = shard_id % num_shards r = cls._apply_shard_info(r, shard_id, pool_id) elif pool_id is not None: r = cls._apply_shard_info(r, None, pool_id) return r
import sys from framework.storage.mysql import MySQL from framework.storage.mysql_pool import MySQLPool from multiprocessing import Pool from pprint import pprint sql_file_name = sys.argv[1] try: pool_id = sys.argv[2] except IndexError: pool_id = MySQLPool.MAIN pool = MySQL.get_pool(pool_id) try: num_threads = sys.argv[3] except IndexError: num_threads = None def get_query_string(file_name): with open('sql/' + file_name) as data_file: return data_file.read() def get_query_runner(pool, query_str): # bind pool and query string to a function # that can make a query per shard id def run_one_query(shard_id): shard = pool.get_shard(shard_id) query_res = shard.query(query_str, None, True)