Package org.syncany.database

Examples of org.syncany.database.DatabaseVersion


    deletedFolderVersion.setVersion(deletedFolderVersion.getVersion()+1);
   
    PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
    deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
   
    DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());   
    winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
   
    // - Create memory database with this version
    MemoryDatabase winnersDatabase = new MemoryDatabase();
    winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
   
View Full Code Here


  @Test
  public void testRemoveDatabaseVersion() {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    // - history 1, version 1
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file.jpg");

    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);

    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);

    database.addDatabaseVersion(databaseVersion1);
   
    // - history 1, version 2   
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file.jpg", fileVersion1);

    FileHistoryId idFile1b = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1b = new PartialFileHistory(idFile1b);

    fileHistory1b.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory1b);

    database.addDatabaseVersion(databaseVersion2);
       
    // Tests: Database should have 2 versions of file
    assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
View Full Code Here

    List<DatabaseVersion> readDatabaseVersions = actualDatabase.getDatabaseVersions();
   
    assertEquals("Different number of database versions.", writtenDatabaseVersions.size(), readDatabaseVersions.size());
     
    for (DatabaseVersion writtenDatabaseVersion : writtenDatabaseVersions) {
      DatabaseVersion readDatabaseVersion = null;
     
      for (DatabaseVersion aReadDatabaseVersion : readDatabaseVersions) {
        if (aReadDatabaseVersion.equals(writtenDatabaseVersion)) {
          readDatabaseVersion = aReadDatabaseVersion;
          break;
View Full Code Here

    ChangeSet localChanges = result.getStatusResult().getChangeSet();
    List<File> locallyUpdatedFiles = extractLocallyUpdatedFiles(localChanges);

    // Index
    DatabaseVersion newDatabaseVersion = index(locallyUpdatedFiles);

    if (newDatabaseVersion.getFileHistories().size() == 0) {
      logger.log(Level.INFO, "Local database is up-to-date. NOTHING TO DO!");
      result.setResultCode(UpResultCode.OK_NO_CHANGES);
     
      finishOperation();
      fireEndEvent();

      return result;
    }
   
    // Upload multichunks
    logger.log(Level.INFO, "Uploading new multichunks ...");
    addMultiChunksToTransaction(newDatabaseVersion.getMultiChunks());   

    // Create delta database and commit transaction
    writeAndAddDeltaDatabase(newDatabaseVersion);
    remoteTransaction.commit();

    // Save local database
    logger.log(Level.INFO, "Persisting local SQL database (new database version {0}) ...", newDatabaseVersion.getHeader().toString());
    long newDatabaseVersionId = localDatabase.persistDatabaseVersion(newDatabaseVersion);

    logger.log(Level.INFO, "Removing DIRTY database versions from database ...");
    localDatabase.removeDirtyDatabaseVersions(newDatabaseVersionId);
View Full Code Here

    return true;
  }

  private void writeAndAddDeltaDatabase(DatabaseVersion newDatabaseVersion) throws InterruptedException, StorageException, IOException {
    // Clone database version (necessary, because the original must not be touched)
    DatabaseVersion deltaDatabaseVersion = newDatabaseVersion.clone();

    // Add dirty data (if existent)
    addDirtyData(deltaDatabaseVersion);

    // New delta database
    MemoryDatabase deltaDatabase = new MemoryDatabase();
    deltaDatabase.addDatabaseVersion(deltaDatabaseVersion);

    // Save delta database locally
    long newestLocalDatabaseVersion = deltaDatabaseVersion.getVectorClock().getClock(config.getMachineName());
    DatabaseRemoteFile remoteDeltaDatabaseFile = new DatabaseRemoteFile(config.getMachineName(), newestLocalDatabaseVersion);
    File localDeltaDatabaseFile = config.getCache().getDatabaseFile(remoteDeltaDatabaseFile.getName());

    logger.log(Level.INFO, "Saving local delta database, version {0} to file {1} ... ", new Object[] { deltaDatabaseVersion.getHeader(),
        localDeltaDatabaseFile });

    saveDeltaDatabase(deltaDatabase, localDeltaDatabaseFile);

    // Upload delta database
View Full Code Here

    }
    else {
      logger.log(Level.INFO, "Adding DIRTY data to new database version: ");

      while (dirtyDatabaseVersions.hasNext()) {
        DatabaseVersion dirtyDatabaseVersion = dirtyDatabaseVersions.next();

        logger.log(Level.INFO, "- Adding chunks/multichunks/filecontents from database version " + dirtyDatabaseVersion.getHeader());

        for (ChunkEntry chunkEntry : dirtyDatabaseVersion.getChunks()) {
          newDatabaseVersion.addChunk(chunkEntry);
        }

        for (MultiChunkEntry multiChunkEntry : dirtyDatabaseVersion.getMultiChunks()) {
          newDatabaseVersion.addMultiChunk(multiChunkEntry);
        }

        for (FileContent fileContent : dirtyDatabaseVersion.getFileContents()) {
          newDatabaseVersion.addFileContent(fileContent);
        }
      }
    }
  }
View Full Code Here

    // Index
    Deduper deduper = new Deduper(config.getChunker(), config.getMultiChunker(), config.getTransformer());
    Indexer indexer = new Indexer(config, deduper);

    DatabaseVersion newDatabaseVersion = indexer.index(localFiles);

    newDatabaseVersion.setVectorClock(newVectorClock);
    newDatabaseVersion.setTimestamp(new Date());
    newDatabaseVersion.setClient(config.getMachineName());

    return newDatabaseVersion;
  }
View Full Code Here

   * {@link SqlDatabase#persistDatabaseVersion(DatabaseVersion)}.
   */
  private void persistDatabaseVersion(MemoryDatabase winnersDatabase, DatabaseVersionHeader currentDatabaseVersionHeader) {
    logger.log(Level.INFO, "  + Applying database version " + currentDatabaseVersionHeader.getVectorClock());

    DatabaseVersion applyDatabaseVersion = winnersDatabase.getDatabaseVersion(currentDatabaseVersionHeader.getVectorClock());       
    localDatabase.persistDatabaseVersion(applyDatabaseVersion);
  }
View Full Code Here

   * of the leftover unreferenced database entities (unmapped chunks, multichunks, file contents).
   */
  private void persistPurgeDatabaseVersion(MemoryDatabase winnersPurgeDatabase, DatabaseVersionHeader currentDatabaseVersionHeader) throws SQLException {
    logger.log(Level.INFO, "  + Applying PURGE database version " + currentDatabaseVersionHeader.getVectorClock());

    DatabaseVersion purgeDatabaseVersion = winnersPurgeDatabase.getDatabaseVersion(currentDatabaseVersionHeader.getVectorClock());
    Map<FileHistoryId, FileVersion> purgeFileVersions = new HashMap<FileHistoryId, FileVersion>();
   
    for (PartialFileHistory purgeFileHistory : purgeDatabaseVersion.getFileHistories()) {
      logger.log(Level.INFO, "     - Purging file history {0}, with versions <= {1}", new Object[] {
          purgeFileHistory.getFileHistoryId().toString(), purgeFileHistory.getLastVersion() });
     
      purgeFileVersions.put(purgeFileHistory.getFileHistoryId(), purgeFileHistory.getLastVersion());       
    }
   
    localDatabase.removeSmallerOrEqualFileVersions(purgeFileVersions);
    localDatabase.removeUnreferencedDatabaseEntities();
    localDatabase.writeDatabaseVersionHeader(purgeDatabaseVersion.getHeader());   
   
    localDatabase.commit(); // TODO [medium] Harmonize commit behavior   
  }
View Full Code Here

    // Local: First, remove file versions that are not longer needed
    localDatabase.removeSmallerOrEqualFileVersions(purgeFileVersions);

    // Local: Then, determine what must be changed remotely and remove it locally
    Map<MultiChunkId, MultiChunkEntry> unusedMultiChunks = localDatabase.getUnusedMultiChunks();
    DatabaseVersion purgeDatabaseVersion = createPurgeDatabaseVersion(purgeFileVersions);

    localDatabase.removeUnreferencedDatabaseEntities();
    localDatabase.persistPurgeDatabaseVersion(purgeDatabaseVersion);   

    // Remote: serialize purge database version to file and upload
    DatabaseRemoteFile newPurgeRemoteFile = findNewPurgeRemoteFile(purgeDatabaseVersion.getHeader());
    File tempLocalPurgeDatabaseFile = writePurgeFile(purgeDatabaseVersion, newPurgeRemoteFile);

    addPurgeFileToTransaction(tempLocalPurgeDatabaseFile, newPurgeRemoteFile);
    remoteDeleteUnusedMultiChunks(unusedMultiChunks);
View Full Code Here

TOP

Related Classes of org.syncany.database.DatabaseVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.