def time_decode(self, num_data, num_parity, ec_type, hd, file_size, iterations): """ :return 2-tuple, (success, average decode time) """ timer = Timer() tsum = 0 handle = pyeclib_c.init(num_data, num_parity, ec_type, hd) whole_file_bytes = self.get_tmp_file(file_size).read() success = True fragments = pyeclib_c.encode(handle, whole_file_bytes) orig_fragments = fragments[:] for i in range(iterations): missing_idxs = [] num_missing = hd - 1 for j in range(num_missing): num_frags_left = len(fragments) idx = random.randint(0, num_frags_left - 1) fragments.pop(idx) timer.start() decoded_file_bytes = pyeclib_c.decode(handle, fragments, len(fragments[0])) tsum += timer.stop_and_return() fragments = orig_fragments[:] if whole_file_bytes != decoded_file_bytes: success = False return success, tsum / iterations
def decode(self, fragment_payloads, ranges=None, force_metadata_checks=False): fragment_len = self._validate_and_return_fragment_size( fragment_payloads) if fragment_len < 0: raise ECPyECLibException( "Invalid fragment payload in ECPyECLibDriver.decode") if len(fragment_payloads) < self.k: raise ECPyECLibException( "Not enough fragments given in ECPyECLibDriver.decode") try: ret = pyeclib_c.decode(self.handle, fragment_payloads, fragment_len, ranges, force_metadata_checks) except PyECLibError as e: raise ECPyECLibException(e) # Was there an error decoding if ret is None: raise ECPyECLibException( "Error decoding from fragments in ECPyECLibDriver.decode") return ret
def decode(self, fragment_payloads, ranges=None, force_metadata_checks=False): fragment_len = self._validate_and_return_fragment_size( fragment_payloads) if fragment_len < 0: raise ECDriverError( "Invalid fragment payload in ECPyECLibDriver.decode") if len(fragment_payloads) < self.k: raise ECInsufficientFragments( "Not enough fragments given in ECPyECLibDriver.decode") return pyeclib_c.decode(self.handle, fragment_payloads, fragment_len, ranges, force_metadata_checks)
def decode(self, fragment_payloads, ranges=None, force_metadata_checks=False): _fragment_payloads = list(fragment_payloads) fragment_len = self._validate_and_return_fragment_size( _fragment_payloads) if fragment_len < 0: raise ECDriverError( "Invalid fragment payload in ECPyECLibDriver.decode") if len(_fragment_payloads) < self.k: raise ECInsufficientFragments( "Not enough fragments given in ECPyECLibDriver.decode") return pyeclib_c.decode(self.handle, _fragment_payloads, fragment_len, ranges, force_metadata_checks)
def time_range_decode(self, num_data, num_parity, ec_type, hd, file_size, iterations): """ :return 2-tuple, (success, average decode time) """ timer = Timer() tsum = 0 handle = pyeclib_c.init(num_data, num_parity, ec_type, hd) whole_file_bytes = self.get_tmp_file(file_size).read() success = True begins = [ long(random.randint(0, len(whole_file_bytes) - 1)) for i in range(3) ] ends = [ long(random.randint(begins[i], len(whole_file_bytes))) for i in range(3) ] ranges = zip(begins, ends) fragments = pyeclib_c.encode(handle, whole_file_bytes) orig_fragments = fragments[:] for i in range(iterations): missing_idxs = [] num_missing = hd - 1 for j in range(num_missing): num_frags_left = len(fragments) idx = random.randint(0, num_frags_left - 1) fragments.pop(idx) timer.start() decoded_file_ranges = pyeclib_c.decode(handle, fragments, len(fragments[0]), ranges) tsum += timer.stop_and_return() fragments = orig_fragments[:] range_offset = 0 for r in ranges: if whole_file_bytes[r[0]:r[1] + 1] != decoded_file_ranges[range_offset]: success = False range_offset += 1 return success, tsum / iterations
def time_range_decode(self, num_data, num_parity, ec_type, hd, file_size, iterations): """ :return 2-tuple, (success, average decode time) """ timer = Timer() tsum = 0 handle = pyeclib_c.init(num_data, num_parity, ec_type, hd) whole_file_bytes = self.get_tmp_file(file_size).read() success = True begins = [int(random.randint(0, len(whole_file_bytes) - 1)) for i in range(3)] ends = [int(random.randint(begins[i], len(whole_file_bytes))) for i in range(3)] ranges = list(zip(begins, ends)) fragments = pyeclib_c.encode(handle, whole_file_bytes) orig_fragments = fragments[:] for i in range(iterations): num_missing = hd - 1 for j in range(num_missing): num_frags_left = len(fragments) idx = random.randint(0, num_frags_left - 1) fragments.pop(idx) timer.start() decoded_file_ranges = pyeclib_c.decode(handle, fragments, len(fragments[0]), ranges) tsum += timer.stop_and_return() fragments = orig_fragments[:] range_offset = 0 for r in ranges: if whole_file_bytes[ r[0]: r[1] + 1] != decoded_file_ranges[range_offset]: success = False range_offset += 1 return success, tsum / iterations