Exemplo n.º 1
0
 def _send_sync_content(self, impl_ctx, item):
     assert isinstance(impl_ctx, TransmitLeader.ImplContext)
     req = dj_pb.SyncPartitionRequest(
         data_source_meta=self._data_source.data_source_meta,
         rank_id=self._rank_id,
         sync_content=self._make_sync_content(item))
     rsp = self._peer_client.SyncPartition(req)
     if rsp.status.code != 0:
         raise RuntimeError("Peer of {} refuse item. reason: {},".format(
             self._repr_str, rsp.status.error_message))
     self._update_peer_index(impl_ctx, rsp.next_index, rsp.dumped_index)
Exemplo n.º 2
0
 def _send_sync_content(self, impl_ctx, item):
     assert isinstance(impl_ctx, TransmitLeader.ImplContext)
     compressed = False
     sync_ctnt = self._serialize_sync_content(item)
     if len(sync_ctnt) > (2 << 20):
         compressed_bytes = zlib.compress(sync_ctnt, 5)
         if len(compressed_bytes) < len(sync_ctnt) * 0.8:
             sync_ctnt = compressed_bytes
             compressed = True
         else:
             logging.warning(
                 'abandon compressed since compress ratio < 0.8')
     req = dj_pb.SyncPartitionRequest(
         data_source_meta=self._data_source.data_source_meta,
         rank_id=self._rank_id,
         content_bytes=sync_ctnt,
         compressed=compressed)
     rsp = self._peer_client.SyncPartition(req)
     if rsp.status.code != 0:
         raise RuntimeError("Peer of {} refuse item. reason: {},".format(
             self._repr_str, rsp.status.error_message))
     self._update_peer_index(impl_ctx, rsp.next_index, rsp.dumped_index)