Package org.syncany.database

Examples of org.syncany.database.VectorClock


    assertEquals("Expected clock value to be different.", 0L, (long) vc.getClock("NonExistingUnit"));
 
   
  @Test
  public void testToString() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitBBB", 5L);
    vc1.setClock("UnitAAA", 4L);
   
    assertEquals("Expected different serialization", "(UnitAAA4,UnitBBB5)", vc1.toString());
 
View Full Code Here


    assertEquals("Expected different serialization", "(UnitAAA4,UnitBBB5)", vc1.toString());
 
 
  @Test
  public void testClone() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);

    VectorClock vc2 = vc1.clone();
       
    assertEquals("Expected clock value of cloned clock to be different.", 4L, (long) vc2.getClock("UnitA"));
    assertEquals("Expected clock value of cloned clock to be different.", 5L, (long) vc2.getClock("UnitB"));
 
View Full Code Here

   */
  // TODO [medium] Do we still have to check for ">="? Isn't "=" enough? We should have full database branches here, because we stitch them before.
  private boolean isGreaterOrEqualDatabaseVersionHeaderInAllDatabaseBranches(DatabaseVersionHeader localDatabaseVersionHeader,
      DatabaseBranches remoteDatabaseVersionHeaders) {
   
    VectorClock localVectorClock = localDatabaseVersionHeader.getVectorClock();
    Set<String> remoteClients = remoteDatabaseVersionHeaders.getClients();

    for (String currentRemoteClient : remoteClients) {
      DatabaseBranch remoteBranch = remoteDatabaseVersionHeaders.getBranch(currentRemoteClient);
      boolean foundInCurrentClient = false;

      for (DatabaseVersionHeader remoteDatabaseVersionHeader : remoteBranch.getAll()) {
        VectorClock remoteVectorClock = remoteDatabaseVersionHeader.getVectorClock();
        VectorClockComparison remoteVsLocalVectorClockComparison = VectorClock.compare(remoteVectorClock, localVectorClock);

        if (remoteVsLocalVectorClockComparison == VectorClockComparison.GREATER
            || remoteVsLocalVectorClockComparison == VectorClockComparison.EQUAL) {

View Full Code Here

  private void completeBranchesWithDatabaseVersionHeaders(DatabaseBranches allBranches, Set<DatabaseVersionHeader> allHeaders) {
    for (String client : allBranches.getClients()) {
      DatabaseBranch clientBranch = allBranches.getBranch(client);
      if (clientBranch.size() > 0) {
        VectorClock lastVectorClock = clientBranch.getLast().getVectorClock();

        for (DatabaseVersionHeader databaseVersionHeader : allHeaders) {
          VectorClock currentVectorClock = databaseVersionHeader.getVectorClock();
          boolean isCurrentVectorClockSmaller = VectorClock.compare(currentVectorClock, lastVectorClock) == VectorClockComparison.SMALLER;
          boolean currentVectorClockExistsInBranch = clientBranch.get(currentVectorClock) != null;
          boolean isInConflict = VectorClock.compare(lastVectorClock, currentVectorClock) == VectorClockComparison.SIMULTANEOUS;

          if (!currentVectorClockExistsInBranch && isCurrentVectorClockSmaller && !isInConflict) {
View Full Code Here

      return new ArrayList<DatabaseRemoteFile>(remoteDatabaseFiles.values());
    }

    // At least one local database version exists
    else {
      VectorClock knownDatabaseVersions = lastLocalDatabaseVersionHeader.getVectorClock();

      for (DatabaseRemoteFile remoteDatabaseFile : remoteDatabaseFiles.values()) {
        String clientName = remoteDatabaseFile.getClientName();
        Long knownClientVersion = knownDatabaseVersions.getClock(clientName);

        // This does NOT filter 'lock' files!

        if (knownClientVersion != null) {
          if (remoteDatabaseFile.getClientVersion() <= knownClientVersion) {
View Full Code Here

  }

  private DatabaseVersion index(List<File> localFiles) throws FileNotFoundException, IOException {
    // Get last vector clock
    DatabaseVersionHeader lastDatabaseVersionHeader = localDatabase.getLastDatabaseVersionHeader();
    VectorClock lastVectorClock = (lastDatabaseVersionHeader != null) ? lastDatabaseVersionHeader.getVectorClock() : new VectorClock();

    // New vector clock
    VectorClock newVectorClock = findNewVectorClock(lastVectorClock);

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

    return newDatabaseVersion;
  }

  private VectorClock findNewVectorClock(VectorClock lastVectorClock) {
    VectorClock newVectorClock = lastVectorClock.clone();

    Long lastLocalValue = lastVectorClock.getClock(config.getMachineName());
    Long lastDirtyLocalValue = localDatabase.getMaxDirtyVectorClock(config.getMachineName());

    Long newLocalValue = null;

    if (lastDirtyLocalValue != null) {
      // TODO [medium] Does this lead to problems? C-1 does not exist! Possible problems with DatabaseReconciliator?
      newLocalValue = lastDirtyLocalValue + 1;
    }
    else {
      if (lastLocalValue != null) {
        newLocalValue = lastLocalValue + 1;
      }
      else {
        newLocalValue = 1L;
      }
    }

    newVectorClock.setClock(config.getMachineName(), newLocalValue);

    return newVectorClock;
  }
View Full Code Here

    MemoryDatabase winnerBranchDatabase = new MemoryDatabase();

    List<DatabaseVersionHeader> winnersApplyBranchList = winnersApplyBranch.getAll();
   
    String rangeClientName = null;
    VectorClock rangeVersionFrom = null;
    VectorClock rangeVersionTo = null;

    for (int i=0; i<winnersApplyBranchList.size(); i++) {
      DatabaseVersionHeader currentDatabaseVersionHeader = winnersApplyBranchList.get(i);
      DatabaseVersionHeader nextDatabaseVersionHeader = (i+1 < winnersApplyBranchList.size()) ? winnersApplyBranchList.get(i+1) : null;
     
View Full Code Here

 
          for (DatabaseVersionHeader muddyDatabaseVersionHeader : otherMuddyDatabaseVersionHeaders) {
            MemoryDatabase muddyMultiChunksDatabase = new MemoryDatabase();
           
            File localFileForMuddyDatabaseVersion = databaseFileList.getNextDatabaseVersionFile(muddyDatabaseVersionHeader);
            VectorClock fromVersion = muddyDatabaseVersionHeader.getVectorClock();
            VectorClock toVersion = muddyDatabaseVersionHeader.getVectorClock();
           
            logger.log(Level.INFO, "  - Loading " + muddyDatabaseVersionHeader + " from file " + localFileForMuddyDatabaseVersion);
            databaseSerializer.load(muddyMultiChunksDatabase, localFileForMuddyDatabaseVersion, fromVersion, toVersion, DatabaseReadType.FULL, DatabaseVersionType.DEFAULT, null);
           
            boolean hasMuddyMultiChunks = muddyMultiChunksDatabase.getMultiChunks().size() > 0;
View Full Code Here

    remoteTransaction.upload(tempPurgeFile, newPurgeRemoteFile);
  }

  private DatabaseVersion createPurgeDatabaseVersion(Map<FileHistoryId, FileVersion> mostRecentPurgeFileVersions) {
    DatabaseVersionHeader lastDatabaseVersionHeader = localDatabase.getLastDatabaseVersionHeader();
    VectorClock lastVectorClock = lastDatabaseVersionHeader.getVectorClock();

    VectorClock purgeVectorClock = lastVectorClock.clone();
    purgeVectorClock.incrementClock(config.getMachineName());

    DatabaseVersionHeader purgeDatabaseVersionHeader = new DatabaseVersionHeader();
    purgeDatabaseVersionHeader.setType(DatabaseVersionType.PURGE);
    purgeDatabaseVersionHeader.setDate(new Date());
    purgeDatabaseVersionHeader.setClient(config.getMachineName());
View Full Code Here

TOP

Related Classes of org.syncany.database.VectorClock

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.