def _calc_object_id(session_id, chunk_key): """ Calc unique object id for chunks """ from pyarrow.plasma import ObjectID key = '%s#%s' % (session_id, chunk_key) digest = hashlib.md5(to_binary(key)).digest() return ObjectID(digest + digest[:4])
def _new_object_id(self, session_id, chunk_key): """ Calc unique object id for chunks """ from pyarrow.plasma import ObjectID while True: new_id = ObjectID.from_random() if not self._plasma_client.contains(new_id): break self._mapper_ref.put(session_id, chunk_key, new_id) return new_id
def get_flight(self, object_id: plasma.ObjectID, location: str) -> paf.FlightStreamReader: """ Retreives an flight object stream """ descriptor = paf.FlightDescriptor.for_path( object_id.binary().hex().encode("utf-8")) logger.debug( f"connecting to {self._scheme}://{location} with descriptor {descriptor}" ) flight_client = paf.FlightClient(f"{self._scheme}://{location}", **self._connection_args) info = flight_client.get_flight_info(descriptor) for endpoint in info.endpoints: logger.debug("using endpoint locations %s", endpoint.locations) return flight_client.do_get(endpoint.ticket)
def exists(self, object_id: plasma.ObjectID, owner: Optional[str] = None) -> bool: """ Returns true if the remote plasmaflight server contains the plasma object. """ # check cache if self.plasma_client.contains(object_id): return True # check remote if owner is not None: client = paf.FlightClient(f"{self._scheme}://{owner}", **self._connection_args) try: info = client.get_flight_info( paf.FlightDescriptor.for_path( object_id.binary().hex().encode("utf-8"))) return True except paf.FlightError: return False return False
def object_id_to_equipment_id(object_id: plasma.ObjectID) -> str: """object_id转换为equipment_id的统一算法""" return str(object_id.binary().rstrip(b"_")) # 删除掉右边的_则还原为object_id