def create_vtgate_cursor(class_, vtgate_conn, tablet_type, is_dml, **kargs): routing = class_.create_shard_routing(is_dml, kargs) # FIXME:extend VTGateCursor's api to accept shard_names # and allow queries based on that. cursor = vtgate_cursor.VTGateCursor(vtgate_conn, class_.keyspace, tablet_type, keyranges=[routing.shard_name,], writable=is_dml) return cursor
def create_vtgate_cursor(class_, vtgate_conn, tablet_type, is_dml, **kargs): routing = class_.create_shard_routing(is_dml) if routing.keyrange is not None: keyranges = [routing.keyrange,] else: dbexceptions.ProgrammingError("Empty Keyrange") cursor = vtgate_cursor.VTGateCursor(vtgate_conn, class_.keyspace, tablet_type, keyranges=keyranges, writable=is_dml) return cursor
def create_vtgate_cursor(class_, vtgate_conn, tablet_type, is_dml, **cursor_kargs): cursor_method = functools.partial(db_object.create_cursor_from_params, vtgate_conn, tablet_type, False) routing = class_.create_shard_routing(cursor_method, **cursor_kargs) if is_dml: if routing.sharding_key is None or db_object._is_iterable_container( routing.sharding_key): dbexceptions.InternalError( "Writes require unique sharding_key") keyspace_ids = None keyranges = None if routing.sharding_key is not None: keyspace_ids = [] if db_object._is_iterable_container(routing.sharding_key): for sk in routing.sharding_key: kid = class_.sharding_key_to_keyspace_id(sk) keyspace_ids.append(pack_keyspace_id(kid)) else: kid = class_.sharding_key_to_keyspace_id(routing.sharding_key) keyspace_ids = [ pack_keyspace_id(kid), ] elif routing.entity_id_sharding_key_map is not None: keyspace_ids = [] for sharding_key in routing.entity_id_sharding_key_map.values(): keyspace_ids.append( pack_keyspace_id( class_.sharding_key_to_keyspace_id(sharding_key))) elif routing.keyrange: keyranges = [ routing.keyrange, ] cursor = vtgate_cursor.VTGateCursor(vtgate_conn, class_.keyspace, tablet_type, keyspace_ids=keyspace_ids, keyranges=keyranges, writable=is_dml) cursor.routing = routing return cursor
def create_vtgate_cursor(class_, vtgate_conn, tablet_type, is_dml, **kargs): routing = class_.create_shard_routing(is_dml, kargs) keyspace_ids = None keyranges = None if routing.sharding_key is not None: keysapce_ids = [class_.sharding_key_to_keyspace_id(routing.sharding_key),] elif routing.entity_id_sharding_key_map is not None: keyspace_ids = [] for sharding_key in routing.entity_id_sharding_key_map.values(): keysapce_ids.append(class_.sharding_key_to_keyspace_id(sharding_key)) elif routing.keyrange: keyranges = [routing.keyrange,] cursor = vtgate_cursor.VTGateCursor(vtgate_conn, class_.keyspace, tablet_type, keyspace_ids=keyspace_ids, keyranges=keyranges, writable=is_dml) return cursor