def get(self, table_name, *keys, **kwargs): num_uuids = self._table_names[table_name] ## A mapping between shards and columns to retrieve from each shard shards = defaultdict(list) ## Track the keys that we find found_keys = set() ## Determine all the shards that we need to contact for key in keys: assert len(key) == num_uuids joined_key = join_uuids(*key) row_names = [self._make_shard_name(table_name, joined_key)] for row_name in row_names: shards[row_name].append(joined_key) ## For each shard we contact, get all the keys it may hold for row_name, columns in shards.iteritems(): try: for key, val in self.tables[table_name].get(row_name, columns=columns,).iteritems(): key = split_uuids(key) logger.critical('cassandra get(%r) yielding %r %d' % (table_name, key, len(val))) ## key is a list [(uuid, uuid)] assert not any(k in found_keys for k in key) found_keys.add(tuple(key)) yield tuple(key), val except NotFoundException: pass ## Raise an exception if we don't retrieve all the keys that were requested missing_keys = set(keys) - found_keys for k in missing_keys: yield k, None
def _get_from_one_row(self, table_name, row_name, columns, start, finish, num_uuids): logger.debug('c* get: table_name=%r row_name=%r columns=%r start=%r finish=%r' % ( table_name, row_name, columns, start, finish)) if not columns: assert start is not None and finish is not None assert start <= finish num_yielded = 0 while True: ## if we have prev_start = start logger.debug('cassandra get(%r...)' % row_name) ## if table_name == 'inbound': ## import ipdb ## ipdb.set_trace() for key, val in self.tables[table_name].get( row_name, columns=columns, column_start=start, column_finish=finish, column_count=1, ).iteritems(): key = split_uuids(key) logger.critical('cassandra get(%r) yielding %r %d' % (table_name, key, len(val))) yield key, val num_yielded += 1 logger.debug('c* get: table_name=%r row_name=%r columns=%r start=%r finish=%r' % ( table_name, row_name, columns, start, finish)) ## prepare to page ahead to next batch if columns: break start = list(key) start[-1] = uuid.UUID(int=key[-1].int+1) assert len(start) == num_uuids start = join_uuids(*start) if start == prev_start or start > finish: break logger.debug('paging forward from %r to %r' % (prev_start, start)) ## We need to raise a not found exception if the caller asked for ## a specific column and we didn't yield any results if not columns and num_yielded == 0: raise pycassa.NotFoundException