use of org.apache.asterix.common.transactions.Checkpoint in project asterixdb by apache.
the class AbstractCheckpointManager method capture.
protected void capture(long minMCTFirstLSN, boolean sharp) throws HyracksDataException {
ILogManager logMgr = txnSubsystem.getLogManager();
ITransactionManager txnMgr = txnSubsystem.getTransactionManager();
Checkpoint checkpointObject = new Checkpoint(logMgr.getAppendLSN(), minMCTFirstLSN, txnMgr.getMaxJobId(), System.currentTimeMillis(), sharp, StorageConstants.VERSION);
persist(checkpointObject);
cleanup();
}
use of org.apache.asterix.common.transactions.Checkpoint in project asterixdb by apache.
the class AbstractCheckpointManager method getLatest.
@Override
public Checkpoint getLatest() throws ACIDException {
// Read all checkpointObjects from the existing checkpoint files
File[] checkpoints = checkpointDir.listFiles(filter);
if (checkpoints == null || checkpoints.length == 0) {
return null;
}
List<Checkpoint> checkpointObjectList = new ArrayList<>();
for (File file : checkpoints) {
try {
LOGGER.log(Level.WARNING, "Reading snapshot file: " + file.getAbsolutePath());
String jsonString = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
checkpointObjectList.add(Checkpoint.fromJson(jsonString));
} catch (IOException e) {
throw new ACIDException("Failed to read a checkpoint file", e);
}
}
// Sort checkpointObjects in descending order by timeStamp to find out the most recent one.
Collections.sort(checkpointObjectList);
// Return the most recent one (the first one in sorted list)
return checkpointObjectList.get(0);
}
use of org.apache.asterix.common.transactions.Checkpoint in project asterixdb by apache.
the class RecoveryManager method startRecovery.
//This method is used only when replication is disabled.
@Override
public void startRecovery(boolean synchronous) throws IOException, ACIDException {
state = SystemState.RECOVERING;
LOGGER.log(Level.INFO, "starting recovery ...");
long readableSmallestLSN = logMgr.getReadableSmallestLSN();
Checkpoint checkpointObject = checkpointManager.getLatest();
long lowWaterMarkLSN = checkpointObject.getMinMCTFirstLsn();
if (lowWaterMarkLSN < readableSmallestLSN) {
lowWaterMarkLSN = readableSmallestLSN;
}
//delete any recovery files from previous failed recovery attempts
deleteRecoveryTemporaryFiles();
//get active partitions on this node
Set<Integer> activePartitions = localResourceRepository.getNodeOrignalPartitions();
replayPartitionsLogs(activePartitions, logMgr.getLogReader(true), lowWaterMarkLSN);
}
use of org.apache.asterix.common.transactions.Checkpoint in project asterixdb by apache.
the class RecoveryManager method startLocalRecovery.
@Override
public void startLocalRecovery(Set<Integer> partitions) throws IOException, ACIDException {
state = SystemState.RECOVERING;
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("starting recovery ...");
}
long readableSmallestLSN = logMgr.getReadableSmallestLSN();
Checkpoint checkpointObject = checkpointManager.getLatest();
long lowWaterMarkLSN = checkpointObject.getMinMCTFirstLsn();
if (lowWaterMarkLSN < readableSmallestLSN) {
lowWaterMarkLSN = readableSmallestLSN;
}
//delete any recovery files from previous failed recovery attempts
deleteRecoveryTemporaryFiles();
//get active partitions on this node
replayPartitionsLogs(partitions, logMgr.getLogReader(true), lowWaterMarkLSN);
}
use of org.apache.asterix.common.transactions.Checkpoint in project asterixdb by apache.
the class AbstractCheckpointManager method cleanup.
private void cleanup() {
File[] checkpointFiles = checkpointDir.listFiles(filter);
// Sort the filenames lexicographically to keep the latest checkpoint history files.
Arrays.sort(checkpointFiles);
for (int i = 0; i < checkpointFiles.length - historyToKeep; i++) {
if (!checkpointFiles[i].delete()) {
LOGGER.warning("Could not delete checkpoint file at: " + checkpointFiles[i].getAbsolutePath());
}
}
}
Aggregations