Search in sources :

Example 1 with Deduper

use of org.syncany.chunk.Deduper in project syncany by syncany.

the class UpOperation method startIndexerThread.

private void startIndexerThread(BlockingQueue<DatabaseVersion> databaseVersionQueue) {
    // Get a list of files that have been updated
    ChangeSet localChanges = result.getStatusResult().getChangeSet();
    List<File> locallyUpdatedFiles = extractLocallyUpdatedFiles(localChanges);
    List<File> locallyDeletedFiles = extractLocallyDeletedFiles(localChanges);
    // Iterate over the changes, deduplicate, and feed DatabaseVersions into an iterator
    Deduper deduper = new Deduper(config.getChunker(), config.getMultiChunker(), config.getTransformer(), options.getTransactionSizeLimit(), options.getTransactionFileLimit());
    AsyncIndexer asyncIndexer = new AsyncIndexer(config, deduper, locallyUpdatedFiles, locallyDeletedFiles, databaseVersionQueue);
    new Thread(asyncIndexer, "AsyncI/" + config.getLocalDir().getName()).start();
}
Also used : Deduper(org.syncany.chunk.Deduper) ChangeSet(org.syncany.operations.ChangeSet) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile)

Example 2 with Deduper

use of org.syncany.chunk.Deduper in project syncany by syncany.

the class FrameworkCombinationTest method deduplicateAndCreateChunkIndex.

private ChunkIndex deduplicateAndCreateChunkIndex(final List<File> inputFiles, FrameworkCombination combination) throws IOException {
    logger.log(Level.INFO, "- Deduplicate and create chunk index ...");
    final ChunkIndex chunkIndex = new ChunkIndex();
    Deduper deduper = new Deduper(combination.chunker, combination.multiChunker, combination.transformer, Long.MAX_VALUE, Long.MAX_VALUE);
    deduper.deduplicate(inputFiles, new DeduperListener() {

        @Override
        public void onMultiChunkWrite(MultiChunk multiChunk, Chunk chunk) {
            logger.log(Level.INFO, "    - Adding chunk " + StringUtil.toHex(chunk.getChecksum()) + " to multichunk " + multiChunk.getId() + " ...");
            chunkIndex.chunkIDToMultiChunkID.put(new ChunkChecksum(chunk.getChecksum()), multiChunk.getId());
        }

        @Override
        public void onFileAddChunk(File file, Chunk chunk) {
            logger.log(Level.INFO, "    - Adding chunk " + StringUtil.toHex(chunk.getChecksum()) + " to inputFileToChunkIDs-map for file " + file + " ...");
            List<ChunkChecksum> chunkIDsForFile = chunkIndex.inputFileToChunkIDs.get(file);
            if (chunkIDsForFile == null) {
                chunkIDsForFile = new ArrayList<ChunkChecksum>();
            }
            chunkIDsForFile.add(new ChunkChecksum(chunk.getChecksum()));
            chunkIndex.inputFileToChunkIDs.put(file, chunkIDsForFile);
        }

        @Override
        public boolean onChunk(Chunk chunk) {
            if (chunkIndex.chunkIDToMultiChunkID.containsKey(new ChunkChecksum(chunk.getChecksum()))) {
                logger.log(Level.INFO, "  + Known chunk " + StringUtil.toHex(chunk.getChecksum()));
                return false;
            } else {
                logger.log(Level.INFO, "  + New chunk " + StringUtil.toHex(chunk.getChecksum()));
                return true;
            }
        }

        @Override
        public File getMultiChunkFile(MultiChunkId multiChunkId) {
            File outputMultiChunk = new File(tempDir + "/multichunk-" + multiChunkId);
            chunkIndex.outputMultiChunkFiles.add(outputMultiChunk);
            return outputMultiChunk;
        }

        @Override
        public MultiChunkId createNewMultiChunkId(Chunk firstChunk) {
            // Note: In the real implementation, this should be random
            return new MultiChunkId(firstChunk.getChecksum());
        }

        @Override
        public boolean onFileFilter(File file) {
            return true;
        }

        @Override
        public boolean onFileStart(File file) {
            return file.isFile() && !FileUtil.isSymlink(file);
        }

        @Override
        public void onFileEnd(File file, byte[] checksum) {
        // Empty
        }

        @Override
        public void onMultiChunkOpen(MultiChunk multiChunk) {
        // Empty
        }

        @Override
        public void onMultiChunkClose(MultiChunk multiChunk) {
        // Empty
        }

        @Override
        public void onStart(int fileCount) {
        // Empty
        }

        @Override
        public void onFinish() {
        // Empty
        }
    });
    return chunkIndex;
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) ArrayList(java.util.ArrayList) MultiChunk(org.syncany.chunk.MultiChunk) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) Chunk(org.syncany.chunk.Chunk) MultiChunk(org.syncany.chunk.MultiChunk) Deduper(org.syncany.chunk.Deduper) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File) DeduperListener(org.syncany.chunk.DeduperListener)

Aggregations

File (java.io.File)2 Deduper (org.syncany.chunk.Deduper)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Chunk (org.syncany.chunk.Chunk)1 DeduperListener (org.syncany.chunk.DeduperListener)1 MultiChunk (org.syncany.chunk.MultiChunk)1 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)1 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)1 ChangeSet (org.syncany.operations.ChangeSet)1 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)1 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)1 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)1