Exemplo n.º 1
0
    def reshape(self, manifest: LocalFileManifest) -> LocalFileManifest:

        for block, source, destination, write_back, removed_ids in prepare_reshape(
                manifest):
            data = self.build_data(source)
            new_chunk = destination.evolve_as_block(data)
            if write_back:
                self.write_chunk(new_chunk, data)
            manifest = manifest.evolve_single_block(block, new_chunk)
            for removed_id in removed_ids:
                self.clear_chunk_data(removed_id)

        return manifest
Exemplo n.º 2
0
    async def _manifest_reshape(self,
                                manifest: LocalFileManifest,
                                cache_only: bool = False) -> List[BlockAccess]:
        """This internal helper does not perform any locking."""

        # Prepare data structures
        missing = []

        # Perform operations
        for block, source, destination, write_back, removed_ids in prepare_reshape(
                manifest):

            # Build data block
            data, extra_missing = await self._build_data(source)

            # Missing data
            if extra_missing:
                missing += extra_missing
                continue

            # Write data if necessary
            new_chunk = destination.evolve_as_block(data)
            if write_back:
                await self._write_chunk(new_chunk, data)

            # Craft the new manifest
            manifest = manifest.evolve_single_block(block, new_chunk)

            # Set the new manifest, acting as a checkpoint
            await self.local_storage.set_manifest(manifest.id,
                                                  manifest,
                                                  cache_only=True,
                                                  removed_ids=removed_ids)

        # Flush if necessary
        if not cache_only:
            await self.local_storage.ensure_manifest_persistent(manifest.id)

        # Return missing block ids
        return missing