Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Damian authored and Adrian Damian committed Mar 14, 2024
1 parent 022ae46 commit 4dde678
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ public void testSyncArtifact() throws Exception {
log.info("found: " + actual.getID() + " aka " + actual);
Assert.assertEquals(expected.getContentLength(), actual.bytesUsed);

// update
Thread.sleep(20L);
// update the artifact only
artifactDAO.delete(actualArtifact.getID());
expected = new Artifact(expected.getURI(), expected.getMetaChecksum(), new Date(), 333L);
artifactDAO.put(expected);
actual = (DataNode)nodeDAO.get(orig.getID());
Assert.assertNotEquals(expected.getContentLength(), actual.bytesUsed);

// do the update
// run the update
asWorker.run();
actual = (DataNode)nodeDAO.get(orig.getID());
Assert.assertEquals(expected.getContentLength(), actual.bytesUsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
import org.opencadc.vospace.db.NodeDAO;

/**
* This class performs the work of synchronizing the size of Data Node between backend storage and Node Persistence
* This class performs the work of synchronizing the size of Data Nodes between backend storage and Node Persistence
*
* @author adriand
*/
Expand All @@ -91,7 +91,8 @@ public class ArtifactSyncWorker implements Runnable {
private final HarvestStateDAO harvestStateDAO;
private final Namespace storageNamespace;

public ArtifactSyncWorker(HarvestStateDAO harvestStateDAO, HarvestState harvestState, ArtifactDAO artifactDAO, Namespace namespace) {
public ArtifactSyncWorker(HarvestStateDAO harvestStateDAO, HarvestState harvestState, ArtifactDAO artifactDAO,
Namespace namespace) {
this.harvestState = harvestState;
this.harvestStateDAO = harvestStateDAO;
this.nodeDAO = new NodeDAO(harvestStateDAO);
Expand All @@ -103,14 +104,14 @@ public ArtifactSyncWorker(HarvestStateDAO harvestStateDAO, HarvestState harvestS
public void run() {
log.debug("Start harvesting " + harvestState.toString() + " at " + harvestState.curLastModified);

TransactionManager tm = nodeDAO.getTransactionManager();
try (final ResourceIterator<Artifact> iter = artifactDAO.iterator(storageNamespace, null,
harvestState.curLastModified, true)) {
while (iter.hasNext()) {
Artifact artifact = iter.next();
DataNode node = nodeDAO.getDataNode(artifact.getURI());
if ((node != null) && !artifact.getContentLength().equals(node.bytesUsed)) {
node.bytesUsed = artifact.getContentLength();
TransactionManager tm = nodeDAO.getTransactionManager();
tm.startTransaction();
try {
nodeDAO.put(node);
Expand All @@ -123,14 +124,20 @@ public void run() {
log.debug("Failed to update data node size for " + node.getName(), ex);
tm.rollbackTransaction();
throw ex;
} finally {
if (tm.isOpen()) {
log.error("BUG: transaction open in finally. Rolling back...");
tm.rollbackTransaction();
log.error("Rollback: OK");
throw new RuntimeException("BUG: transaction open in finally");
}
}
}
}
} catch (IOException ex) {
//log.error("Error closing iterator", ex);
log.error("Error closing iterator", ex);
throw new RuntimeException("error while closing ResourceIterator", ex);
}
log.debug("End harvesting " + harvestState.toString() + " at " + harvestState.curLastModified);

}
}

0 comments on commit 4dde678

Please sign in to comment.