def get(self, name, tag, idx=-1): algorithm, sub_name = self.__check_authorization(name, is_send=False) auth_dict = self.trans_conf.get(algorithm) src_role = auth_dict.get(sub_name).get('src') src_party_ids = self.__get_parties(src_role) if 0 <= idx < len(src_party_ids): # idx is specified, return the remote object party_ids = [src_party_ids[idx]] else: # idx is not valid, return remote object list party_ids = src_party_ids _status_table = _get_meta_table(STATUS_TABLE_NAME, self.job_id) LOGGER.debug("[GET] {} {} getting remote object {} from {} {}".format( self.role, self.party_id, tag, src_role, party_ids)) tasks = [] for party_id in party_ids: _tagged_key = self.__remote__object_key(self.job_id, name, tag, src_role, party_id, self.role, self.party_id) tasks.append(check_status_and_get_value(_status_table, _tagged_key)) results = self._loop.run_until_complete(asyncio.gather(*tasks)) rtn = [] _object_table = _get_meta_table(OBJECT_STORAGE_NAME, self.job_id) for r in results: if isinstance(r, tuple): _persistent = r[0] == StoreType.LMDB rtn.append(Standalone.get_instance().table( name=r[1], namespace=r[2], persistent=_persistent, partition=r[3])) else: rtn.append(_object_table.get(r)) if 0 <= idx < len(src_party_ids): return rtn[0] return rtn
def get(self, name: str, tag: str, parties: Union[Party, list]) -> Tuple[list, Rubbish]: if isinstance(parties, Party): parties = [parties] self._get_side_auth(name=name, parties=parties) _status_table = _get_meta_table(STATUS_TABLE_NAME, self._session_id) LOGGER.debug( f"[GET] {self._local_party} getting {name}.{tag} from {parties}") tasks = [] for party in parties: _tagged_key = self.__remote__object_key(self._session_id, name, tag, party.role, party.party_id, self._role, self._party_id) tasks.append(check_status_and_get_value(_status_table, _tagged_key)) results = self._loop.run_until_complete(asyncio.gather(*tasks)) rtn = [] rubbish = Rubbish(name, tag) _object_table = _get_meta_table(OBJECT_STORAGE_NAME, self._session_id) for r in results: LOGGER.debug( f"[GET] {self._local_party} getting {r} from {parties}") if isinstance(r, tuple): _persistent = r[0] == StoreType.LMDB table = Standalone.get_instance().table(name=r[1], namespace=r[2], persistent=_persistent, partition=r[3]) rtn.append(table) rubbish.add_table(table) else: # todo: should standalone mode split large object? obj = _object_table.get(r) rtn.append(obj) rubbish.add_obj(_object_table, r) rubbish.add_obj(_status_table, r) return rtn, rubbish
def _get_meta_table(_name, _job_id): return Standalone.get_instance().table(_name, _job_id, partition=10)