Search in sources :

Example 1 with ILockManager

use of org.apache.asterix.common.transactions.ILockManager 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);
            }
        }
    };
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) AbstractUnaryInputSinkOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputSinkOperatorNodePushable) INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) ILockManager(org.apache.asterix.common.transactions.ILockManager) ITransactionManager(org.apache.asterix.common.transactions.ITransactionManager) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)1 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 ILockManager (org.apache.asterix.common.transactions.ILockManager)1 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)1 ITransactionManager (org.apache.asterix.common.transactions.ITransactionManager)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 AbstractUnaryInputSinkOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractUnaryInputSinkOperatorNodePushable)1