use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.
the class TransactionContext method registerIndexAndCallback.
@Override
public void registerIndexAndCallback(long resourceId, ILSMIndex index, AbstractOperationCallback callback, boolean isPrimaryIndex) {
synchronized (indexMap) {
if (isPrimaryIndex && primaryIndex == null) {
primaryIndex = index;
primaryIndexCallback = callback;
primaryIndexOpTracker = (PrimaryIndexOperationTracker) index.getOperationTracker();
}
tempResourceIdForRegister.set(resourceId);
if (!indexMap.containsKey(tempResourceIdForRegister)) {
indexMap.put(new MutableLong(resourceId), ((AbstractLSMIOOperationCallback) index.getIOOperationCallback()));
}
}
}
use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.
the class DatasetLifecycleManager method flushDatasetOpenIndexes.
/*
* This method can only be called asynchronously safely if we're sure no modify operation will take place until the flush is scheduled
*/
private void flushDatasetOpenIndexes(DatasetInfo dsInfo, boolean asyncFlush) throws HyracksDataException {
if (!dsInfo.isExternal() && dsInfo.isDurable()) {
synchronized (logRecord) {
TransactionUtil.formFlushLogRecord(logRecord, dsInfo.getDatasetID(), null, logManager.getNodeId(), dsInfo.getIndexes().size());
try {
logManager.log(logRecord);
} catch (ACIDException e) {
throw new HyracksDataException("could not write flush log while closing dataset", e);
}
try {
//notification will come from LogPage class (notifyFlushTerminator)
logRecord.wait();
} catch (InterruptedException e) {
throw new HyracksDataException(e);
}
}
for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
//update resource lsn
AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) iInfo.getIndex().getIOOperationCallback();
ioOpCallback.updateLastLSN(logRecord.getLSN());
}
}
if (asyncFlush) {
for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
ILSMIndexAccessor accessor = iInfo.getIndex().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
accessor.scheduleFlush(iInfo.getIndex().getIOOperationCallback());
}
} else {
for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
// TODO: This is not efficient since we flush the indexes sequentially.
// Think of a way to allow submitting the flush requests concurrently. We don't do them concurrently because this
// may lead to a deadlock scenario between the DatasetLifeCycleManager and the PrimaryIndexOperationTracker.
flushAndWaitForIO(dsInfo, iInfo);
}
}
}
use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.
the class PrimaryIndexOperationTracker method triggerScheduleFlush.
//This method is called sequentially by LogPage.notifyFlushTerminator in the sequence flushes were scheduled.
public synchronized void triggerScheduleFlush(LogRecord logRecord) throws HyracksDataException {
for (ILSMIndex lsmIndex : dsInfo.getDatasetIndexes()) {
//get resource
ILSMIndexAccessor accessor = lsmIndex.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
//update resource lsn
AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) lsmIndex.getIOOperationCallback();
ioOpCallback.updateLastLSN(logRecord.getLSN());
//schedule flush after update
accessor.scheduleFlush(lsmIndex.getIOOperationCallback());
}
flushLogCreated = false;
}
use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback 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.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.
the class LSMIndexUtil method checkAndSetFirstLSN.
public static void checkAndSetFirstLSN(AbstractLSMIndex lsmIndex, ILogManager logManager) throws HyracksDataException {
// If the index has an empty memory component, we need to set its first LSN (For soft checkpoint)
if (lsmIndex.isCurrentMutableComponentEmpty()) {
//prevent transactions from incorrectly setting the first LSN on a modified component by checking the index is still empty
synchronized (lsmIndex.getOperationTracker()) {
if (lsmIndex.isCurrentMutableComponentEmpty()) {
AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) lsmIndex.getIOOperationCallback();
ioOpCallback.setFirstLSN(logManager.getAppendLSN());
}
}
}
}
Aggregations