Search in sources :

Example 56 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridCachePartitionedConcurrentMap method putEntryIfObsoleteOrAbsent.

/**
 * {@inheritDoc}
 */
@Override
public GridCacheMapEntry putEntryIfObsoleteOrAbsent(GridCacheContext ctx, AffinityTopologyVersion topVer, KeyCacheObject key, boolean create, boolean skipReserve) {
    while (true) {
        GridDhtLocalPartition part = localPartition(ctx, key, topVer, create);
        if (part == null)
            return null;
        GridCacheMapEntry res = part.putEntryIfObsoleteOrAbsent(ctx, topVer, key, create, skipReserve);
        if (res != null || !create)
            return res;
    // Otherwise partition was concurrently evicted and should be re-created on next iteration.
    }
}
Also used : GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry)

Example 57 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridDistributedCacheAdapter method localSizeLong.

/**
 * {@inheritDoc}
 */
@Override
public long localSizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
    PeekModes modes = parsePeekModes(peekModes, true);
    long size = 0;
    if (modes.near)
        size += nearSize();
    // Swap and offheap are disabled for near cache.
    if (modes.primary || modes.backup) {
        AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
        IgniteCacheOffheapManager offheap = ctx.offheap();
        if (modes.offheap)
            size += offheap.cacheEntriesCount(ctx.cacheId(), modes.primary, modes.backup, topVer);
        else if (modes.heap) {
            for (GridDhtLocalPartition locPart : ctx.topology().currentLocalPartitions()) {
                if ((modes.primary && locPart.primary(topVer)) || (modes.backup && locPart.backup(topVer)))
                    size += locPart.publicSize(ctx.cacheId());
            }
        }
    }
    return size;
}
Also used : IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 58 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridCacheDatabaseSharedManager method dumpPartitionsInfo.

/**
 * Retrieves from page memory meta information about given {@code grp} group partitions
 * and dumps this information to log INFO level.
 *
 * @param grp Cache group.
 * @param log Logger.
 * @throws IgniteCheckedException If failed.
 */
private static void dumpPartitionsInfo(CacheGroupContext grp, IgniteLogger log) throws IgniteCheckedException {
    PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
    IgnitePageStoreManager pageStore = grp.shared().pageStore();
    assert pageStore != null : "Persistent cache should have initialize page store manager.";
    for (int p = 0; p < grp.affinity().partitions(); p++) {
        GridDhtLocalPartition part = grp.topology().localPartition(p);
        if (part != null) {
            if (log.isInfoEnabled())
                log.info("Partition [grp=" + grp.cacheOrGroupName() + ", id=" + p + ", state=" + part.state() + ", counter=" + part.dataStore().partUpdateCounter() + ", size=" + part.fullSize() + "]");
            continue;
        }
        if (!pageStore.exists(grp.groupId(), p))
            continue;
        pageStore.ensure(grp.groupId(), p);
        if (pageStore.pages(grp.groupId(), p) <= 1) {
            if (log.isInfoEnabled())
                log.info("Partition [grp=" + grp.cacheOrGroupName() + ", id=" + p + ", state=N/A (only file header) ]");
            continue;
        }
        long partMetaId = pageMem.partitionMetaPageId(grp.groupId(), p);
        long partMetaPage = pageMem.acquirePage(grp.groupId(), partMetaId);
        try {
            long pageAddr = pageMem.readLock(grp.groupId(), partMetaId, partMetaPage);
            try {
                PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
                GridDhtPartitionState partState = fromOrdinal(io.getPartitionState(pageAddr));
                String state = partState != null ? partState.toString() : "N/A";
                long updateCntr = io.getUpdateCounter(pageAddr);
                long size = io.getSize(pageAddr);
                if (log.isInfoEnabled())
                    log.info("Partition [grp=" + grp.cacheOrGroupName() + ", id=" + p + ", state=" + state + ", counter=" + updateCntr + ", size=" + size + "]");
            } finally {
                pageMem.readUnlock(grp.groupId(), partMetaId, partMetaPage);
            }
        } finally {
            pageMem.releasePage(grp.groupId(), partMetaId, partMetaPage);
        }
    }
}
Also used : IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)

Example 59 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridCacheDatabaseSharedManager method applyUpdate.

/**
 * @param cacheCtx Cache context to apply an update.
 * @param dataEntry Data entry to apply.
 * @throws IgniteCheckedException If failed to restore.
 */
private void applyUpdate(GridCacheContext<?, ?> cacheCtx, DataEntry dataEntry) throws IgniteCheckedException {
    assert cacheCtx.offheap() instanceof GridCacheOffheapManager;
    int partId = dataEntry.partitionId();
    if (partId == -1)
        partId = cacheCtx.affinity().partition(dataEntry.key());
    GridDhtLocalPartition locPart = cacheCtx.isLocal() ? null : cacheCtx.topology().forceCreatePartition(partId);
    switch(dataEntry.op()) {
        case CREATE:
        case UPDATE:
            if (dataEntry instanceof MvccDataEntry) {
                cacheCtx.offheap().mvccApplyUpdate(cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), dataEntry.expireTime(), locPart, ((MvccDataEntry) dataEntry).mvccVer());
            } else {
                cacheCtx.offheap().update(cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), dataEntry.expireTime(), locPart, null);
            }
            if (dataEntry.partitionCounter() != 0)
                cacheCtx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
            break;
        case DELETE:
            if (dataEntry instanceof MvccDataEntry) {
                cacheCtx.offheap().mvccApplyUpdate(cacheCtx, dataEntry.key(), null, dataEntry.writeVersion(), 0L, locPart, ((MvccDataEntry) dataEntry).mvccVer());
            } else
                cacheCtx.offheap().remove(cacheCtx, dataEntry.key(), partId, locPart);
            if (dataEntry.partitionCounter() != 0)
                cacheCtx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
            break;
        case READ:
            // do nothing
            break;
        default:
            throw new IgniteCheckedException("Invalid operation for WAL entry update: " + dataEntry.op());
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 60 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class IgniteTxHandler method mvccEnlistBatch.

/**
 * Writes updated values on the backup node.
 *
 * @param tx Transaction.
 * @param ctx Cache context.
 * @param op Operation.
 * @param keys Keys.
 * @param vals Values sent from the primary node.
 * @param snapshot Mvcc snapshot.
 * @param batchNum Batch number.
 * @param futId Future id.
 * @throws IgniteCheckedException If failed.
 */
public void mvccEnlistBatch(GridDhtTxRemote tx, GridCacheContext ctx, EnlistOperation op, List<KeyCacheObject> keys, List<Message> vals, MvccSnapshot snapshot, IgniteUuid futId, int batchNum) throws IgniteCheckedException {
    assert keys != null && (vals == null || vals.size() == keys.size());
    assert tx != null;
    GridDhtCacheAdapter dht = ctx.dht();
    tx.addActiveCache(ctx, false);
    for (int i = 0; i < keys.size(); i++) {
        KeyCacheObject key = keys.get(i);
        assert key != null;
        int part = ctx.affinity().partition(key);
        try {
            GridDhtLocalPartition locPart = ctx.topology().localPartition(part, tx.topologyVersion(), false);
            if (locPart != null && locPart.reserve()) {
                try {
                    // Skip renting partitions.
                    if (locPart.state() == RENTING) {
                        tx.addInvalidPartition(ctx.cacheId(), part);
                        continue;
                    }
                    CacheObject val = null;
                    EntryProcessor entryProc = null;
                    Object[] invokeArgs = null;
                    boolean needOldVal = tx.txState().useMvccCaching(ctx.cacheId());
                    Message val0 = vals != null ? vals.get(i) : null;
                    CacheEntryInfoCollection entries = val0 instanceof CacheEntryInfoCollection ? (CacheEntryInfoCollection) val0 : null;
                    if (entries == null && !op.isDeleteOrLock() && !op.isInvoke())
                        val = (val0 instanceof CacheObject) ? (CacheObject) val0 : null;
                    if (entries == null && op.isInvoke()) {
                        assert val0 instanceof GridInvokeValue;
                        GridInvokeValue invokeVal = (GridInvokeValue) val0;
                        entryProc = invokeVal.entryProcessor();
                        invokeArgs = invokeVal.invokeArgs();
                    }
                    assert entries != null || entryProc != null || !op.isInvoke() : "entryProc=" + entryProc + ", op=" + op;
                    GridDhtCacheEntry entry = dht.entryExx(key, tx.topologyVersion());
                    GridCacheUpdateTxResult updRes;
                    while (true) {
                        ctx.shared().database().checkpointReadLock();
                        try {
                            if (entries == null) {
                                switch(op) {
                                    case DELETE:
                                        updRes = entry.mvccRemove(tx, ctx.localNodeId(), tx.topologyVersion(), snapshot, false, needOldVal, null, false);
                                        break;
                                    case INSERT:
                                    case TRANSFORM:
                                    case UPSERT:
                                    case UPDATE:
                                        updRes = entry.mvccSet(tx, ctx.localNodeId(), val, entryProc, invokeArgs, 0, tx.topologyVersion(), snapshot, op.cacheOperation(), false, false, needOldVal, null, false, false);
                                        break;
                                    default:
                                        throw new IgniteSQLException("Cannot acquire lock for operation [op= " + op + "]" + "Operation is unsupported at the moment ", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
                                }
                            } else {
                                updRes = entry.mvccUpdateRowsWithPreloadInfo(tx, ctx.localNodeId(), tx.topologyVersion(), entries.infos(), op.cacheOperation(), snapshot, futId, batchNum);
                            }
                            break;
                        } catch (GridCacheEntryRemovedException ignore) {
                            entry = dht.entryExx(key);
                        } finally {
                            ctx.shared().database().checkpointReadUnlock();
                        }
                    }
                    if (!updRes.filtered())
                        ctx.shared().mvccCaching().addEnlisted(key, updRes.newValue(), 0, 0, tx.xidVersion(), updRes.oldValue(), tx.local(), tx.topologyVersion(), snapshot, ctx.cacheId(), tx, futId, batchNum);
                    assert updRes.updateFuture() == null : "Entry should not be locked on the backup";
                } finally {
                    locPart.release();
                }
            } else
                tx.addInvalidPartition(ctx.cacheId(), part);
        } catch (GridDhtInvalidPartitionException e) {
            tx.addInvalidPartition(ctx.cacheId(), e.partition());
        }
    }
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridInvokeValue(org.apache.ignite.internal.processors.cache.distributed.dht.GridInvokeValue) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) PartitionUpdateCountersMessage(org.apache.ignite.internal.processors.cache.distributed.dht.PartitionUpdateCountersMessage) EntryProcessor(javax.cache.processor.EntryProcessor) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) GridCacheUpdateTxResult(org.apache.ignite.internal.processors.cache.GridCacheUpdateTxResult) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)95 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 IgniteEx (org.apache.ignite.internal.IgniteEx)19 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)19 ArrayList (java.util.ArrayList)18 Map (java.util.Map)18 Test (org.junit.Test)18 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)15 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)13 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)13 Ignite (org.apache.ignite.Ignite)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 IgniteException (org.apache.ignite.IgniteException)11