Skip to content

Commit

Permalink
fixed, improved logging
Browse files Browse the repository at this point in the history
Issue #188
  • Loading branch information
rsoika committed Jun 13, 2023
1 parent 9525daa commit 73d165b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import jakarta.ejb.Stateless;
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;

import org.imixs.archive.service.ArchiveException;
import org.imixs.archive.service.resync.ResyncService;
import org.imixs.workflow.FileData;
Expand All @@ -37,6 +29,14 @@
import com.datastax.driver.core.Row;
import com.datastax.driver.core.SimpleStatement;

import jakarta.ejb.Stateless;
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;

/**
* The SnapshotService is used to store a imixs snapshot into the cluster
* keyspace.
Expand Down Expand Up @@ -129,9 +129,10 @@ public void saveSnapshot(ItemCollection snapshot) throws ArchiveException {

// verify if this snapshot is already stored - if so, we do not overwrite
// the origin data. See issue #40
// For example this situation also occurs when restoring a remote snapshot.
if (existSnapshot(snapshotID)) {
// skip!
logger.info("...snapshot '" + snapshot.getUniqueID() + "' already exits....");
logger.fine("...snapshot '" + snapshot.getUniqueID() + "' already exits....");
return;
}

Expand Down Expand Up @@ -220,13 +221,13 @@ public ItemCollection loadSnapshot(String snapshotID, boolean mergeDocuments) th
if (row != null) {
// load ItemCollection object
ByteBuffer data = row.getBytes(COLUMN_DATA);
if (data!=null && data.hasArray()) {
if (data != null && data.hasArray()) {
snapshot = getItemCollection(data.array());

// next we need to load the document data if exists...
mergeDocumentData(snapshot);
} else {
logger.warning("no data found for snapshotId '"+snapshotID+"'");
logger.warning("no data found for snapshotId '" + snapshotID + "'");
}
} else {
// does not exist - create empty object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,16 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception {
// we search for snapshotIDs until we found one or the syncdate is after the
// restore.to point.
while (localDateRestoreTo.isAfter(localDateSyncPoint)) {

List<String> snapshotIDs = dataService.loadSnapshotsByDate(localDateSyncPoint.toLocalDate());
// verify all snapshots of this day....
if (!snapshotIDs.isEmpty()) {
logger.info("......restore snapshot date " + localDateSyncPoint);
logger.info("......validate snapshot date " + localDateSyncPoint + "...");
// print out the snapshotIDs we found
for (String snapshotID : snapshotIDs) {

String latestSnapshot = findLatestSnapshotID(snapshotID, restoreFrom, restoreTo);
// did we found a snapshot to restore?
ItemCollection snapshot;
String remoteSnapshotID = null;
if (latestSnapshot != null) {
if (latestSnapshot != null && matchFilterOptions(latestSnapshot, options)) {
// yes, lets see if this snapshot is already restored or synced?
try {
remoteSnapshotID = remoteAPIService
Expand All @@ -291,30 +288,26 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception {
logger.finest(
"......no need to restore - snapshot:" + latestSnapshot + " is up to date!");
} else {
// test the filter options
if (matchFilterOptions(latestSnapshot, options)) {
long _tmpSize = -1;
try {
logger.info("......restoring: " + latestSnapshot);
snapshot = dataService.loadSnapshot(latestSnapshot);
_tmpSize = dataService.calculateSize(XMLDocumentAdapter.getDocument(snapshot));
logger.finest("......size=: " + _tmpSize);

remoteAPIService.restoreSnapshot(snapshot);

restoreSize = restoreSize + _tmpSize;
restoreCount++;
snapshot = null;
} catch (Exception e) {
logger.severe("...Failed to restore '" + latestSnapshot + "' ("
+ messageService.userFriendlyBytes(_tmpSize) + ") - " + e.getMessage());
restoreErrors++;
}
// start restore...
long _tmpSize = -1;
try {
logger.info("......restore snapshot " + latestSnapshot + " ...");
snapshot = dataService.loadSnapshot(latestSnapshot);
_tmpSize = dataService.calculateSize(XMLDocumentAdapter.getDocument(snapshot));
logger.finest("......size=: " + _tmpSize);
remoteAPIService.restoreSnapshot(snapshot);
restoreSize = restoreSize + _tmpSize;
restoreCount++;
snapshot = null;
} catch (Exception e) {
logger.severe("...Failed to restore '" + latestSnapshot + "' ("
+ messageService.userFriendlyBytes(_tmpSize) + ") - " + e.getMessage());
restoreErrors++;
}
}
} else {
logger.warning(
".... unexpected data situation: no latest snapshot found, matching requested restore time range!");
logger.fine(
".... no snapshot found matching requested restore time range and options");
}
}
}
Expand Down

0 comments on commit 73d165b

Please sign in to comment.