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.
}
}
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;
}
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);
}
}
}
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());
}
}
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());
}
}
}
Aggregations