示例#1
0
    def __init__(self, sqluri, standard_collections=False, **dbkwds):
        self.sqluri = sqluri
        instance_id, database_id = sqluri[len("spanner://"):].split(":")
        self.client = spanner.Client()
        self._instance = self.client.instance(instance_id)
        self._pool = pool = spanner.BurstyPool(
            target_size=int(dbkwds.get("pool_size", 100)))
        self._database = self._instance.database(database_id, pool=pool)
        # for debugging: support disabling FORCE_INDEX=BsoLastModified
        self._force_bsolm_index = dbkwds.get("_force_bsolm_index", True)

        self.standard_collections = standard_collections
        if self.standard_collections and dbkwds.get("create_tables", False):
            raise Exception("Creating tables in Spanner must be done manually")

        # A local in-memory cache for the name => collectionid mapping.
        self._collections_by_name = {}
        self._collections_by_id = {}
        if self.standard_collections:
            for id, name in STANDARD_COLLECTIONS.iteritems():
                self._collections_by_name[name] = id
                self._collections_by_id[id] = name

        # A thread-local to track active sessions.
        self._tldata = threading.local()
示例#2
0
def open_database(parameters):
    """Opens a database specified by the parameters from parse_options()."""
    spanner_client = spanner.Client()
    instance_id = parameters['cloudspanner.instance']
    instance = spanner_client.instance(instance_id)
    database_id = parameters['cloudspanner.database']
    pool = spanner.BurstyPool(int(parameters['num_worker']))
    database = instance.database(database_id, pool=pool)

    return database