def is_empty(self): leftmost_leaf_name, rightmost_leaf_name = ( self._file_tree.get_leftmost_leaf(), self._file_tree.get_rightmost_leaf()) self.increment_rpc_count_by(n=2) if FileUtil.is_dir_empty( dir_name=leftmost_leaf_name) and FileUtil.is_dir_empty( dir_name=rightmost_leaf_name): return True else: return False
def is_empty(self): if self.is_updated(): self.sys_log("Tree updated, need force rebuilding the tree.") self._logger.info("Tree updated, need force rebuilding the tree.") self.initialize_from_dir(dir_name=self.get_dir_name(), force=True) leftmost_leaf_name, rightmost_leaf_name = ( self._file_tree.get_leftmost_leaf(), self._file_tree.get_rightmost_leaf()) if FileUtil.is_dir_empty( dir_name=leftmost_leaf_name) and FileUtil.is_dir_empty( dir_name=rightmost_leaf_name): return True else: return False
def resize_to_new_table(self, new_size_per_shard, new_dir_name): self.increment_rpc_count_by(n=2) assert not FileUtil.does_dir_exist(dir_name=new_dir_name) or FileUtil.is_dir_empty(dir_name=new_dir_name) new_sptable_storage = ShardedProtoTableStorage(size_per_shard=new_size_per_shard) new_sptable_storage.initialize_from_dir(dir_name=new_dir_name) for shard in range(self.get_num_shards()): related_proto_file = self._shard_to_file(shard=shard) proto_table = ProtoTableStorage() proto_table.initialize_from_file(file_name=related_proto_file) new_sptable_storage.write(data=proto_table.read_all()) self.increment_rpc_count_by(n=proto_table.get_rpc_call_count_and_reset()) return new_sptable_storage