use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class GridCacheProcessor method onExchangeDone.
/**
* Callback invoked when first exchange future for dynamic cache is completed.
*
* @param cacheStartVer Started caches version to create proxy for.
* @param exchActions Change requests.
* @param err Error.
*/
@SuppressWarnings("unchecked")
public void onExchangeDone(AffinityTopologyVersion cacheStartVer, @Nullable ExchangeActions exchActions, @Nullable Throwable err) {
initCacheProxies(cacheStartVer, err);
if (exchActions == null)
return;
if (exchActions.systemCachesStarting() && exchActions.stateChangeRequest() == null) {
ctx.dataStructures().restoreStructuresState(ctx);
ctx.service().updateUtilityCache();
}
if (err == null) {
// Force checkpoint if there is any cache stop request
if (exchActions.cacheStopRequests().size() > 0) {
try {
sharedCtx.database().waitForCheckpoint("caches stop");
} catch (IgniteCheckedException e) {
U.error(log, "Failed to wait for checkpoint finish during cache stop.", e);
}
}
for (ExchangeActions.CacheActionData action : exchActions.cacheStopRequests()) {
CacheGroupContext gctx = cacheGrps.get(action.descriptor().groupId());
// Cancel all operations blocking gateway
if (gctx != null) {
final String msg = "Failed to wait for topology update, cache group is stopping.";
// If snapshot operation in progress we must throw CacheStoppedException
// for correct cache proxy restart. For more details see
// IgniteCacheProxy.cacheException()
gctx.affinity().cancelFutures(new CacheStoppedException(msg));
}
stopGateway(action.request());
sharedCtx.database().checkpointReadLock();
try {
prepareCacheStop(action.request().cacheName(), action.request().destroy());
} finally {
sharedCtx.database().checkpointReadUnlock();
}
}
sharedCtx.database().checkpointReadLock();
try {
// Do not invoke checkpoint listeners for groups are going to be destroyed to prevent metadata corruption.
for (ExchangeActions.CacheGroupActionData action : exchActions.cacheGroupsToStop()) {
Integer groupId = action.descriptor().groupId();
CacheGroupContext grp = cacheGrps.get(groupId);
if (grp != null && grp.persistenceEnabled() && sharedCtx.database() instanceof GridCacheDatabaseSharedManager) {
GridCacheDatabaseSharedManager mngr = (GridCacheDatabaseSharedManager) sharedCtx.database();
mngr.removeCheckpointListener((DbCheckpointListener) grp.offheap());
}
}
} finally {
sharedCtx.database().checkpointReadUnlock();
}
List<IgniteBiTuple<CacheGroupContext, Boolean>> stoppedGroups = new ArrayList<>();
for (ExchangeActions.CacheGroupActionData action : exchActions.cacheGroupsToStop()) {
Integer groupId = action.descriptor().groupId();
if (cacheGrps.containsKey(groupId)) {
stoppedGroups.add(F.t(cacheGrps.get(groupId), action.destroy()));
stopCacheGroup(groupId);
}
}
if (!sharedCtx.kernalContext().clientNode())
sharedCtx.database().onCacheGroupsStopped(stoppedGroups);
if (exchActions.deactivate())
sharedCtx.deactivate();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class GridDhtPartitionTopologyImpl method initPartitions0.
/**
* @param affVer Affinity version to use.
* @param exchFut Exchange future.
* @param updateSeq Update sequence.
* @return {@code True} if partitions must be refreshed.
*/
private boolean initPartitions0(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture exchFut, long updateSeq) {
List<List<ClusterNode>> aff = grp.affinity().readyAssignments(affVer);
boolean needRefresh = false;
if (grp.affinityNode()) {
ClusterNode loc = ctx.localNode();
ClusterNode oldest = discoCache.oldestAliveServerNode();
GridDhtPartitionExchangeId exchId = exchFut.exchangeId();
assert grp.affinity().lastVersion().equals(affVer) : "Invalid affinity [topVer=" + grp.affinity().lastVersion() + ", grp=" + grp.cacheOrGroupName() + ", affVer=" + affVer + ", fut=" + exchFut + ']';
int num = grp.affinity().partitions();
if (grp.rebalanceEnabled()) {
boolean added = exchFut.cacheGroupAddedOnExchange(grp.groupId(), grp.receivedFrom());
boolean first = added || (loc.equals(oldest) && loc.id().equals(exchId.nodeId()) && exchId.isJoined());
if (first) {
assert exchId.isJoined() || added;
for (int p = 0; p < num; p++) {
if (localNode(p, aff) || initLocalPartition(p, discoCache)) {
GridDhtLocalPartition locPart = createPartition(p);
if (grp.persistenceEnabled()) {
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) grp.shared().database();
locPart.restoreState(db.readPartitionState(grp, locPart.id()));
} else {
boolean owned = locPart.own();
assert owned : "Failed to own partition for oldest node [grp=" + grp.cacheOrGroupName() + ", part=" + locPart + ']';
if (log.isDebugEnabled())
log.debug("Owned partition for oldest node [grp=" + grp.cacheOrGroupName() + ", part=" + locPart + ']');
}
needRefresh = true;
updateSeq = updateLocal(p, locPart.state(), updateSeq, affVer);
}
}
} else
createPartitions(affVer, aff, updateSeq);
} else {
// the partitions this node is not responsible for.
for (int p = 0; p < num; p++) {
GridDhtLocalPartition locPart = localPartition0(p, affVer, false, true, false);
boolean belongs = localNode(p, aff);
if (locPart != null) {
if (!belongs) {
GridDhtPartitionState state = locPart.state();
if (state.active()) {
locPart.rent(false);
updateSeq = updateLocal(p, locPart.state(), updateSeq, affVer);
if (log.isDebugEnabled()) {
log.debug("Evicting partition with rebalancing disabled (it does not belong to " + "affinity) [grp=" + grp.cacheOrGroupName() + ", part=" + locPart + ']');
}
}
} else
locPart.own();
} else if (belongs) {
locPart = createPartition(p);
locPart.own();
updateLocal(p, locPart.state(), updateSeq, affVer);
}
}
}
}
updateRebalanceVersion(aff);
return needRefresh;
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testDataWalEntries.
/**
* @throws Exception if failed.
*/
public void testDataWalEntries() throws Exception {
IgniteEx ig = startGrid(0);
ig.active(true);
GridCacheSharedContext<Object, Object> sharedCtx = ig.context().cache().context();
GridCacheContext<Object, Object> cctx = sharedCtx.cache().cache(cacheName).context();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
IgniteWriteAheadLogManager wal = sharedCtx.wal();
assertTrue(wal.isAlwaysWriteFullPages());
db.enableCheckpoints(false).get();
final int cnt = 10;
List<DataEntry> entries = new ArrayList<>(cnt);
for (int i = 0; i < cnt; i++) {
GridCacheOperation op = i % 2 == 0 ? GridCacheOperation.UPDATE : GridCacheOperation.DELETE;
KeyCacheObject key = cctx.toCacheKeyObject(i);
CacheObject val = null;
if (op != GridCacheOperation.DELETE)
val = cctx.toCacheObject("value-" + i);
entries.add(new DataEntry(cctx.cacheId(), key, val, op, null, cctx.versions().next(), 0L, cctx.affinity().partition(i), i));
}
UUID cpId = UUID.randomUUID();
WALPointer start = wal.log(new CheckpointRecord(cpId, null));
wal.fsync(start);
for (DataEntry entry : entries) wal.log(new DataRecord(entry));
// Data will not be written to the page store.
stopAllGrids();
ig = startGrid(0);
ig.active(true);
sharedCtx = ig.context().cache().context();
cctx = sharedCtx.cache().cache(cacheName).context();
db = (GridCacheDatabaseSharedManager) sharedCtx.database();
wal = sharedCtx.wal();
db.enableCheckpoints(false).get();
try (PartitionMetaStateRecordExcludeIterator it = new PartitionMetaStateRecordExcludeIterator(wal.replay(start))) {
IgniteBiTuple<WALPointer, WALRecord> cpRecordTup = it.next();
assert cpRecordTup.get2() instanceof CheckpointRecord;
assertEquals(start, cpRecordTup.get1());
CheckpointRecord cpRec = (CheckpointRecord) cpRecordTup.get2();
assertEquals(cpId, cpRec.checkpointId());
assertNull(cpRec.checkpointMark());
assertFalse(cpRec.end());
int idx = 0;
CacheObjectContext coctx = cctx.cacheObjectContext();
while (idx < entries.size()) {
IgniteBiTuple<WALPointer, WALRecord> dataRecTup = it.next();
assert dataRecTup.get2() instanceof DataRecord;
DataRecord dataRec = (DataRecord) dataRecTup.get2();
DataEntry entry = entries.get(idx);
assertEquals(1, dataRec.writeEntries().size());
DataEntry readEntry = dataRec.writeEntries().get(0);
assertEquals(entry.cacheId(), readEntry.cacheId());
assertEquals(entry.key().<Integer>value(coctx, true), readEntry.key().<Integer>value(coctx, true));
assertEquals(entry.op(), readEntry.op());
if (entry.op() == GridCacheOperation.UPDATE)
assertEquals(entry.value().value(coctx, true), readEntry.value().value(coctx, true));
else
assertNull(entry.value());
assertEquals(entry.writeVersion(), readEntry.writeVersion());
assertEquals(entry.nearXidVersion(), readEntry.nearXidVersion());
assertEquals(entry.partitionCounter(), readEntry.partitionCounter());
idx++;
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method testCheckpointHistory.
/**
* @throws Exception if failed.
*/
public void testCheckpointHistory() throws Exception {
Ignite ignite = startGrid();
ignite.cluster().active(true);
try {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
dbMgr.waitForCheckpoint("test");
// This number depends on wal history size.
int entries = WAL_HIST_SIZE * 2;
IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
for (int i = 0; i < entries; i++) {
// Put to partition 0.
cache.put(i * PARTS, i * PARTS);
// Put to partition 1.
cache.put(i * PARTS + 1, i * PARTS + 1);
dbMgr.waitForCheckpoint("test");
}
GridCacheDatabaseSharedManager.CheckpointHistory hist = dbMgr.checkpointHistory();
assertTrue(hist.checkpoints().size() <= WAL_HIST_SIZE);
File cpDir = dbMgr.checkpointDirectory();
File[] cpFiles = cpDir.listFiles();
// starts & ends + node_start
assertTrue(cpFiles.length <= WAL_HIST_SIZE * 2 + 1);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class DiskPageCompressionIntegrationTest method doTestPageCompression.
/**
* @throws Exception If failed.
*/
@Override
protected void doTestPageCompression() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
String cacheName = "test";
CacheConfiguration<Integer, TestVal> ccfg = new CacheConfiguration<Integer, TestVal>().setName(cacheName).setBackups(0).setAtomicityMode(ATOMIC).setIndexedTypes(Integer.class, TestVal.class).setDiskPageCompression(compression).setDiskPageCompressionLevel(compressionLevel);
IgniteCache<Integer, TestVal> cache = ignite.getOrCreateCache(ccfg);
int cnt = 2_000;
for (int i = 0; i < cnt; i++) assertTrue(cache.putIfAbsent(i, new TestVal(i)));
for (int i = 0; i < cnt; i += 2) assertEquals(new TestVal(i), cache.getAndRemove(i));
GridCacheDatabaseSharedManager dbMgr = ((GridCacheDatabaseSharedManager) ignite.context().cache().context().database());
dbMgr.forceCheckpoint("test compression").futureFor(FINISHED).get();
FilePageStoreManager storeMgr = dbMgr.getFileStoreManager();
checkFileIOFactory(storeMgr.getPageStoreFileIoFactory());
// Wait for metrics update.
Thread.sleep(100);
long storeSize = ignite.dataStorageMetrics().getStorageSize();
long sparseStoreSize = ignite.dataStorageMetrics().getSparseStorageSize();
assertTrue("storeSize: " + storeSize, storeSize > 0);
if (U.isLinux()) {
assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
} else
assertTrue(sparseStoreSize < 0);
GridCacheContext<?, ?> cctx = ignite.cachex(cacheName).context();
int cacheId = cctx.cacheId();
int groupId = cctx.groupId();
assertEquals(cacheId, groupId);
MetricRegistry mreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, cctx.group().cacheOrGroupName()));
storeSize = mreg.<LongMetric>findMetric("StorageSize").value();
sparseStoreSize = mreg.<LongMetric>findMetric("SparseStorageSize").value();
assertTrue("storeSize: " + storeSize, storeSize > 0);
if (U.isLinux()) {
assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
} else
assertTrue(sparseStoreSize < 0);
int parts = cctx.affinity().partitions();
for (int i = 0; i < parts; i++) {
PageStore store = storeMgr.getStore(cacheId, i);
long realSize = store.size();
long virtualSize = store.getPageSize() * store.pages();
long sparseSize = store.getSparseSize();
assertTrue(virtualSize > 0);
error("virt: " + virtualSize + ", real: " + realSize + ", sparse: " + sparseSize);
if (!store.exists())
continue;
if (virtualSize > sparseSize)
return;
}
fail("No files were compacted.");
}
Aggregations