Search in sources :

Example 31 with FailureContext

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;
    }
}
Also used : TransactionState(org.apache.ignite.transactions.TransactionState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)

Example 32 with FailureContext

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);
    }
}
Also used : FailureContext(org.apache.ignite.failure.FailureContext) IgniteException(org.apache.ignite.IgniteException) File(java.io.File) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO)

Example 33 with FailureContext

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;
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) FailureContext(org.apache.ignite.failure.FailureContext) File(java.io.File)

Example 34 with FailureContext

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);
    }
}
Also used : CheckpointStatus(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) IOException(java.io.IOException)

Example 35 with FailureContext

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) CheckpointStatus(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) DefragmentationWorkflowCallback(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationWorkflowCallback)

Aggregations

FailureContext (org.apache.ignite.failure.FailureContext)54 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)13 Ignite (org.apache.ignite.Ignite)11 IOException (java.io.IOException)9 AbstractFailureHandler (org.apache.ignite.failure.AbstractFailureHandler)9 IgniteEx (org.apache.ignite.internal.IgniteEx)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 Test (org.junit.Test)9 IgniteException (org.apache.ignite.IgniteException)8 File (java.io.File)6 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)6 StorageException (org.apache.ignite.internal.processors.cache.persistence.StorageException)6 LogListener (org.apache.ignite.testframework.LogListener)5 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)4 ByteBuffer (java.nio.ByteBuffer)3 UUID (java.util.UUID)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3