Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Transactionifying the transaction cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pimotte committed Aug 14, 2014
1 parent 5ce98fe commit 42f32c5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public CleanupOperationResult execute() throws Exception {

startOperation();

transferManager.cleanTransactions(config.getMachineName());
transferManager.cleanTransactions(config);

// Wait two seconds (conservative cleanup, see #104)
logger.log(Level.INFO, "Cleanup: Waiting a while to be sure that no other actions are running ...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public UpOperationResult execute() throws Exception {
startOperation();

// TODO [medium/high] Remove this and construct mechanism to resume uploads
transferManager.cleanTransactions(config.getMachineName());
transferManager.cleanTransactions(config);

ChangeSet localChanges = result.getStatusResult().getChangeSet();
List<File> locallyUpdatedFiles = extractLocallyUpdatedFiles(localChanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public <T extends RemoteFile> Map<String, T> list(Class<T> remoteFileClass) thro
for (File file : files) {
try {
T remoteFile = RemoteFile.createRemoteFile(file.getName(), remoteFileClass);
remoteFiles.put(file.getName(), remoteFile);
if (!filesToIgnore.contains(remoteFile)) {
remoteFiles.put(file.getName(), remoteFile);
}
}
catch (Exception e) {
logger.log(Level.INFO, "Cannot create instance of " + remoteFileClass.getSimpleName() + " for file " + file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.io.FileUtils;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.syncany.config.Config;
import org.syncany.plugins.StorageException;
import org.syncany.plugins.StorageTestResult;
import org.syncany.plugins.transfer.files.RemoteFile;
Expand Down Expand Up @@ -105,20 +106,22 @@ public StorageTestResult test(boolean testCreateTarget) {
return result;
}

public void cleanTransactions(String machineName) throws StorageException {
public void cleanTransactions(Config config) throws StorageException {
Map<TransactionTO, TransactionRemoteFile> transactions = getTransactionTOs();
RemoteTransaction remoteTransaction = new RemoteTransaction(config, this);
for (TransactionTO transaction : transactions.keySet()) {
if (transaction.getMachineName().equals(machineName)) {
if (transaction.getMachineName().equals(config.getMachineName())) {
// Delete all permanent or temporary files in this transaction.
for (ActionTO action : transaction.getActions()) {
delete(action.getRemoteFile());
delete(action.getTempRemoteFile());
remoteTransaction.delete(action.getRemoteFile());
remoteTransaction.delete(action.getTempRemoteFile());
}

// Get corresponding remote file of transaction and delete it.
delete(transactions.get(transaction));
remoteTransaction.delete(transactions.get(transaction));
}
}
remoteTransaction.commit();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,35 @@ public void commit() throws StorageException {
transferManager.upload(localTransactionFile, remoteTransactionFile);

for (ActionTO action : transactionTO.getActions()) {

RemoteFile tempRemoteFile = action.getTempRemoteFile();
if (action.getType().equals(ActionTO.TYPE_UPLOAD)) {
File localFile = action.getLocalTempLocation();
RemoteFile tempRemoteFile = action.getTempRemoteFile();
logger.log(Level.INFO, "- Uploading {0} to temp. file {1} ...", new Object[] { localFile, tempRemoteFile });
transferManager.upload(localFile, tempRemoteFile);
}
else if (action.getType().equals(ActionTO.TYPE_DELETE)) {
RemoteFile remoteFile = action.getRemoteFile();
RemoteFile tempRemoteFile = action.getTempRemoteFile();
logger.log(Level.INFO, "- Moving {0} to temp. file {1} ...", new Object[] { remoteFile, tempRemoteFile });
transferManager.move(remoteFile, tempRemoteFile);
}
}

// After this deletion, the transaction is final!
logger.log(Level.INFO, "- Deleting remote transaction file {0} ...", remoteTransactionFile);
transferManager.delete(remoteTransactionFile);

for (ActionTO action : transactionTO.getActions()) {
if (action.getType().equals(ActionTO.TYPE_UPLOAD)) {
RemoteFile tempRemoteFile = action.getTempRemoteFile();
RemoteFile finalRemoteFile = action.getRemoteFile();
logger.log(Level.INFO, "- Moving temp. file {0} to final location {1} ...", new Object[] { tempRemoteFile, finalRemoteFile });
transferManager.move(tempRemoteFile, finalRemoteFile);
}
else if (action.getType().equals(ActionTO.TYPE_DELETE)){
}

// After this deletion, the transaction is final!
logger.log(Level.INFO, "- Deleting remote transaction file {0} ...", remoteTransactionFile);
transferManager.delete(remoteTransactionFile);

for (ActionTO action : transactionTO.getActions()) {
if (action.getType().equals(ActionTO.TYPE_DELETE)){
RemoteFile tempRemoteFile = action.getTempRemoteFile();
logger.log(Level.INFO, "- Moving deleting temp. file {0} ...", new Object[] { tempRemoteFile });
transferManager.delete(tempRemoteFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.syncany.config.Config;
import org.syncany.plugins.StorageException;
import org.syncany.plugins.StorageTestResult;
import org.syncany.plugins.transfer.files.RemoteFile;
Expand Down Expand Up @@ -140,11 +141,11 @@ public Object execute() throws StorageException {
}

@Override
public void cleanTransactions(final String machineName) throws StorageException {
public void cleanTransactions(final Config config) throws StorageException {
retryMethod(new RetriableMethod() {
@Override
public Object execute() throws StorageException {
underlyingTransferManager.cleanTransactions(machineName);
underlyingTransferManager.cleanTransactions(config);
return null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.util.Map;

import org.syncany.config.Config;
import org.syncany.plugins.StorageException;
import org.syncany.plugins.StorageTestResult;
import org.syncany.plugins.transfer.files.DatabaseRemoteFile;
Expand Down Expand Up @@ -162,7 +163,7 @@ public interface TransferManager {
* @throws StorageException If the connection fails due to no Internet connection,
* authentication errors, etc
*/
public void cleanTransactions(String machineName) throws StorageException;
public void cleanTransactions(Config config) throws StorageException;

/**
* Tests whether the repository parameters are valid. In particular, the method tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,5 @@ public File getLocalTempLocation() {
return new File(localTempLocation);
}

public void execute() {
if (TYPE_UPLOAD.equals(getType())) {

}
else if (TYPE_DELETE.equals(getType())) {
throw new RuntimeException("NOT IMPLEMENTED YET");
}
}



}

0 comments on commit 42f32c5

Please sign in to comment.