Search in sources :

Example 1 with Checkpoint

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();
}
Also used : Checkpoint(org.apache.asterix.common.transactions.Checkpoint) ITransactionManager(org.apache.asterix.common.transactions.ITransactionManager) ILogManager(org.apache.asterix.common.transactions.ILogManager)

Example 2 with Checkpoint

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);
}
Also used : Checkpoint(org.apache.asterix.common.transactions.Checkpoint) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 3 with Checkpoint

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);
}
Also used : Checkpoint(org.apache.asterix.common.transactions.Checkpoint)

Example 4 with Checkpoint

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);
}
Also used : Checkpoint(org.apache.asterix.common.transactions.Checkpoint)

Example 5 with Checkpoint

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());
        }
    }
}
Also used : File(java.io.File) Checkpoint(org.apache.asterix.common.transactions.Checkpoint)

Aggregations

Checkpoint (org.apache.asterix.common.transactions.Checkpoint)5 File (java.io.File)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 ILogManager (org.apache.asterix.common.transactions.ILogManager)1 ITransactionManager (org.apache.asterix.common.transactions.ITransactionManager)1