Search in sources :

Example 26 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class DownOperation method applyChangesAndPersistDatabase.

private void applyChangesAndPersistDatabase(MemoryDatabase winnersDatabase, boolean cleanupOccurred, List<PartialFileHistory> preDeleteFileHistoriesWithLastVersion) throws Exception {
    if (options.isApplyChanges()) {
        new ApplyChangesOperation(config, localDatabase, transferManager, winnersDatabase, result, cleanupOccurred, preDeleteFileHistoriesWithLastVersion).execute();
    } else {
        logger.log(Level.INFO, "Doing nothing on the file system, because --no-apply switched on");
    }
    // We only persist the versions that we have already applied.
    DatabaseBranch currentApplyBranch = new DatabaseBranch();
    for (DatabaseVersion databaseVersion : winnersDatabase.getDatabaseVersions()) {
        currentApplyBranch.add(databaseVersion.getHeader());
    }
    persistDatabaseVersions(currentApplyBranch, winnersDatabase);
    localDatabase.commit();
}
Also used : DatabaseVersion(org.syncany.database.DatabaseVersion)

Example 27 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class LogOperation method execute.

@Override
public LogOperationResult execute() throws Exception {
    logger.log(Level.INFO, "");
    logger.log(Level.INFO, "Running 'Log' at client " + config.getMachineName() + " ...");
    logger.log(Level.INFO, "--------------------------------------------");
    ArrayList<LightweightDatabaseVersion> databaseVersions = new ArrayList<>();
    Iterator<DatabaseVersion> databaseVersionsIterator = localDatabase.getLastDatabaseVersions(options.getMaxDatabaseVersionCount(), options.getStartDatabaseVersionIndex(), options.getMaxFileHistoryCount());
    while (databaseVersionsIterator.hasNext()) {
        DatabaseVersion databaseVersion = databaseVersionsIterator.next();
        LightweightDatabaseVersion lightweightDatabaseVersion = createLightweightDatabaseVersion(databaseVersion);
        databaseVersions.add(lightweightDatabaseVersion);
    }
    return new LogOperationResult(databaseVersions);
}
Also used : ArrayList(java.util.ArrayList) DatabaseVersion(org.syncany.database.DatabaseVersion)

Example 28 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class Indexer method indexWithNewFiles.

private void indexWithNewFiles(List<File> files, List<File> deletedFiles, Queue<DatabaseVersion> databaseVersionQueue) throws IOException {
    boolean isFirstFile = true;
    int filesCount = files.size();
    while (!files.isEmpty()) {
        DatabaseVersion newDatabaseVersion = new DatabaseVersion();
        // Create the DeduperListener that will receive MultiChunks and store them in the DatabaseVersion object
        DeduperListener deduperListener = new IndexerDeduperListener(newDatabaseVersion);
        // Signal the start of indexing if we are about to deduplicate the first file
        if (isFirstFile) {
            deduperListener.onStart(files.size());
            // Add deletions in first database version
            removeDeletedFiles(newDatabaseVersion, deletedFiles);
            isFirstFile = false;
        }
        // Find and index new files
        deduper.deduplicate(files, deduperListener);
        if (!newDatabaseVersion.getFileHistories().isEmpty()) {
            logger.log(Level.FINE, "Processed new database version: " + newDatabaseVersion);
            databaseVersionQueue.offer(newDatabaseVersion);
            int remainingFilesCount = filesCount - files.size();
            eventBus.post(new UpIndexMidSyncExternalEvent(config.getLocalDir().toString(), filesCount, remainingFilesCount));
        }
    //else { (comment-only else case)
    // Just chunks and multichunks, no filehistory. Since this means the file was being
    // written/vanished during operations, it makes no sense to upload it. If the user
    // wants it indexed, Up can be run again.
    //}
    }
}
Also used : UpIndexMidSyncExternalEvent(org.syncany.operations.daemon.messages.UpIndexMidSyncExternalEvent) DatabaseVersion(org.syncany.database.DatabaseVersion) DeduperListener(org.syncany.chunk.DeduperListener)

Example 29 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class Indexer method indexWithoutNewFiles.

private void indexWithoutNewFiles(List<File> files, List<File> deletedFiles, Queue<DatabaseVersion> databaseVersionQueue) {
    DatabaseVersion newDatabaseVersion = new DatabaseVersion();
    removeDeletedFiles(newDatabaseVersion, deletedFiles);
    logger.log(Level.FINE, "Added database version with only deletions: " + newDatabaseVersion);
    databaseVersionQueue.offer(newDatabaseVersion);
}
Also used : DatabaseVersion(org.syncany.database.DatabaseVersion)

Example 30 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class DatabaseVersionDaoTest method testPersistDatabaseVersion.

@Test
public void testPersistDatabaseVersion() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
    FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
    DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
    // a. Capture database version header (now)
    DatabaseVersionHeader lastDatabaseVersionHeaderBefore = databaseVersionDao.getLastDatabaseVersionHeader();
    // b. Add new database header (with one file history)
    DatabaseVersion newDatabaseVersion = new DatabaseVersion();
    DatabaseVersionHeader newDatabaseVersionHeader = new DatabaseVersionHeader();
    newDatabaseVersionHeader.setClient("C");
    newDatabaseVersionHeader.setDate(new Date(1489977288000L));
    newDatabaseVersionHeader.setVectorClock(TestDatabaseUtil.createVectorClock("A5,C1"));
    newDatabaseVersion.setHeader(newDatabaseVersionHeader);
    PartialFileHistory newFileHistory = new PartialFileHistory(FileHistoryId.secureRandomFileId());
    FileVersion newFileVersion = new FileVersion();
    newFileVersion.setVersion(1L);
    newFileVersion.setPath("newfile");
    newFileVersion.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
    newFileVersion.setLinkTarget(null);
    newFileVersion.setPosixPermissions("rwxrwxrwx");
    newFileVersion.setDosAttributes(null);
    newFileVersion.setStatus(FileStatus.NEW);
    newFileVersion.setLastModified(new Date());
    newFileVersion.setUpdated(new Date());
    newFileVersion.setSize(1L);
    newFileVersion.setType(FileType.FILE);
    newFileHistory.addFileVersion(newFileVersion);
    newDatabaseVersion.addFileHistory(newFileHistory);
    ChunkEntry newChunkEntry = new ChunkEntry(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), 1);
    newDatabaseVersion.addChunk(newChunkEntry);
    MultiChunkEntry newMultiChunkEntry = new MultiChunkEntry(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"), 10);
    newMultiChunkEntry.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addMultiChunk(newMultiChunkEntry);
    FileContent newFileContent = new FileContent();
    newFileContent.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
    newFileContent.setSize(1L);
    newFileContent.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addFileContent(newFileContent);
    // c. Persist database version
    databaseVersionDao.writeDatabaseVersion(newDatabaseVersion);
    // d. Capture new last database version header
    DatabaseVersionHeader lastDatabaseVersionHeaderAfter = databaseVersionDao.getLastDatabaseVersionHeader();
    // Test
    assertNotNull(lastDatabaseVersionHeaderBefore);
    assertEquals("A/(A5)/T=1388935689000", lastDatabaseVersionHeaderBefore.toString());
    assertNotNull(lastDatabaseVersionHeaderAfter);
    assertEquals("C/(A5,C1)/T=1489977288000", lastDatabaseVersionHeaderAfter.toString());
    assertEquals(newDatabaseVersionHeader.getVectorClock(), lastDatabaseVersionHeaderAfter.getVectorClock());
    assertEquals(newChunkEntry, chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f")));
    assertEquals(newFileContent, fileContentDao.getFileContent(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), true));
    Map<MultiChunkId, MultiChunkEntry> multiChunkIds = multiChunkDao.getMultiChunks(newDatabaseVersionHeader.getVectorClock());
    assertNotNull(multiChunkIds);
    assertEquals(1, multiChunkIds.size());
    MultiChunkEntry actualNewMultiChunkEntry = multiChunkIds.get(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"));
    assertNotNull(actualNewMultiChunkEntry);
    assertEquals(newMultiChunkEntry.getId(), actualNewMultiChunkEntry.getId());
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Date(java.util.Date) PartialFileHistory(org.syncany.database.PartialFileHistory) FileContent(org.syncany.database.FileContent) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) ChunkEntry(org.syncany.database.ChunkEntry) MultiChunkEntry(org.syncany.database.MultiChunkEntry) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileVersion(org.syncany.database.FileVersion) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) MultiChunkEntry(org.syncany.database.MultiChunkEntry) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Aggregations

DatabaseVersion (org.syncany.database.DatabaseVersion)43 Test (org.junit.Test)22 MemoryDatabase (org.syncany.database.MemoryDatabase)20 MultiChunkEntry (org.syncany.database.MultiChunkEntry)12 PartialFileHistory (org.syncany.database.PartialFileHistory)12 ChunkEntry (org.syncany.database.ChunkEntry)11 FileVersion (org.syncany.database.FileVersion)10 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)9 ArrayList (java.util.ArrayList)8 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)8 File (java.io.File)7 Config (org.syncany.config.Config)7 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)6 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)6 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)6 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)6 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)6 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)6 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)6 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6