use of org.apache.ignite.internal.processors.cache.CacheGroupDescriptor in project ignite by apache.
the class IgniteSnapshotManager method createSnapshot.
/**
* {@inheritDoc}
*/
@Override
public IgniteFuture<Void> createSnapshot(String name) {
A.notNullOrEmpty(name, "Snapshot name cannot be null or empty.");
A.ensure(U.alphanumericUnderscore(name), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
try {
cctx.kernalContext().security().authorize(ADMIN_SNAPSHOT);
if (!IgniteFeatures.allNodesSupports(cctx.discovery().aliveServerNodes(), PERSISTENCE_CACHE_SNAPSHOT))
throw new IgniteException("Not all nodes in the cluster support a snapshot operation.");
if (!CU.isPersistenceEnabled(cctx.gridConfig())) {
throw new IgniteException("Create snapshot request has been rejected. Snapshots on an in-memory " + "clusters are not allowed.");
}
if (!cctx.kernalContext().state().clusterState().state().active())
throw new IgniteException("Snapshot operation has been rejected. The cluster is inactive.");
DiscoveryDataClusterState clusterState = cctx.kernalContext().state().clusterState();
if (!clusterState.hasBaselineTopology())
throw new IgniteException("Snapshot operation has been rejected. The baseline topology is not configured for cluster.");
if (cctx.kernalContext().clientNode()) {
ClusterNode crd = U.oldest(cctx.kernalContext().discovery().aliveServerNodes(), null);
if (crd == null)
throw new IgniteException("There is no alive server nodes in the cluster");
return new IgniteSnapshotFutureImpl(cctx.kernalContext().closure().callAsyncNoFailover(BALANCE, new CreateSnapshotCallable(name), Collections.singletonList(crd), false, 0, true));
}
ClusterSnapshotFuture snpFut0;
synchronized (snpOpMux) {
if (clusterSnpFut != null && !clusterSnpFut.isDone()) {
throw new IgniteException("Create snapshot request has been rejected. The previous snapshot operation was not completed.");
}
if (clusterSnpReq != null)
throw new IgniteException("Create snapshot request has been rejected. Parallel snapshot processes are not allowed.");
if (localSnapshotNames().contains(name)) {
throw new IgniteException("Create snapshot request has been rejected. Snapshot with given name already exists on local node.");
}
if (isRestoring()) {
throw new IgniteException("Snapshot operation has been rejected. Cache group restore operation is currently in progress.");
}
snpFut0 = new ClusterSnapshotFuture(UUID.randomUUID(), name);
clusterSnpFut = snpFut0;
lastSeenSnpFut = snpFut0;
}
List<String> grps = cctx.cache().persistentGroups().stream().filter(g -> cctx.cache().cacheType(g.cacheOrGroupName()) == CacheType.USER).map(CacheGroupDescriptor::cacheOrGroupName).collect(Collectors.toList());
grps.add(METASTORAGE_CACHE_NAME);
List<ClusterNode> srvNodes = cctx.discovery().serverNodes(AffinityTopologyVersion.NONE);
snpFut0.listen(f -> {
if (f.error() == null)
recordSnapshotEvent(name, SNAPSHOT_FINISHED_MSG + grps, EVT_CLUSTER_SNAPSHOT_FINISHED);
else
recordSnapshotEvent(name, SNAPSHOT_FAILED_MSG + f.error().getMessage(), EVT_CLUSTER_SNAPSHOT_FAILED);
});
startSnpProc.start(snpFut0.rqId, new SnapshotOperationRequest(snpFut0.rqId, cctx.localNodeId(), name, grps, new HashSet<>(F.viewReadOnly(srvNodes, F.node2id(), (node) -> CU.baselineNode(node, clusterState)))));
String msg = "Cluster-wide snapshot operation started [snpName=" + name + ", grps=" + grps + ']';
recordSnapshotEvent(name, msg, EVT_CLUSTER_SNAPSHOT_STARTED);
if (log.isInfoEnabled())
log.info(msg);
return new IgniteFutureImpl<>(snpFut0);
} catch (Exception e) {
recordSnapshotEvent(name, SNAPSHOT_FAILED_MSG + e.getMessage(), EVT_CLUSTER_SNAPSHOT_FAILED);
U.error(log, SNAPSHOT_FAILED_MSG, e);
lastSeenSnpFut = new ClusterSnapshotFuture(name, e);
return new IgniteFinishedFutureImpl<>(e);
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupDescriptor in project ignite by apache.
the class GridCacheDatabaseSharedManager method cleanupRestoredCaches.
/**
* {@inheritDoc}
*/
@Override
public void cleanupRestoredCaches() {
if (dataRegionMap.isEmpty())
return;
boolean hasMvccCache = false;
for (CacheGroupDescriptor grpDesc : cctx.cache().cacheGroupDescriptors().values()) {
hasMvccCache |= grpDesc.config().getAtomicityMode() == TRANSACTIONAL_SNAPSHOT;
String regionName = grpDesc.config().getDataRegionName();
DataRegion region = regionName != null ? dataRegionMap.get(regionName) : dfltDataRegion;
if (region == null)
continue;
if (log.isInfoEnabled())
log.info("Page memory " + region.config().getName() + " for " + grpDesc + " has invalidated.");
int partitions = grpDesc.config().getAffinity().partitions();
if (region.pageMemory() instanceof PageMemoryEx) {
PageMemoryEx memEx = (PageMemoryEx) region.pageMemory();
for (int partId = 0; partId < partitions; partId++) memEx.invalidate(grpDesc.groupId(), partId);
memEx.invalidate(grpDesc.groupId(), PageIdAllocator.INDEX_PARTITION);
}
if (grpDesc.config().isEncryptionEnabled())
cctx.kernalContext().encryption().onCacheGroupStop(grpDesc.groupId());
}
if (!hasMvccCache && dataRegionMap.containsKey(TxLog.TX_LOG_CACHE_NAME)) {
PageMemory memory = dataRegionMap.get(TxLog.TX_LOG_CACHE_NAME).pageMemory();
if (memory instanceof PageMemoryEx)
((PageMemoryEx) memory).invalidate(TxLog.TX_LOG_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
}
final boolean hasMvccCache0 = hasMvccCache;
storeMgr.cleanupPageStoreIfMatch(new Predicate<Integer>() {
@Override
public boolean test(Integer grpId) {
return MetaStorage.METASTORAGE_CACHE_ID != grpId && (TxLog.TX_LOG_CACHE_ID != grpId || !hasMvccCache0);
}
}, true);
}
use of org.apache.ignite.internal.processors.cache.CacheGroupDescriptor in project ignite by apache.
the class IgnitePdsCacheAssignmentNodeRestartsTest method validateDepIds.
/**
* @param grpCnt Group count.
*/
private void validateDepIds(int grpCnt) {
Map<Integer, IgniteUuid> depIds = new HashMap<>();
for (Ignite ignite : G.allGrids()) {
final Map<Integer, CacheGroupDescriptor> descMap = ((IgniteEx) ignite).context().cache().cacheGroupDescriptors();
for (Map.Entry<Integer, CacheGroupDescriptor> entry : descMap.entrySet()) {
final IgniteUuid u = entry.getValue().deploymentId();
final IgniteUuid u0 = depIds.get(entry.getKey());
if (u0 == null)
depIds.put(entry.getKey(), u);
else
assertEquals("Descriptors do not match", u0, u);
}
}
assertEquals(grpCnt + 1, depIds.size());
}
use of org.apache.ignite.internal.processors.cache.CacheGroupDescriptor in project ignite by apache.
the class AbstractSnapshotSelfTest method ensureCacheAbsent.
/**
* @param ccfg Cache configuration.
* @throws IgniteCheckedException if failed.
*/
protected void ensureCacheAbsent(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException {
String cacheName = ccfg.getName();
for (Ignite ignite : G.allGrids()) {
GridKernalContext kctx = ((IgniteEx) ignite).context();
if (kctx.clientNode())
continue;
CacheGroupDescriptor desc = kctx.cache().cacheGroupDescriptors().get(CU.cacheId(cacheName));
assertNull("nodeId=" + kctx.localNodeId() + ", cache=" + cacheName, desc);
boolean success = GridTestUtils.waitForCondition(() -> !kctx.cache().context().snapshotMgr().isRestoring(), TIMEOUT);
assertTrue("The process has not finished on the node " + kctx.localNodeId(), success);
File dir = ((FilePageStoreManager) kctx.cache().context().pageStore()).cacheWorkDir(ccfg);
String errMsg = String.format("%s, dir=%s, exists=%b, files=%s", ignite.name(), dir, dir.exists(), Arrays.toString(dir.list()));
assertTrue(errMsg, !dir.exists() || dir.list().length == 0);
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupDescriptor in project ignite by apache.
the class CachePartitionLossWithRestartsTest method waitForDetection.
/**
* @param node Node.
* @param topVer Topology version.
*/
private GridDhtPartitionTopology waitForDetection(IgniteEx node, AffinityTopologyVersion topVer) throws Exception {
GridCacheSharedContext<Object, Object> cctx = node.context().cache().context();
CacheGroupDescriptor desc = cctx.affinity().cacheGroups().get(CU.cacheId(DEFAULT_CACHE_NAME));
CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId());
GridDhtPartitionTopology top = grp != null ? grp.topology() : cctx.exchange().clientTopology(desc.groupId(), null);
cctx.exchange().affinityReadyFuture(topVer).get();
cctx.exchange().lastTopologyFuture().get();
return top;
}
Aggregations