/** * Compares the two given database versions headers and returns -1, 0 or 1 depending on * which header is considered larger. See {@link DatabaseVersionHeaderComparator class description} * for details regarding the precedence. * * @return -1 if dbvh1 is smaller than dbvh2, 0 if they are equal, 1 if dbvh1 is greater than dbvh2 */ @Override public int compare(DatabaseVersionHeader dbvh1, DatabaseVersionHeader dbvh2) { return compareByVectorClock(dbvh1, dbvh2); }
public DatabaseFileReader(DatabaseXmlSerializer databaseSerializer, DatabaseBranch winnersApplyBranch, Map<DatabaseVersionHeader, File> databaseVersionLocations) { this.winnersApplyBranchList = winnersApplyBranch.getAll(); this.databaseVersionLocations = databaseVersionLocations; this.databaseSerializer = databaseSerializer; }
@Override public DatabaseBranch clone() { DatabaseBranch clonedBranch = new DatabaseBranch(); clonedBranch.addAll(getAll()); return clonedBranch; }
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(); }
@Override public OperationResult execute() throws Exception { logger.log(Level.INFO, "Determine file system actions ..."); FileSystemActionReconciliator actionReconciliator = new FileSystemActionReconciliator(config, result.getChangeSet()); List<FileSystemAction> actions; if (cleanupOccurred) { actions = actionReconciliator.determineFileSystemActions(winnersDatabase, true, preDeleteFileHistoriesWithLastVersion); } else { actions = actionReconciliator.determineFileSystemActions(winnersDatabase); } Set<MultiChunkId> unknownMultiChunks = determineRequiredMultiChunks(actions, winnersDatabase); downloader.downloadAndDecryptMultiChunks(unknownMultiChunks); result.getDownloadedMultiChunks().addAll(unknownMultiChunks); applyFileSystemActions(actions); return null; }
public DownOperationResult down(DownOperationOptions options) throws Exception { return new DownOperation(config, options).execute(); }
public DatabaseBranch findLosersPruneBranch(DatabaseBranch losersBranch, DatabaseBranch winnersBranch) { DatabaseBranch losersPruneBranch = new DatabaseBranch(); boolean pruneBranchStarted = false; for (int i = 0; i < losersBranch.size(); i++) { if (pruneBranchStarted) { losersPruneBranch.add(losersBranch.get(i)); } else if (i < winnersBranch.size() && !losersBranch.get(i).equals(winnersBranch.get(i))) { pruneBranchStarted = true; losersPruneBranch.add(losersBranch.get(i)); } } return losersPruneBranch; }
private List<DatabaseVersionHeader> sortBranches(DatabaseBranches allBranches) { List<DatabaseVersionHeader> databaseVersionHeaders = new ArrayList<DatabaseVersionHeader>(); for (String client : allBranches.getClients()) { databaseVersionHeaders.addAll(allBranches.getBranch(client).getAll()); } Collections.sort(databaseVersionHeaders, new DatabaseVersionHeaderComparator(true)); return databaseVersionHeaders; } }
public static DatabaseBranch createBranch(String[] databaseVersionHeaderStrings) throws Exception { DatabaseBranch branch = new DatabaseBranch(); for (String databaseVersionHeaderString : databaseVersionHeaderStrings) { DatabaseVersionHeader databaseVersionHeader = createFromString(databaseVersionHeaderString); branch.add(databaseVersionHeader); } return branch; }
public DownOperation(Config config) { this(config, new DownOperationOptions()); }
@Override public int compare(FileSystemAction a1, FileSystemAction a2) { int a1Position = determinePosition(a1); int a2Position = determinePosition(a2); if (a1Position > a2Position) { return 1; } else if (a1Position < a2Position) { return -1; } return compareByFullName(a1, a2); }
/** * Persists the given winners branch to the local database, i.e. for every database version * in the winners branch, all contained multichunks, chunks, etc. are added to the local SQL * database. * * <p>This method applies both regular database versions as well as purge database versions. */ private void persistDatabaseVersions(DatabaseBranch winnersApplyBranch, MemoryDatabase winnersDatabase) throws SQLException { // Add winners database to local database // Note: This must happen AFTER the file system stuff, because we compare the winners database with the local database! logger.log(Level.INFO, "- Adding database versions to SQL database ..."); for (DatabaseVersionHeader currentDatabaseVersionHeader : winnersApplyBranch.getAll()) { persistDatabaseVersion(winnersDatabase, currentDatabaseVersionHeader); } }
public DatabaseBranch getBranch(String client, boolean createIfNotExistant) { DatabaseBranch branch = branches.get(client); if (branch == null && createIfNotExistant) { branch = new DatabaseBranch(); branches.put(client, branch); } return branch; }
public DownOperation(Config config, DownOperationOptions options) { super(config, ACTION_ID); this.options = options; this.result = new DownOperationResult(); this.localDatabase = new SqlDatabase(config); this.databaseReconciliator = new DatabaseReconciliator(); this.databaseSerializer = new DatabaseXmlSerializer(config.getTransformer()); }
public DatabaseBranch getBranch(String client) { return getBranch(client, false); }
@Override public DatabaseBranches clone() { DatabaseBranches clonedBranches = new DatabaseBranches(); clonedBranches.branches.putAll(branches); return clonedBranches; } }
public List<FileSystemAction> determineFileSystemActions(MemoryDatabase winnersDatabase) throws Exception { List<PartialFileHistory> localFileHistoriesWithLastVersion = localDatabase.getFileHistoriesWithLastVersion(); return determineFileSystemActions(winnersDatabase, false, localFileHistoriesWithLastVersion); }
/** * This method queries the local database and compares the result to existing remoteCleanupFiles to determine * if cleanup has occurred since the last time it was locally handled. The cleanupNumber is a simple count. */ private boolean cleanupOccurred(Map<String, CleanupRemoteFile> remoteCleanupFiles) throws Exception { Long lastRemoteCleanupNumber = getLastRemoteCleanupNumber(remoteCleanupFiles); Long lastLocalCleanupNumber = localDatabase.getCleanupNumber(); if (lastLocalCleanupNumber != null) { return lastRemoteCleanupNumber > lastLocalCleanupNumber; } else { return lastRemoteCleanupNumber > 0; } } }
@Override public int execute(String[] operationArgs) throws Exception { DownOperationOptions operationOptions = parseOptions(operationArgs); DownOperationResult operationResult = new DownOperation(config, operationOptions).execute(); printResults(operationResult); return 0; }
public DownOperationResult down() throws Exception { return down(new DownOperationOptions()); }