Skip to content

Commit

Permalink
DataNodeSizeSync logging in machine readable format
Browse files Browse the repository at this point in the history
move info logging from DataNodeSizeWorker to DataNodeSizeSync
  • Loading branch information
pdowler committed Mar 25, 2024
1 parent f737dee commit c2c650b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public class DataNodeSizeWorker implements Runnable {
private final ArtifactDAO artifactDAO;
private final HarvestStateDAO harvestStateDAO;
private final Namespace storageNamespace;

private long numArtifactsProcessed;

/**
* Worker constructor.
Expand All @@ -112,16 +114,21 @@ public DataNodeSizeWorker(HarvestStateDAO harvestStateDAO, HarvestState harvestS
this.storageNamespace = namespace;
}

public long getNumArtifactsProcessed() {
return numArtifactsProcessed;
}

@Override
public void run() {
this.numArtifactsProcessed = 0L;
String opName = DataNodeSizeWorker.class.getSimpleName() + ".artifactQuery";
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
if (harvestState.curLastModified != null) {
log.info(opName + " source=" + harvestState.getResourceID()
log.debug(opName + " source=" + harvestState.getResourceID()
+ " instance=" + harvestState.instanceID
+ " start=" + df.format(harvestState.curLastModified));
} else {
log.info(opName + " source=" + harvestState.getResourceID()
log.debug(opName + " source=" + harvestState.getResourceID()
+ " instance=" + harvestState.instanceID);
}

Expand Down Expand Up @@ -159,17 +166,18 @@ public void run() {
harvestState.curLastModified = artifact.getLastModified();
harvestState.curID = artifact.getID();
harvestStateDAO.put(harvestState);
numArtifactsProcessed++;
}
} catch (IOException ex) {
log.error("Error closing iterator", ex);
throw new RuntimeException("error while closing ResourceIterator", ex);
}
if (harvestState.curLastModified != null) {
log.info(opName + " source=" + harvestState.getResourceID()
log.debug(opName + " source=" + harvestState.getResourceID()
+ " instance=" + harvestState.instanceID
+ " end=" + df.format(harvestState.curLastModified));
} else {
log.info(opName + " source=" + harvestState.getResourceID()
log.debug(opName + " source=" + harvestState.getResourceID()
+ " instance=" + harvestState.instanceID
+ " end=true");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,25 @@ public void run() {
log.debug("created: " + state);
}

long t1 = System.currentTimeMillis();
BackgroundLogInfo logInfo = new BackgroundLogInfo(instanceID.toString());
logInfo.setSuccess(false);

// determine leader
boolean leader = checkLeaderStatus(state);

logInfo.leader = leader;

log.info(logInfo.start());
long sleep = LONG_SLEEP; // default for not leader
if (leader) {
log.debug("leader: " + state);
boolean fail = false;
try {
DataNodeSizeWorker worker = new DataNodeSizeWorker(stateDAO, state, artifactDAO, artifactNamespace);
worker.run();
logInfo.setLastModified(state.curLastModified);
logInfo.processed = worker.getNumArtifactsProcessed();
logInfo.setSuccess(true);
} catch (Exception ex) {
log.error("unexpected worker fail", ex);
fail = true;
Expand All @@ -173,16 +183,19 @@ public void run() {
}

if (fail) {
log.debug("failed leader " + state.instanceID + " sleep=" + FAIL_SLEEP);
Thread.sleep(FAIL_SLEEP);
sleep = FAIL_SLEEP;
} else {
log.debug("idle leader " + state.instanceID + " sleep=" + SHORT_SLEEP);
Thread.sleep(SHORT_SLEEP);
sleep = SHORT_SLEEP;
}
logInfo.setSuccess(!fail);
logInfo.setElapsedTime(System.currentTimeMillis() - t1);
} else {
log.debug("not leader: sleep=" + LONG_SLEEP);
Thread.sleep(LONG_SLEEP);
// not leader success
logInfo.setSuccess(true);
}
logInfo.sleep = sleep;
log.info(logInfo.end());
Thread.sleep(sleep);
}
} catch (InterruptedException ex) {
log.debug("interrupted - assuming shutdown", ex);
Expand Down

0 comments on commit c2c650b

Please sign in to comment.