use of org.apache.ignite.internal.processors.cache.database.CacheDataRow in project ignite by apache.
the class SchemaIndexCacheVisitorImpl method processPartition.
/**
* Process partition.
*
* @param part Partition.
* @param clo Index closure.
* @throws IgniteCheckedException If failed.
*/
private void processPartition(GridDhtLocalPartition part, FilteringVisitorClosure clo) throws IgniteCheckedException {
checkCancelled();
boolean reserved = false;
if (part != null && part.state() != EVICTED)
reserved = (part.state() == OWNING || part.state() == RENTING) && part.reserve();
if (!reserved)
return;
try {
GridCursor<? extends CacheDataRow> cursor = part.dataStore().cursor();
while (cursor.next()) {
CacheDataRow row = cursor.get();
KeyCacheObject key = row.key();
processKey(key, row.link(), clo);
}
} finally {
part.release();
}
}
use of org.apache.ignite.internal.processors.cache.database.CacheDataRow in project ignite by apache.
the class H2PkHashIndex method find.
/** {@inheritDoc} */
@Override
public Cursor find(Session ses, final SearchRow lower, final SearchRow upper) {
IndexingQueryFilter f = threadLocalFilter();
IgniteBiPredicate<Object, Object> p = null;
if (f != null) {
String cacheName = getTable().cacheName();
p = f.forCache(cacheName);
}
KeyCacheObject lowerObj = null;
KeyCacheObject upperObj = null;
if (lower != null)
lowerObj = cctx.toCacheKeyObject(lower.getValue(0).getObject());
if (upper != null)
upperObj = cctx.toCacheKeyObject(upper.getValue(0).getObject());
try {
List<GridCursor<? extends CacheDataRow>> cursors = new ArrayList<>();
for (IgniteCacheOffheapManager.CacheDataStore store : cctx.offheap().cacheDataStores()) cursors.add(store.cursor(lowerObj, upperObj));
return new H2Cursor(new CompositeGridCursor<>(cursors.iterator()), p);
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
}
use of org.apache.ignite.internal.processors.cache.database.CacheDataRow in project ignite by apache.
the class IgniteH2Indexing method rebuildIndexesFromHash.
/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
if (tbl == null)
return;
assert tbl.table() != null;
assert tbl.table().rebuildFromHashInProgress();
H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
Cursor cursor = hashIdx.find((Session) null, null, null);
while (cursor.next()) {
CacheDataRow dataRow = (CacheDataRow) cursor.get();
boolean done = false;
while (!done) {
GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
try {
synchronized (entry) {
// TODO : How to correctly get current value and link here?
GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
row.link(dataRow.link());
List<Index> indexes = tbl.table().getAllIndexes();
for (int i = 2; i < indexes.size(); i++) {
Index idx = indexes.get(i);
if (idx instanceof H2TreeIndex)
((H2TreeIndex) idx).put(row);
}
done = true;
}
} catch (GridCacheEntryRemovedException e) {
// No-op
}
}
}
tbl.table().markRebuildFromHashInProgress(false);
}
use of org.apache.ignite.internal.processors.cache.database.CacheDataRow in project ignite by apache.
the class GridDhtLocalPartition method clearAll.
/**
* Clears values for this partition.
*
* @throws NodeStoppingException If node stopping.
*/
public void clearAll() throws NodeStoppingException {
GridCacheVersion clearVer = cctx.versions().next();
boolean rec = cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
Iterator<GridCacheMapEntry> it = allEntries().iterator();
GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer);
while (it.hasNext()) {
GridCacheMapEntry cached = null;
cctx.shared().database().checkpointReadLock();
try {
cached = it.next();
if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
removeEntry(cached);
if (!cached.isInternal()) {
if (rec) {
cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
}
}
}
} catch (GridDhtInvalidPartitionException e) {
assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
// Partition is already concurrently cleared and evicted.
break;
} catch (NodeStoppingException e) {
if (log.isDebugEnabled())
log.debug("Failed to clear cache entry for evicted partition: " + cached.partition());
rent.onDone(e);
throw e;
} catch (IgniteCheckedException e) {
U.error(log, "Failed to clear cache entry for evicted partition: " + cached, e);
} finally {
cctx.shared().database().checkpointReadUnlock();
}
}
if (!cctx.allowFastEviction()) {
try {
GridIterator<CacheDataRow> it0 = cctx.offheap().iterator(id);
while (it0.hasNext()) {
cctx.shared().database().checkpointReadLock();
try {
CacheDataRow row = it0.next();
GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent(cctx.affinity().affinityTopologyVersion(), row.key(), true, false);
if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
if (rec) {
cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
}
}
} catch (GridDhtInvalidPartitionException e) {
assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
// Partition is already concurrently cleared and evicted.
break;
} finally {
cctx.shared().database().checkpointReadUnlock();
}
}
} catch (NodeStoppingException e) {
if (log.isDebugEnabled())
log.debug("Failed to get iterator for evicted partition: " + id);
rent.onDone(e);
throw e;
} catch (IgniteCheckedException e) {
U.error(log, "Failed to get iterator for evicted partition: " + id, e);
}
}
}
use of org.apache.ignite.internal.processors.cache.database.CacheDataRow in project ignite by apache.
the class GridPartitionedSingleGetFuture method localGet.
/**
* @param topVer Topology version.
* @param part Partition.
* @return {@code True} if future completed.
*/
private boolean localGet(AffinityTopologyVersion topVer, int part) {
assert cctx.affinityNode() : this;
GridDhtCacheAdapter colocated = cctx.dht();
boolean readNoEntry = cctx.readNoEntry(expiryPlc, false);
boolean evt = !skipVals;
while (true) {
try {
CacheObject v = null;
GridCacheVersion ver = null;
boolean skipEntry = readNoEntry;
if (readNoEntry) {
CacheDataRow row = cctx.offheap().read(key);
if (row != null) {
long expireTime = row.expireTime();
if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
v = row.value();
if (needVer)
ver = row.version();
if (evt) {
cctx.events().readEvent(key, null, row.value(), subjId, taskName, !deserializeBinary);
}
} else
skipEntry = false;
}
}
if (!skipEntry) {
GridCacheEntryEx entry = colocated.entryEx(key);
// If our DHT cache do has value, then we peek it.
if (entry != null) {
boolean isNew = entry.isNewLocked();
if (needVer) {
EntryGetResult res = entry.innerGetVersioned(null, null, /*update-metrics*/
false, /*event*/
evt, subjId, null, taskName, expiryPlc, true, null);
if (res != null) {
v = res.value();
ver = res.version();
}
} else {
v = entry.innerGet(null, null, /*read-through*/
false, /*update-metrics*/
false, /*event*/
evt, subjId, null, taskName, expiryPlc, true);
}
colocated.context().evicts().touch(entry, topVer);
// Entry was not in memory or in swap, so we remove it from cache.
if (v == null) {
if (isNew && entry.markObsoleteIfEmpty(ver))
colocated.removeEntry(entry);
}
}
}
if (v != null) {
if (!skipVals && cctx.config().isStatisticsEnabled())
cctx.cache().metrics0().onRead(true);
if (!skipVals)
setResult(v, ver);
else
setSkipValueResult(true, ver);
return true;
}
boolean topStable = cctx.isReplicated() || topVer.equals(cctx.topology().topologyVersion());
// Entry not found, complete future with null result if topology did not change and there is no store.
if (!cctx.readThroughConfigured() && (topStable || partitionOwned(part))) {
if (!skipVals && cctx.config().isStatisticsEnabled())
colocated.metrics0().onRead(false);
if (skipVals)
setSkipValueResult(false, null);
else
setResult(null, null);
return true;
}
return false;
} catch (GridCacheEntryRemovedException ignored) {
// No-op, will retry.
} catch (GridDhtInvalidPartitionException ignored) {
return false;
} catch (IgniteCheckedException e) {
onDone(e);
return true;
}
}
}
Aggregations