@Override public void jobletFinish(JobStatus jobStatus) { try { ITransactionManager txnManager = ((INcApplicationContext) jobletContext.getServiceContext().getApplicationContext()) .getTransactionSubsystem().getTransactionManager(); for (TxnId subTxnId : txnIdMap.values()) { ITransactionContext txnContext = txnManager.getTransactionContext(subTxnId); txnContext.setWriteTxn(transactionalWrite); if (jobStatus != JobStatus.FAILURE) { txnManager.commitTransaction(subTxnId); } else { txnManager.abortTransaction(subTxnId); } } } catch (ACIDException e) { throw new Error(e); } }
@Override public void jobletFinish(JobStatus jobStatus) { try { ITransactionManager txnManager = ((INcApplicationContext) jobletContext.getServiceContext().getApplicationContext()) .getTransactionSubsystem().getTransactionManager(); ITransactionContext txnContext = txnManager.getTransactionContext(txnId); txnContext.setWriteTxn(transactionalWrite); if (jobStatus != JobStatus.FAILURE) { txnManager.commitTransaction(txnId); } else { txnManager.abortTransaction(txnId); } } catch (ACIDException e) { throw new Error(e); } }
@Override public void open() throws HyracksDataException { try { transactionContext = transactionManager.getTransactionContext(txnId); transactionContext.setWriteTxn(isWriteTransaction); ILogMarkerCallback callback = TaskUtil.get(ILogMarkerCallback.KEY_MARKER_CALLBACK, ctx); logRecord = new LogRecord(callback); if (isSink) { return; } initAccessAppend(ctx); super.open(); } catch (ACIDException e) { throw HyracksDataException.create(e); } }
@Override public LockThenSearchOperationCallback createSearchOperationCallback(long resourceId, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); try { IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); return new LockThenSearchOperationCallback(new DatasetId(datasetId), resourceId, primaryKeyFields, txnSubsystem, txnCtx, operatorNodePushable); } catch (ACIDException e) { throw HyracksDataException.create(e); } }
@Override public ISearchOperationCallback createSearchOperationCallback(long resourceId, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); try { IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); return new PrimaryIndexInstantSearchOperationCallback(new DatasetId(datasetId), resourceId, primaryKeyFields, txnSubsystem.getLockManager(), txnCtx); } catch (ACIDException e) { throw HyracksDataException.create(e); } }
@Override public ISearchOperationCallback createSearchOperationCallback(long resourceId, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); try { IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); return new PrimaryIndexSearchOperationCallback(new DatasetId(datasetId), resourceId, primaryKeyFields, txnSubsystem.getLockManager(), txnCtx); } catch (ACIDException e) { throw HyracksDataException.create(e); } }
@Override public ISearchOperationCallback createSearchOperationCallback(long resourceId, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { try { // If the plan is an index-only query plan, we need to try to get an instant try lock on PK. // If an instant tryLock on PK fails, we do not attempt to do a lock since the operations // will be dealt with in the operators after the given secondary-index search. ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); return new SecondaryIndexInstantSearchOperationCallback(new DatasetId(datasetId), resourceId, primaryKeyFields, txnSubsystem.getLockManager(), txnCtx); } catch (ACIDException e) { throw HyracksDataException.create(e); } } }
datasetLifecycleManager.open(resourceName); try { ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(txnId); IModificationOperationCallback modCallback = createIndexModificationCallback(op, txnCtx, metadataIndex); IIndexAccessParameters iap = new IndexAccessParameters(modCallback, NoOpOperationCallback.INSTANCE);
@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(txnId); // lock the dataset granule lockManager.lock(datasetId, -1, LockMode.S, txnCtx); // flush the dataset synchronously DatasetInfo datasetInfo = datasetLifeCycleManager.getDatasetInfo(datasetId.getId()); // TODO: Remove the isOpen check and let it fail if flush is requested for a dataset that is closed synchronized (datasetLifeCycleManager) { if (datasetInfo.isOpen()) { datasetLifeCycleManager.flushDataset(datasetId.getId(), false); } } datasetInfo.waitForIO(); } catch (ACIDException e) { throw HyracksDataException.create(e); } }
@Override public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); IResourceLifecycleManager<IIndex> indexLifeCycleManager = txnSubsystem.getApplicationContext().getDatasetLifecycleManager(); ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath()); if (index == null) { throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered."); } try { IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource(); IModificationOperationCallback modCallback = new PrimaryIndexModificationOperationCallback( new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp, operatorNodePushable); txnCtx.register(resource.getId(), aResource.getPartition(), index, modCallback, true); return modCallback; } catch (ACIDException e) { throw HyracksDataException.create(e); } } }
@Override public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource(); ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); IResourceLifecycleManager indexLifeCycleManager = txnSubsystem.getApplicationContext().getDatasetLifecycleManager(); ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath()); if (index == null) { throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered."); } try { IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); IModificationOperationCallback modCallback = new UpsertOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp); txnCtx.register(resource.getId(), aResource.getPartition(), index, modCallback, true); return modCallback; } catch (ACIDException e) { throw HyracksDataException.create(e); } } }
@Override public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException { ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx); IResourceLifecycleManager indexLifeCycleManager = txnSubsystem.getApplicationContext().getDatasetLifecycleManager(); ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath()); if (index == null) { throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered."); } try { IJobletEventListenerFactory fact = ctx.getJobletContext().getJobletEventListenerFactory(); ITransactionContext txnCtx = txnSubsystem.getTransactionManager() .getTransactionContext(((IJobEventListenerFactory) fact).getTxnId(datasetId)); DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource(); IModificationOperationCallback modCallback = new SecondaryIndexModificationOperationCallback( new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp); txnCtx.register(resource.getId(), aResource.getPartition(), index, modCallback, false); return modCallback; } catch (ACIDException e) { throw HyracksDataException.create(e); } } }
reusableTxnId.setId(logRecord.getTxnId()); reusableDatasetId.setId(logRecord.getDatasetId()); txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(reusableTxnId); txnSubsystem.getLockManager().unlock(reusableDatasetId, logRecord.getPKHashValue(), LockMode.ANY, txnCtx);