use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class IgniteDrDataStreamerCacheUpdater method receive.
/**
* {@inheritDoc}
*/
@Override
public void receive(IgniteCache<KeyCacheObject, CacheObject> cache0, Collection<Map.Entry<KeyCacheObject, CacheObject>> col) {
try {
String cacheName = cache0.getConfiguration(CacheConfiguration.class).getName();
GridKernalContext ctx = ((IgniteKernal) cache0.unwrap(Ignite.class)).context();
IgniteLogger log = ctx.log(IgniteDrDataStreamerCacheUpdater.class);
GridCacheAdapter internalCache = ctx.cache().internalCache(cacheName);
CacheOperationContext opCtx = ((IgniteCacheProxy) cache0).context().operationContextPerCall();
IgniteInternalCache cache = opCtx != null ? new GridCacheProxyImpl(internalCache.context(), internalCache, opCtx) : internalCache;
assert !F.isEmpty(col);
if (log.isDebugEnabled())
log.debug("Running DR put job [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
CacheObjectContext cacheObjCtx = cache.context().cacheObjectContext();
for (Map.Entry<KeyCacheObject, CacheObject> entry0 : col) {
GridCacheRawVersionedEntry entry = (GridCacheRawVersionedEntry) entry0;
entry.unmarshal(cacheObjCtx, ctx.config().getMarshaller());
KeyCacheObject key = entry.getKey();
// Ensure that receiver to not receive special-purpose values for TTL and expire time.
assert entry.ttl() != CU.TTL_NOT_CHANGED && entry.ttl() != CU.TTL_ZERO && entry.ttl() >= 0;
assert entry.expireTime() != CU.EXPIRE_TIME_CALCULATE && entry.expireTime() >= 0;
CacheObject cacheVal = entry.getValue();
GridCacheDrInfo val = cacheVal != null ? entry.ttl() != CU.TTL_ETERNAL ? new GridCacheDrExpirationInfo(cacheVal, entry.version(), entry.ttl(), entry.expireTime()) : new GridCacheDrInfo(cacheVal, entry.version()) : null;
if (val == null)
cache.removeAllConflict(Collections.singletonMap(key, entry.version()));
else
cache.putAllConflict(Collections.singletonMap(key, val));
}
if (log.isDebugEnabled())
log.debug("DR put job finished [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class GridCachePartitionExchangeManager method onClusterStateChangeFinish.
/**
*/
private void onClusterStateChangeFinish(IgniteInternalFuture<AffinityTopologyVersion> fut, ExchangeActions exchActions, boolean baselineChanging) {
A.notNull(exchActions, "exchActions");
GridEventStorageManager evtMngr = cctx.kernalContext().event();
if (exchActions.activate() && evtMngr.isRecordable(EVT_CLUSTER_ACTIVATED) || exchActions.deactivate() && evtMngr.isRecordable(EVT_CLUSTER_DEACTIVATED) || exchActions.changedClusterState() && evtMngr.isRecordable(EVT_CLUSTER_STATE_CHANGED)) {
List<Event> evts = new ArrayList<>(2);
ClusterNode locNode = cctx.kernalContext().discovery().localNode();
Collection<BaselineNode> bltNodes = cctx.kernalContext().cluster().get().currentBaselineTopology();
boolean collectionUsed = false;
if (exchActions.activate() && evtMngr.isRecordable(EVT_CLUSTER_ACTIVATED)) {
assert !exchActions.deactivate() : exchActions;
collectionUsed = true;
evts.add(new ClusterActivationEvent(locNode, "Cluster activated.", EVT_CLUSTER_ACTIVATED, bltNodes));
}
if (exchActions.deactivate() && evtMngr.isRecordable(EVT_CLUSTER_DEACTIVATED)) {
assert !exchActions.activate() : exchActions;
collectionUsed = true;
evts.add(new ClusterActivationEvent(locNode, "Cluster deactivated.", EVT_CLUSTER_DEACTIVATED, bltNodes));
}
if (exchActions.changedClusterState() && evtMngr.isRecordable(EVT_CLUSTER_STATE_CHANGED)) {
StateChangeRequest req = exchActions.stateChangeRequest();
if (collectionUsed && bltNodes != null)
bltNodes = new ArrayList<>(bltNodes);
evts.add(new ClusterStateChangeEvent(req.prevState(), req.state(), bltNodes, locNode, "Cluster state changed."));
}
A.notEmpty(evts, "events " + exchActions);
cctx.kernalContext().pools().getSystemExecutorService().submit(() -> evts.forEach(e -> cctx.kernalContext().event().record(e)));
}
GridKernalContext ctx = cctx.kernalContext();
DiscoveryDataClusterState state = ctx.state().clusterState();
if (baselineChanging) {
ctx.pools().getStripedExecutorService().execute(new Runnable() {
@Override
public void run() {
if (ctx.event().isRecordable(EventType.EVT_BASELINE_CHANGED)) {
ctx.event().record(new BaselineChangedEvent(ctx.discovery().localNode(), "Baseline changed.", EventType.EVT_BASELINE_CHANGED, ctx.cluster().get().currentBaselineTopology()));
}
}
});
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class FilePageStoreManager method start0.
/**
* {@inheritDoc}
*/
@Override
public void start0() throws IgniteCheckedException {
final GridKernalContext ctx = cctx.kernalContext();
if (ctx.clientNode())
return;
final PdsFolderSettings folderSettings = ctx.pdsFolderResolver().resolveFolders();
storeWorkDir = folderSettings.persistentStoreNodePath();
U.ensureDirectory(storeWorkDir, "page store work directory", log);
String tmpDir = System.getProperty("java.io.tmpdir");
if (tmpDir != null && storeWorkDir.getAbsolutePath().startsWith(tmpDir)) {
log.warning("Persistence store directory is in the temp directory and may be cleaned." + "To avoid this set \"IGNITE_HOME\" environment variable properly or " + "change location of persistence directories in data storage configuration " + "(see DataStorageConfiguration#walPath, DataStorageConfiguration#walArchivePath, " + "DataStorageConfiguration#storagePath properties). " + "Current persistence store directory is: [" + storeWorkDir.getAbsolutePath() + "]");
}
File[] files = storeWorkDir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
File[] tmpFiles = file.listFiles((k, v) -> v.endsWith(CACHE_DATA_TMP_FILENAME));
if (tmpFiles != null) {
for (File tmpFile : tmpFiles) {
if (!tmpFile.delete())
log.warning("Failed to delete temporary cache config file" + "(make sure Ignite process has enough rights):" + file.getName());
}
}
}
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class IgniteSnapshotManager method start0.
/**
* {@inheritDoc}
*/
@Override
protected void start0() throws IgniteCheckedException {
super.start0();
GridKernalContext ctx = cctx.kernalContext();
if (ctx.clientNode())
return;
if (!CU.isPersistenceEnabled(ctx.config()))
return;
assert cctx.pageStore() instanceof FilePageStoreManager;
storeMgr = (FilePageStoreManager) cctx.pageStore();
pdsSettings = cctx.kernalContext().pdsFolderResolver().resolveFolders();
locSnpDir = resolveSnapshotWorkDirectory(ctx.config());
tmpWorkDir = U.resolveWorkDirectory(storeMgr.workDir().getAbsolutePath(), DFLT_SNAPSHOT_TMP_DIR, true);
U.ensureDirectory(locSnpDir, "snapshot work directory", log);
U.ensureDirectory(tmpWorkDir, "temp directory for snapshot creation", log);
handlers.initialize(ctx, ctx.pools().getSnapshotExecutorService());
MetricRegistry mreg = cctx.kernalContext().metric().registry(SNAPSHOT_METRICS);
mreg.register("LastSnapshotStartTime", () -> lastSeenSnpFut.startTime, "The system time of the last cluster snapshot request start time on this node.");
mreg.register("LastSnapshotEndTime", () -> lastSeenSnpFut.endTime, "The system time of the last cluster snapshot request end time on this node.");
mreg.register("LastSnapshotName", () -> lastSeenSnpFut.name, String.class, "The name of last started cluster snapshot request on this node.");
mreg.register("LastSnapshotErrorMessage", () -> lastSeenSnpFut.error() == null ? "" : lastSeenSnpFut.error().getMessage(), String.class, "The error message of last started cluster snapshot request which fail with an error. " + "This value will be empty if last snapshot request has been completed successfully.");
mreg.register("LocalSnapshotNames", this::localSnapshotNames, List.class, "The list of names of all snapshots currently saved on the local node with respect to " + "the configured via IgniteConfiguration snapshot working path.");
restoreCacheGrpProc.registerMetrics();
cctx.exchange().registerExchangeAwareComponent(this);
ctx.internalSubscriptionProcessor().registerMetastorageListener(this);
cctx.gridEvents().addDiscoveryEventListener(discoLsnr = (evt, discoCache) -> {
if (!busyLock.enterBusy())
return;
try {
UUID leftNodeId = evt.eventNode().id();
if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
SnapshotOperationRequest snpReq = clusterSnpReq;
String err = "Snapshot operation interrupted, because baseline node left the cluster: " + leftNodeId;
boolean reqNodeLeft = snpReq != null && snpReq.nodes().contains(leftNodeId);
// the final snapshot phase (SNAPSHOT_END), we start it from a new one.
if (reqNodeLeft && snpReq.startStageEnded() && U.isLocalNodeCoordinator(ctx.discovery())) {
snpReq.error(new ClusterTopologyCheckedException(err));
endSnpProc.start(snpReq.requestId(), snpReq);
}
for (AbstractSnapshotFutureTask<?> sctx : locSnpTasks.values()) {
if (sctx.sourceNodeId().equals(leftNodeId) || (reqNodeLeft && snpReq.snapshotName().equals(sctx.snapshotName())))
sctx.acceptException(new ClusterTopologyCheckedException(err));
}
restoreCacheGrpProc.onNodeLeft(leftNodeId);
snpRmtMgr.onNodeLeft(leftNodeId);
}
} finally {
busyLock.leaveBusy();
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
cctx.gridIO().addMessageListener(DFLT_INITIAL_SNAPSHOT_TOPIC, snpRmtMgr);
cctx.kernalContext().io().addTransmissionHandler(DFLT_INITIAL_SNAPSHOT_TOPIC, snpRmtMgr);
ctx.systemView().registerView(SNAPSHOT_SYS_VIEW, SNAPSHOT_SYS_VIEW_DESC, new SnapshotViewWalker(), () -> F.flatCollections(F.transform(localSnapshotNames(), this::readSnapshotMetadatas)), this::snapshotViewSupplier);
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class IgniteSnapshotManager method partitionRowIterator.
/**
* @param snpName Snapshot name.
* @param folderName The node folder name, usually it's the same as the U.maskForFileName(consistentId).
* @param grpName Cache group name.
* @param partId Partition id.
* @return Iterator over partition.
* @throws IgniteCheckedException If and error occurs.
*/
public GridCloseableIterator<CacheDataRow> partitionRowIterator(GridKernalContext ctx, String snpName, String folderName, String grpName, int partId) throws IgniteCheckedException {
File snpDir = resolveSnapshotDir(snpName);
File nodePath = new File(snpDir, databaseRelativePath(folderName));
if (!nodePath.exists())
throw new IgniteCheckedException("Consistent id directory doesn't exists: " + nodePath.getAbsolutePath());
List<File> grps = cacheDirectories(nodePath, name -> name.equals(grpName));
if (F.isEmpty(grps)) {
throw new IgniteCheckedException("The snapshot cache group not found [dir=" + snpDir.getAbsolutePath() + ", grpName=" + grpName + ']');
}
if (grps.size() > 1) {
throw new IgniteCheckedException("The snapshot cache group directory cannot be uniquely identified [dir=" + snpDir.getAbsolutePath() + ", grpName=" + grpName + ']');
}
File snpPart = getPartitionFile(new File(snapshotLocalDir(snpName), databaseRelativePath(folderName)), grps.get(0).getName(), partId);
int grpId = CU.cacheId(grpName);
FilePageStore pageStore = (FilePageStore) storeMgr.getPageStoreFactory(grpId, cctx.cache().isEncrypted(grpId)).createPageStore(getTypeByPartId(partId), snpPart::toPath, val -> {
});
GridCloseableIterator<CacheDataRow> partIter = partitionRowIterator(ctx, grpName, partId, pageStore);
return new GridCloseableIteratorAdapter<CacheDataRow>() {
/**
* {@inheritDoc}
*/
@Override
protected CacheDataRow onNext() throws IgniteCheckedException {
return partIter.nextX();
}
/**
* {@inheritDoc}
*/
@Override
protected boolean onHasNext() throws IgniteCheckedException {
return partIter.hasNextX();
}
/**
* {@inheritDoc}
*/
@Override
protected void onClose() {
U.closeQuiet(pageStore);
}
};
}
Aggregations