use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheMvcc method readyNearLocal.
/**
* Marks near-local candidate as ready and makes locks reassignment. Following reorderings are performed when
* candidate is marked ready:
* <ul>
* <li/> All candidates preceding ready one are moved right after it.
* <li/> Near local candidate is assigned a mapped dht version. All remote non-pending candidates with
* version less then mapped dht version are marked as owned.
* </ul>
*
* @param ver Version to mark as ready.
* @param mappedVer Mapped dht version.
* @param committedVers Committed versions.
* @param rolledBackVers Rolled back versions.
* @param pending Pending dht versions that are not owned and which version is less then mapped.
* @return Lock owner after reassignment.
*/
@Nullable
public CacheLockCandidates readyNearLocal(GridCacheVersion ver, GridCacheVersion mappedVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledBackVers, Collection<GridCacheVersion> pending) {
GridCacheMvccCandidate cand = candidate(locs, ver);
if (cand != null) {
assert cand.nearLocal() : "Near local candidate is not marked as near local: " + cand;
cand.setReady();
boolean setMapped = cand.otherVersion(mappedVer);
assert setMapped : "Failed to set mapped dht version for near local candidate [mappedVer=" + mappedVer + ", cand=" + cand + ']';
// For near locals we move all not owned candidates after this one.
List<GridCacheMvccCandidate> mvAfter = null;
for (ListIterator<GridCacheMvccCandidate> it = locs.listIterator(); it.hasNext(); ) {
GridCacheMvccCandidate c = it.next();
assert c.nearLocal() : "Near local candidate is not marked as near local: " + c;
if (c == cand) {
if (mvAfter != null)
for (GridCacheMvccCandidate mv : mvAfter) it.add(mv);
break;
} else {
if (c.owner())
continue;
assert !c.ready() || (c.read() && cand.read()) : "Cannot have more then one ready near-local candidate [c=" + c + ", cand=" + cand + ", mvcc=" + this + ']';
it.remove();
if (mvAfter == null)
mvAfter = new LinkedList<>();
mvAfter.add(c);
}
}
// Mark all remote candidates with less version as owner unless it is pending.
if (rmts != null) {
for (GridCacheMvccCandidate rmt : rmts) {
GridCacheVersion rmtVer = rmt.version();
if (rmtVer.isLess(mappedVer)) {
if (!pending.contains(rmtVer) && !mappedVer.equals(rmt.ownerVersion()))
rmt.setOwner();
} else {
// Remote version is greater, so need to check if it was committed or rolled back.
if (committedVers.contains(rmtVer) || rolledBackVers.contains(rmtVer))
rmt.setOwner();
}
}
}
reassign();
}
return allOwners();
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheMvcc method compareSerializableVersion.
/**
* @param cand Existing candidate.
* @param newCand New candidate.
* @return {@code False} if new candidate can not be added.
*/
private boolean compareSerializableVersion(GridCacheMvccCandidate cand, GridCacheMvccCandidate newCand) {
assert cand.serializable() && newCand.serializable();
GridCacheVersion candOrder = cand.serializableOrder();
assert candOrder != null : cand;
GridCacheVersion newCandOrder = newCand.serializableOrder();
assert newCandOrder != null : newCand;
int cmp = SER_VER_COMPARATOR.compare(candOrder, newCandOrder);
assert cmp != 0;
return cmp < 0;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheUtils method createBackupPostProcessingClosure.
/**
* Creates closure that saves initial value to backup partition.
* <p>
* Useful only when store with readThrough is used. In situation when
* get() on backup node returns successful result, it's expected that
* localPeek() will be successful as well. But it isn't true when
* primary node loaded value from local store, in this case backups
* will remain non-initialized.
* <br>
* To meet that requirement the value requested from primary should
* be saved on backup during get().
* </p>
*
* @param topVer Topology version.
* @param log Logger.
* @param cctx Cache context.
* @param key Key.
* @param expiryPlc Expiry policy.
* @param readThrough Read through.
* @param skipVals Skip values.
*/
@Nullable
public static BackupPostProcessingClosure createBackupPostProcessingClosure(final AffinityTopologyVersion topVer, final IgniteLogger log, final GridCacheContext cctx, @Nullable final KeyCacheObject key, @Nullable final IgniteCacheExpiryPolicy expiryPlc, boolean readThrough, boolean skipVals) {
if (cctx.mvccEnabled() || !readThrough || skipVals || (key != null && !cctx.affinity().backupsByKey(key, topVer).contains(cctx.localNode())))
return null;
return new BackupPostProcessingClosure() {
private void process(KeyCacheObject key, CacheObject val, GridCacheVersion ver, GridDhtCacheAdapter colocated) {
while (true) {
GridCacheEntryEx entry = null;
cctx.shared().database().checkpointReadLock();
try {
entry = colocated.entryEx(key, topVer);
entry.initialValue(val, ver, expiryPlc == null ? 0 : expiryPlc.forCreate(), expiryPlc == null ? 0 : toExpireTime(expiryPlc.forCreate()), true, topVer, GridDrType.DR_BACKUP, true, false);
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry during postprocessing (will retry): " + entry);
} catch (IgniteCheckedException e) {
U.error(log, "Error saving backup value: " + entry, e);
throw new GridClosureException(e);
} catch (GridDhtInvalidPartitionException ignored) {
break;
} finally {
if (entry != null)
entry.touch();
cctx.shared().database().checkpointReadUnlock();
}
}
}
@Override
public void apply(CacheObject val, GridCacheVersion ver) {
process(key, val, ver, cctx.dht());
}
@Override
public void apply(Collection<GridCacheEntryInfo> infos) {
if (!F.isEmpty(infos)) {
GridCacheAffinityManager aff = cctx.affinity();
ClusterNode locNode = cctx.localNode();
GridDhtCacheAdapter colocated = cctx.cache().isNear() ? ((GridNearCacheAdapter) cctx.cache()).dht() : cctx.dht();
for (GridCacheEntryInfo info : infos) {
// Save backup value.
if (aff.backupsByKey(info.key(), topVer).contains(locNode))
process(info.key(), info.value(), info.version(), colocated);
}
}
}
};
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class RecordDataV1Serializer method readPlainDataEntry.
/**
* @param in Input to read from.
* @return Read entry.
*/
DataEntry readPlainDataEntry(ByteBufferBackedDataInput in, RecordType type) throws IOException, IgniteCheckedException {
int cacheId = in.readInt();
int keySize = in.readInt();
byte keyType = in.readByte();
byte[] keyBytes = new byte[keySize];
in.readFully(keyBytes);
int valSize = in.readInt();
byte valType = 0;
byte[] valBytes = null;
if (valSize >= 0) {
valType = in.readByte();
valBytes = new byte[valSize];
in.readFully(valBytes);
}
byte ord = in.readByte();
GridCacheOperation op = GridCacheOperation.fromOrdinal(ord & 0xFF);
GridCacheVersion nearXidVer = readVersion(in, true);
GridCacheVersion writeVer = readVersion(in, false);
int partId = in.readInt();
long partCntr = in.readLong();
long expireTime = in.readLong();
byte flags = type == DATA_RECORD_V2 ? in.readByte() : (byte) 0;
GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
if (cacheCtx != null) {
CacheObjectContext coCtx = cacheCtx.cacheObjectContext();
KeyCacheObject key = co.toKeyCacheObject(coCtx, keyType, keyBytes);
if (key.partition() == -1)
key.partition(partId);
CacheObject val = valBytes != null ? co.toCacheObject(coCtx, valType, valBytes) : null;
return new DataEntry(cacheId, key, val, op, nearXidVer, writeVer, expireTime, partId, partCntr, flags);
} else
return new LazyDataEntry(cctx, cacheId, keyType, keyBytes, valType, valBytes, op, nearXidVer, writeVer, expireTime, partId, partCntr, flags);
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method clearCache.
/**
* Clears offheap entries.
*
* @param readers {@code True} to clear readers.
*/
@Override
public void clearCache(GridCacheContext cctx, boolean readers) {
GridCacheVersion obsoleteVer = null;
try (GridCloseableIterator<CacheDataRow> it = grp.isLocal() ? iterator(cctx.cacheId(), cacheDataStores().iterator(), null, null) : evictionSafeIterator(cctx.cacheId(), cacheDataStores().iterator())) {
while (it.hasNext()) {
cctx.shared().database().checkpointReadLock();
try {
KeyCacheObject key = it.next().key();
try {
if (obsoleteVer == null)
obsoleteVer = cctx.cache().nextVersion();
GridCacheEntryEx entry = cctx.cache().entryEx(key);
entry.clear(obsoleteVer, readers);
} catch (GridDhtInvalidPartitionException ignore) {
// Ignore.
} catch (IgniteCheckedException e) {
U.error(log, "Failed to clear cache entry: " + key, e);
}
} finally {
cctx.shared().database().checkpointReadUnlock();
}
}
} catch (IgniteCheckedException e) {
U.error(log, "Failed to close iterator", e);
}
}
Aggregations