@Override public synchronized void secure(TxnId id) throws HyracksDataException { securedLSNs.put(id, txnSubsystem.getRecoveryManager().getMinFirstLSN()); }
private SystemState getCurrentSystemState() { final NodeProperties nodeProperties = runtimeContext.getNodeProperties(); IRecoveryManager recoveryMgr = runtimeContext.getTransactionSubsystem().getRecoveryManager(); SystemState state = recoveryMgr.getSystemState(); // Since we don't pass initial run flag in AsterixHyracksIntegrationUtil, we use the virtualNC flag if (state == SystemState.PERMANENT_DATA_LOSS && (nodeProperties.isInitialRun() || nodeProperties.isVirtualNc())) { state = SystemState.BOOTSTRAPPING; } return state; }
@Override public synchronized void promote(int partition) throws HyracksDataException { if (partitions.contains(partition)) { return; } final PersistentLocalResourceRepository localResourceRepository = (PersistentLocalResourceRepository) appCtx.getLocalResourceRepository(); localResourceRepository.cleanup(partition); final IRecoveryManager recoveryManager = appCtx.getTransactionSubsystem().getRecoveryManager(); recoveryManager.replayReplicaPartitionLogs(Stream.of(partition).collect(Collectors.toSet()), true); partitions.add(partition); }
@Override public void abortTransaction(TxnId txnId) throws ACIDException { final ITransactionContext txnCtx = getTransactionContext(txnId); try { if (txnCtx.isWriteTxn()) { LogRecord logRecord = new LogRecord(); TransactionUtil.formJobTerminateLogRecord(txnCtx, logRecord, false); txnSubsystem.getLogManager().log(logRecord); txnSubsystem.getCheckpointManager().secure(txnId); txnSubsystem.getRecoveryManager().rollbackTransaction(txnCtx); txnCtx.setTxnState(ITransactionManager.ABORTED); } } catch (HyracksDataException e) { String msg = "Could not complete rollback! System is in an inconsistent state"; if (LOGGER.isErrorEnabled()) { LOGGER.log(Level.ERROR, msg, e); } throw new ACIDException(msg, e); } finally { txnCtx.complete(); txnSubsystem.getLockManager().releaseLocks(txnCtx); txnCtxRepository.remove(txnCtx.getTxnId()); txnSubsystem.getCheckpointManager().completed(txnId); } }
@Override public void perform(CcId ccId, IControllerService cs) throws HyracksDataException { INcApplicationContext appContext = (INcApplicationContext) cs.getApplicationContext(); try { appContext.getTransactionSubsystem().getRecoveryManager().startLocalRecovery(partitions); } catch (IOException | ACIDException e) { throw HyracksDataException.create(e); } }
private void stallAbortTxn(Thread t, ITransactionContext txnCtx, ITransactionSubsystem txnSubsystem, TxnId txnId) throws InterruptedException, HyracksDataException { try { if (txnCtx.isWriteTxn()) { LogRecord logRecord = new LogRecord(); TransactionUtil.formJobTerminateLogRecord(txnCtx, logRecord, false); txnSubsystem.getLogManager().log(logRecord); txnSubsystem.getCheckpointManager().secure(txnId); synchronized (t) { t.notifyAll(); t.wait(); } txnSubsystem.getRecoveryManager().rollbackTransaction(txnCtx); txnCtx.setTxnState(ITransactionManager.ABORTED); } } catch (ACIDException | HyracksDataException e) { String msg = "Could not complete rollback! System is in an inconsistent state"; throw new ACIDException(msg, e); } finally { txnCtx.complete(); txnSubsystem.getLockManager().releaseLocks(txnCtx); txnSubsystem.getCheckpointManager().completed(txnId); } }
/*** * Attempts to perform a soft checkpoint at the specified {@code checkpointTargetLSN}. * If a checkpoint cannot be captured due to datasets having LSN < {@code checkpointTargetLSN}, * an asynchronous flush is triggered on them. When a checkpoint is successful, all transaction * log files that end with LSN < {@code checkpointTargetLSN} are deleted. */ @Override public synchronized long tryCheckpoint(long checkpointTargetLSN) throws HyracksDataException { LOGGER.info("Attemping soft checkpoint..."); final long minSecuredLSN = getMinSecuredLSN(); if (minSecuredLSN != NO_SECURED_LSN && checkpointTargetLSN >= minSecuredLSN) { return minSecuredLSN; } final long minFirstLSN = txnSubsystem.getRecoveryManager().getMinFirstLSN(); boolean checkpointSucceeded = minFirstLSN >= checkpointTargetLSN; if (!checkpointSucceeded) { // Flush datasets with indexes behind target checkpoint LSN final IDatasetLifecycleManager dlcm = txnSubsystem.getApplicationContext().getDatasetLifecycleManager(); dlcm.asyncFlushMatchingIndexes(newLaggingDatasetPredicate(checkpointTargetLSN)); } capture(minFirstLSN, false); if (checkpointSucceeded) { txnSubsystem.getLogManager().deleteOldLogFiles(minFirstLSN); LOGGER.info(String.format("soft checkpoint succeeded at LSN(%s)", minFirstLSN)); } return minFirstLSN; }
@Override public void perform(CcId ccId, IControllerService cs) throws HyracksDataException { INcApplicationContext appContext = (INcApplicationContext) cs.getApplicationContext(); try { appContext.getReplicaManager().promote(partitionId); SystemState state = appContext.getTransactionSubsystem().getRecoveryManager().getSystemState(); appContext.initializeMetadata(state == SystemState.PERMANENT_DATA_LOSS, partitionId); } catch (Exception e) { throw HyracksDataException.create(e); } }
(AbstractCheckpointManager) txnSubsystem.getCheckpointManager(); final long minFirstLSN = txnSubsystem.getRecoveryManager().getMinFirstLSN(); checkpointManager.tryCheckpoint(minFirstLSN);
LOGGER.info("System state: " + recoveryMgr.getSystemState()); LOGGER.info("Node ID: " + nodeId); LOGGER.info("Stores: " + PrintUtil.toString(metadataProperties.getStores()));
txnSubsystem = new TransactionSubsystem(this, recoveryManagerFactory); IRecoveryManager recoveryMgr = txnSubsystem.getRecoveryManager(); SystemState systemState = recoveryMgr.getSystemState(); if (initialRun || systemState == SystemState.PERMANENT_DATA_LOSS) {