use of org.apache.asterix.common.api.IDatasetLifecycleManager in project asterixdb by apache.
the class RecoveryManager method getLocalMinFirstLSN.
@Override
public long getLocalMinFirstLSN() throws HyracksDataException {
IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
List<IIndex> openIndexList = datasetLifecycleManager.getOpenResources();
long firstLSN;
//the min first lsn can only be the current append or smaller
long minFirstLSN = logMgr.getAppendLSN();
if (!openIndexList.isEmpty()) {
for (IIndex index : openIndexList) {
AbstractLSMIOOperationCallback ioCallback = (AbstractLSMIOOperationCallback) ((ILSMIndex) index).getIOOperationCallback();
if (!((AbstractLSMIndex) index).isCurrentMutableComponentEmpty() || ioCallback.hasPendingFlush()) {
firstLSN = ioCallback.getFirstLSN();
minFirstLSN = Math.min(minFirstLSN, firstLSN);
}
}
}
return minFirstLSN;
}
use of org.apache.asterix.common.api.IDatasetLifecycleManager in project asterixdb by apache.
the class CheckpointManager method tryCheckpoint.
/***
* 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 minFirstLSN = txnSubsystem.getRecoveryManager().getMinFirstLSN();
boolean checkpointSucceeded = minFirstLSN >= checkpointTargetLSN;
if (!checkpointSucceeded) {
// Flush datasets with indexes behind target checkpoint LSN
IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
datasetLifecycleManager.scheduleAsyncFlushForLaggingDatasets(checkpointTargetLSN);
}
capture(minFirstLSN, false);
if (checkpointSucceeded) {
txnSubsystem.getLogManager().deleteOldLogFiles(minFirstLSN);
LOGGER.info(String.format("soft checkpoint succeeded at LSN(%s)", minFirstLSN));
}
return minFirstLSN;
}
use of org.apache.asterix.common.api.IDatasetLifecycleManager in project asterixdb by apache.
the class CheckpointManager method doSharpCheckpoint.
/**
* Performs a sharp checkpoint. All datasets are flushed and all transaction
* log files are deleted.
*/
@Override
public synchronized void doSharpCheckpoint() throws HyracksDataException {
LOGGER.info("Starting sharp checkpoint...");
final IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
datasetLifecycleManager.flushAllDatasets();
capture(SHARP_CHECKPOINT_LSN, true);
txnSubsystem.getLogManager().renewLogFiles();
LOGGER.info("Completed sharp checkpoint.");
}
use of org.apache.asterix.common.api.IDatasetLifecycleManager in project asterixdb by apache.
the class ReplicationCheckpointManager method tryCheckpoint.
/***
* 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. If the checkpoint fails due to a replica index,
* a request is sent to the primary replica of the index to flush it.
* 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 minFirstLSN = txnSubsystem.getRecoveryManager().getMinFirstLSN();
boolean checkpointSucceeded = minFirstLSN >= checkpointTargetLSN;
if (!checkpointSucceeded) {
// Flush datasets with indexes behind target checkpoint LSN
final IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
datasetLifecycleManager.scheduleAsyncFlushForLaggingDatasets(checkpointTargetLSN);
// Request remote replicas to flush lagging indexes
final IReplicationManager replicationManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getAppContext().getReplicationManager();
try {
replicationManager.requestFlushLaggingReplicaIndexes(checkpointTargetLSN);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
capture(minFirstLSN, false);
if (checkpointSucceeded) {
txnSubsystem.getLogManager().deleteOldLogFiles(minFirstLSN);
LOGGER.info(String.format("soft checkpoint succeeded with at LSN(%s)", minFirstLSN));
}
return minFirstLSN;
}
use of org.apache.asterix.common.api.IDatasetLifecycleManager in project asterixdb by apache.
the class FlushDatasetOperatorDescriptor method createPushRuntime.
@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
return new AbstractUnaryInputSinkOperatorNodePushable() {
@Override
public void open() throws HyracksDataException {
}
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
}
@Override
public void fail() throws HyracksDataException {
this.close();
}
@Override
public void close() throws HyracksDataException {
try {
INcApplicationContext appCtx = (INcApplicationContext) ctx.getJobletContext().getServiceContext().getApplicationContext();
IDatasetLifecycleManager datasetLifeCycleManager = appCtx.getDatasetLifecycleManager();
ILockManager lockManager = appCtx.getTransactionSubsystem().getLockManager();
ITransactionManager txnManager = appCtx.getTransactionSubsystem().getTransactionManager();
// get the local transaction
ITransactionContext txnCtx = txnManager.getTransactionContext(jobId, false);
// lock the dataset granule
lockManager.lock(datasetId, -1, LockMode.S, txnCtx);
// flush the dataset synchronously
datasetLifeCycleManager.flushDataset(datasetId.getId(), false);
} catch (ACIDException e) {
throw new HyracksDataException(e);
}
}
};
}
Aggregations