Search in sources :

Example 1 with TableCheckpoint

use of herddb.core.AbstractTableManager.TableCheckpoint in project herddb by diennea.

the class TableSpaceManager method checkpoint.

TableSpaceCheckpoint checkpoint(boolean full, boolean pin) throws DataStorageManagerException, LogNotAvailableException {
    if (virtual) {
        return null;
    }
    long _start = System.currentTimeMillis();
    LogSequenceNumber logSequenceNumber;
    LogSequenceNumber _logSequenceNumber;
    List<PostCheckpointAction> actions = new ArrayList<>();
    Map<String, LogSequenceNumber> checkpoints = new HashMap<>();
    generalLock.writeLock().lock();
    try {
        logSequenceNumber = log.getLastSequenceNumber();
        if (logSequenceNumber.isStartOfTime()) {
            LOGGER.log(Level.INFO, nodeId + " checkpoint " + tableSpaceName + " at " + logSequenceNumber + ". skipped (no write ever issued to log)");
            return new TableSpaceCheckpoint(logSequenceNumber, checkpoints);
        }
        LOGGER.log(Level.INFO, nodeId + " checkpoint start " + tableSpaceName + " at " + logSequenceNumber);
        if (actualLogSequenceNumber == null) {
            throw new DataStorageManagerException("actualLogSequenceNumber cannot be null");
        }
        // TODO: transactions checkpoint is not atomic
        actions.addAll(dataStorageManager.writeTransactionsAtCheckpoint(tableSpaceUUID, logSequenceNumber, new ArrayList<>(transactions.values())));
        actions.addAll(writeTablesOnDataStorageManager(new CommitLogResult(logSequenceNumber, false)));
        // we checkpoint all data to disk and save the actual log sequence number
        for (AbstractTableManager tableManager : tables.values()) {
            if (!tableManager.isSystemTable()) {
                TableCheckpoint checkpoint = full ? tableManager.fullCheckpoint(pin) : tableManager.checkpoint(pin);
                if (checkpoint != null) {
                    actions.addAll(checkpoint.actions);
                    checkpoints.put(checkpoint.tableName, checkpoint.sequenceNumber);
                    if (afterTableCheckPointAction != null) {
                        afterTableCheckPointAction.run();
                    }
                }
            }
        }
        // we are sure that all data as been flushed. upon recovery we will replay the log starting from this position
        actions.addAll(dataStorageManager.writeCheckpointSequenceNumber(tableSpaceUUID, logSequenceNumber));
        /* Indexes checkpoint is handled by TableManagers */
        log.dropOldLedgers(logSequenceNumber);
        _logSequenceNumber = log.getLastSequenceNumber();
    } finally {
        generalLock.writeLock().unlock();
    }
    for (PostCheckpointAction action : actions) {
        try {
            action.run();
        } catch (Exception error) {
            LOGGER.log(Level.SEVERE, "postcheckpoint error:" + error, error);
        }
    }
    long _stop = System.currentTimeMillis();
    LOGGER.log(Level.INFO, "{0} checkpoint finish {1} started ad {2}, finished at {3}, total time {4} ms", new Object[] { nodeId, tableSpaceName, logSequenceNumber, _logSequenceNumber, Long.toString(_stop - _start) });
    return new TableSpaceCheckpoint(logSequenceNumber, checkpoints);
}
Also used : TableCheckpoint(herddb.core.AbstractTableManager.TableCheckpoint) DataStorageManagerException(herddb.storage.DataStorageManagerException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LogSequenceNumber(herddb.log.LogSequenceNumber) CommitLogResult(herddb.log.CommitLogResult) HDBException(herddb.client.HDBException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) LogNotAvailableException(herddb.log.LogNotAvailableException) ClientSideMetadataProviderException(herddb.client.ClientSideMetadataProviderException) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) FullRecoveryNeededException(herddb.log.FullRecoveryNeededException) TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) TimeoutException(java.util.concurrent.TimeoutException) DataStorageManagerException(herddb.storage.DataStorageManagerException) TableDoesNotExistException(herddb.model.TableDoesNotExistException) DDLException(herddb.model.DDLException) StatementExecutionException(herddb.model.StatementExecutionException) EOFException(java.io.EOFException) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException)

Aggregations

ClientSideMetadataProviderException (herddb.client.ClientSideMetadataProviderException)1 HDBException (herddb.client.HDBException)1 TableCheckpoint (herddb.core.AbstractTableManager.TableCheckpoint)1 CommitLogResult (herddb.log.CommitLogResult)1 FullRecoveryNeededException (herddb.log.FullRecoveryNeededException)1 LogNotAvailableException (herddb.log.LogNotAvailableException)1 LogSequenceNumber (herddb.log.LogSequenceNumber)1 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 DDLException (herddb.model.DDLException)1 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)1 IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)1 StatementExecutionException (herddb.model.StatementExecutionException)1 TableAlreadyExistsException (herddb.model.TableAlreadyExistsException)1 TableDoesNotExistException (herddb.model.TableDoesNotExistException)1 DataStorageManagerException (herddb.storage.DataStorageManagerException)1 EOFException (java.io.EOFException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1