use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class GridDistributedTxRemoteAdapter method commitRemoteTx.
/**
* {@inheritDoc}
*/
@Override
public final void commitRemoteTx() throws IgniteCheckedException {
if (optimistic())
state(PREPARED);
if (!state(COMMITTING)) {
TransactionState state = state();
// If other thread is doing commit, then no-op.
if (state == COMMITTING || state == COMMITTED)
return;
if (log.isDebugEnabled())
log.debug("Failed to set COMMITTING transaction state (will rollback): " + this);
setRollbackOnly();
if (!isSystemInvalidate())
throw new IgniteCheckedException("Invalid transaction state for commit [state=" + state + ", tx=" + this + ']');
rollbackRemoteTx();
return;
}
try {
commitIfLocked();
} catch (IgniteTxHeuristicCheckedException e) {
// Treat heuristic exception as critical.
cctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw e;
}
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class BinaryMetadataFileStore method writeMetadata.
/**
* @param binMeta Binary metadata to be written to disk.
*/
void writeMetadata(BinaryMetadata binMeta) {
if (!isPersistenceEnabled)
return;
try {
File file = new File(metadataDir, binMeta.typeId() + ".bin");
byte[] marshalled = U.marshal(ctx, binMeta);
try (final FileIO out = fileIOFactory.create(file)) {
int left = marshalled.length;
while ((left -= out.writeFully(marshalled, 0, Math.min(marshalled.length, left))) > 0) ;
out.force();
}
} catch (Exception e) {
final String msg = "Failed to save metadata for typeId: " + binMeta.typeId() + "; exception was thrown: " + e.getMessage();
U.error(log, msg);
U.cancel(writer);
ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw new IgniteException(msg, e);
}
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class BinaryMetadataFileStore method removeMeta.
/**
* Remove metadata for specified type.
*
* @param typeId Type identifier.
*/
private void removeMeta(int typeId) {
if (!isPersistenceEnabled)
return;
File file = new File(metadataDir, typeId + ".bin");
if (!file.delete()) {
final String msg = "Failed to remove metadata for typeId: " + typeId;
U.error(log, msg);
writer.cancel();
IgniteException e = new IgniteException(msg);
ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw e;
}
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class GridCacheDatabaseSharedManager method finishRecovery.
/**
* Restores last valid WAL pointer and resumes logging from that pointer.
* Re-creates metastorage if needed.
*
* @throws IgniteCheckedException If failed.
*/
private void finishRecovery() throws IgniteCheckedException {
assert !cctx.kernalContext().clientNode();
long time = System.currentTimeMillis();
CHECKPOINT_LOCK_HOLD_COUNT.set(CHECKPOINT_LOCK_HOLD_COUNT.get() + 1);
try {
for (DatabaseLifecycleListener lsnr : getDatabaseListeners(cctx.kernalContext())) lsnr.beforeResumeWalLogging(this);
// Try to resume logging since last finished checkpoint if possible.
if (walTail == null) {
CheckpointStatus status = readCheckpointStatus();
walTail = CheckpointStatus.NULL_PTR.equals(status.endPtr) ? null : status.endPtr;
}
resumeWalLogging();
walTail = null;
// Recreate metastorage to refresh page memory state after deactivation.
if (metaStorage == null)
metaStorage = createMetastorage(false);
notifyMetastorageReadyForReadWrite();
U.log(log, "Finish recovery performed in " + (System.currentTimeMillis() - time) + " ms.");
} catch (IgniteCheckedException e) {
if (X.hasCause(e, StorageException.class, IOException.class))
cctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw e;
} finally {
CHECKPOINT_LOCK_HOLD_COUNT.set(CHECKPOINT_LOCK_HOLD_COUNT.get() - 1);
}
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class GridCacheDatabaseSharedManager method readMetastore.
/**
*/
private void readMetastore() throws IgniteCheckedException {
try {
CheckpointStatus status = readCheckpointStatus();
checkpointReadLock();
try {
dataRegion(METASTORE_DATA_REGION_NAME).pageMemory().start();
performBinaryMemoryRestore(status, onlyMetastorageGroup(), physicalRecords(), false);
metaStorage = createMetastorage(true);
applyLogicalUpdates(status, onlyMetastorageGroup(), onlyMetastorageAndEncryptionRecords(), true);
fillWalDisabledGroups();
checkpointManager.initializeStorage();
registerSystemView();
notifyMetastorageReadyForRead();
cctx.kernalContext().maintenanceRegistry().registerWorkflowCallbackIfTaskExists(DEFRAGMENTATION_MNTC_TASK_NAME, task -> {
prepareCacheDefragmentation(fromStore(task).cacheNames());
return new DefragmentationWorkflowCallback(cctx.kernalContext()::log, defrgMgr, cctx.kernalContext().failure());
});
} finally {
if (metaStorage != null)
metaStorage.close();
metaStorage = null;
dataRegion(METASTORE_DATA_REGION_NAME).pageMemory().stop(false);
cctx.pageStore().cleanupPageStoreIfMatch(new Predicate<Integer>() {
@Override
public boolean test(Integer grpId) {
return MetaStorage.METASTORAGE_CACHE_ID == grpId;
}
}, false);
checkpointReadUnlock();
}
} catch (StorageException e) {
cctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw new IgniteCheckedException(e);
}
}
Aggregations