Search in sources :

Example 6 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class SnapshotRestoreProcess method preload.

/**
 * @param reqId Request id.
 * @return Future which will be completed when the preload ends.
 */
private IgniteInternalFuture<Boolean> preload(UUID reqId) {
    if (ctx.clientNode())
        return new GridFinishedFuture<>();
    SnapshotRestoreContext opCtx0 = opCtx;
    GridFutureAdapter<Boolean> retFut = new GridFutureAdapter<>();
    if (opCtx0 == null)
        return new GridFinishedFuture<>(new IgniteCheckedException("Snapshot restore process has incorrect restore state: " + reqId));
    if (opCtx0.dirs.isEmpty())
        return new GridFinishedFuture<>();
    try {
        if (ctx.isStopping())
            throw new NodeStoppingException("Node is stopping: " + ctx.localNodeId());
        Set<SnapshotMetadata> allMetas = opCtx0.metasPerNode.values().stream().flatMap(List::stream).collect(Collectors.toSet());
        AbstractSnapshotVerificationTask.checkMissedMetadata(allMetas);
        IgniteSnapshotManager snpMgr = ctx.cache().context().snapshotMgr();
        synchronized (this) {
            opCtx0.stopFut = new IgniteFutureImpl<>(retFut.chain(f -> null));
        }
        if (log.isInfoEnabled()) {
            log.info("Starting snapshot preload operation to restore cache groups " + "[reqId=" + reqId + ", snapshot=" + opCtx0.snpName + ", caches=" + F.transform(opCtx0.dirs, FilePageStoreManager::cacheGroupName) + ']');
        }
        CompletableFuture<Void> metaFut = ctx.localNodeId().equals(opCtx0.opNodeId) ? CompletableFuture.runAsync(() -> {
            try {
                SnapshotMetadata meta = F.first(opCtx0.metasPerNode.get(opCtx0.opNodeId));
                File binDir = binaryWorkDir(snpMgr.snapshotLocalDir(opCtx0.snpName).getAbsolutePath(), meta.folderName());
                ctx.cacheObjects().updateMetadata(binDir, opCtx0.stopChecker);
            } catch (Throwable t) {
                log.error("Unable to perform metadata update operation for the cache groups restore process", t);
                opCtx0.errHnd.accept(t);
            }
        }, snpMgr.snapshotExecutorService()) : CompletableFuture.completedFuture(null);
        Map<String, GridAffinityAssignmentCache> affCache = new HashMap<>();
        for (StoredCacheData data : opCtx0.cfgs.values()) {
            affCache.computeIfAbsent(CU.cacheOrGroupName(data.config()), grp -> calculateAffinity(ctx, data.config(), opCtx0.discoCache));
        }
        Map<Integer, Set<PartitionRestoreFuture>> allParts = new HashMap<>();
        Map<Integer, Set<PartitionRestoreFuture>> rmtLoadParts = new HashMap<>();
        ClusterNode locNode = ctx.cache().context().localNode();
        List<SnapshotMetadata> locMetas = opCtx0.metasPerNode.get(locNode.id());
        // First preload everything from the local node.
        for (File dir : opCtx0.dirs) {
            String cacheOrGrpName = cacheGroupName(dir);
            int grpId = CU.cacheId(cacheOrGrpName);
            File tmpCacheDir = formatTmpDirName(dir);
            tmpCacheDir.mkdir();
            Set<PartitionRestoreFuture> leftParts;
            // Partitions contained in the snapshot.
            Set<Integer> availParts = new HashSet<>();
            for (SnapshotMetadata meta : allMetas) {
                Set<Integer> parts = meta.partitions().get(grpId);
                if (parts != null)
                    availParts.addAll(parts);
            }
            List<List<ClusterNode>> assignment = affCache.get(cacheOrGrpName).idealAssignment().assignment();
            Set<PartitionRestoreFuture> partFuts = availParts.stream().filter(p -> p != INDEX_PARTITION && assignment.get(p).contains(locNode)).map(p -> new PartitionRestoreFuture(p, opCtx0.processedParts)).collect(Collectors.toSet());
            allParts.put(grpId, partFuts);
            rmtLoadParts.put(grpId, leftParts = new HashSet<>(partFuts));
            if (leftParts.isEmpty())
                continue;
            SnapshotMetadata full = findMetadataWithSamePartitions(locMetas, grpId, leftParts.stream().map(p -> p.partId).collect(Collectors.toSet()));
            for (SnapshotMetadata meta : full == null ? locMetas : Collections.singleton(full)) {
                if (leftParts.isEmpty())
                    break;
                File snpCacheDir = new File(ctx.cache().context().snapshotMgr().snapshotLocalDir(opCtx0.snpName), Paths.get(databaseRelativePath(meta.folderName()), dir.getName()).toString());
                leftParts.removeIf(partFut -> {
                    boolean doCopy = ofNullable(meta.partitions().get(grpId)).orElse(Collections.emptySet()).contains(partFut.partId);
                    if (doCopy) {
                        copyLocalAsync(ctx.cache().context().snapshotMgr(), opCtx0, snpCacheDir, tmpCacheDir, partFut);
                    }
                    return doCopy;
                });
                if (meta == full) {
                    assert leftParts.isEmpty() : leftParts;
                    if (log.isInfoEnabled()) {
                        log.info("The snapshot was taken on the same cluster topology. The index will be copied to " + "restoring cache group if necessary [reqId=" + reqId + ", snapshot=" + opCtx0.snpName + ", dir=" + dir.getName() + ']');
                    }
                    File idxFile = new File(snpCacheDir, FilePageStoreManager.getPartitionFileName(INDEX_PARTITION));
                    if (idxFile.exists()) {
                        PartitionRestoreFuture idxFut;
                        allParts.computeIfAbsent(grpId, g -> new HashSet<>()).add(idxFut = new PartitionRestoreFuture(INDEX_PARTITION, opCtx0.processedParts));
                        copyLocalAsync(ctx.cache().context().snapshotMgr(), opCtx0, snpCacheDir, tmpCacheDir, idxFut);
                    }
                }
            }
        }
        // Load other partitions from remote nodes.
        List<PartitionRestoreFuture> rmtAwaitParts = rmtLoadParts.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
        // This is necessary for sending only one partitions request per each cluster node.
        Map<UUID, Map<Integer, Set<Integer>>> snpAff = snapshotAffinity(opCtx0.metasPerNode.entrySet().stream().filter(e -> !e.getKey().equals(ctx.localNodeId())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), (grpId, partId) -> rmtLoadParts.get(grpId) != null && rmtLoadParts.get(grpId).remove(new PartitionRestoreFuture(partId, opCtx0.processedParts)));
        Map<Integer, File> grpToDir = opCtx0.dirs.stream().collect(Collectors.toMap(d -> CU.cacheId(FilePageStoreManager.cacheGroupName(d)), d -> d));
        try {
            if (log.isInfoEnabled() && !snpAff.isEmpty()) {
                log.info("Trying to request partitions from remote nodes " + "[reqId=" + reqId + ", snapshot=" + opCtx0.snpName + ", map=" + snpAff.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> partitionsMapToCompactString(e.getValue()))) + ']');
            }
            for (Map.Entry<UUID, Map<Integer, Set<Integer>>> m : snpAff.entrySet()) {
                ctx.cache().context().snapshotMgr().requestRemoteSnapshotFiles(m.getKey(), opCtx0.snpName, m.getValue(), opCtx0.stopChecker, (snpFile, t) -> {
                    if (opCtx0.stopChecker.getAsBoolean())
                        throw new IgniteInterruptedException("Snapshot remote operation request cancelled.");
                    if (t == null) {
                        int grpId = CU.cacheId(cacheGroupName(snpFile.getParentFile()));
                        int partId = partId(snpFile.getName());
                        PartitionRestoreFuture partFut = F.find(allParts.get(grpId), null, new IgnitePredicate<PartitionRestoreFuture>() {

                            @Override
                            public boolean apply(PartitionRestoreFuture f) {
                                return f.partId == partId;
                            }
                        });
                        assert partFut != null : snpFile.getAbsolutePath();
                        File tmpCacheDir = formatTmpDirName(grpToDir.get(grpId));
                        Path partFile = Paths.get(tmpCacheDir.getAbsolutePath(), snpFile.getName());
                        try {
                            Files.move(snpFile.toPath(), partFile);
                            partFut.complete(partFile);
                        } catch (Exception e) {
                            opCtx0.errHnd.accept(e);
                            completeListExceptionally(rmtAwaitParts, e);
                        }
                    } else {
                        opCtx0.errHnd.accept(t);
                        completeListExceptionally(rmtAwaitParts, t);
                    }
                });
            }
        } catch (IgniteCheckedException e) {
            opCtx0.errHnd.accept(e);
            completeListExceptionally(rmtAwaitParts, e);
        }
        List<PartitionRestoreFuture> allPartFuts = allParts.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
        int size = allPartFuts.size();
        opCtx0.totalParts = size;
        CompletableFuture.allOf(allPartFuts.toArray(new CompletableFuture[size])).runAfterBothAsync(metaFut, () -> {
            try {
                if (opCtx0.stopChecker.getAsBoolean())
                    throw new IgniteInterruptedException("The operation has been stopped on temporary directory switch.");
                for (File src : opCtx0.dirs) Files.move(formatTmpDirName(src).toPath(), src.toPath(), StandardCopyOption.ATOMIC_MOVE);
            } catch (IOException e) {
                throw new IgniteException(e);
            }
        }, snpMgr.snapshotExecutorService()).whenComplete((r, t) -> opCtx0.errHnd.accept(t)).whenComplete((res, t) -> {
            Throwable t0 = ofNullable(opCtx0.err.get()).orElse(t);
            if (t0 == null)
                retFut.onDone(true);
            else {
                log.error("Unable to restore cache group(s) from a snapshot " + "[reqId=" + opCtx.reqId + ", snapshot=" + opCtx.snpName + ']', t0);
                retFut.onDone(t0);
            }
        });
    } catch (Exception ex) {
        opCtx0.errHnd.accept(ex);
        return new GridFinishedFuture<>(ex);
    }
    return retFut;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) CacheObjectBinaryProcessorImpl.binaryWorkDir(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.binaryWorkDir) RESTORE_CACHE_GROUP_SNAPSHOT_ROLLBACK(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_ROLLBACK) BooleanSupplier(java.util.function.BooleanSupplier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Path(java.nio.file.Path) IgniteFuture(org.apache.ignite.lang.IgniteFuture) FilePageStoreManager.cacheGroupName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheGroupName) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FilePageStoreManager.partId(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.partId) Serializable(java.io.Serializable) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) SNAPSHOT_RESTORE_CACHE_GROUP(org.apache.ignite.internal.IgniteFeatures.SNAPSHOT_RESTORE_CACHE_GROUP) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) CACHE_GRP_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_GRP_DIR_PREFIX) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterSnapshotFuture(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.ClusterSnapshotFuture) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteSnapshotManager.databaseRelativePath(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) BiPredicate(java.util.function.BiPredicate) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) S(org.apache.ignite.internal.util.typedef.internal.S) METASTORAGE_CACHE_NAME(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE) RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) F(org.apache.ignite.internal.util.typedef.F) Files(java.nio.file.Files) Optional.ofNullable(java.util.Optional.ofNullable) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) File(java.io.File) Consumer(java.util.function.Consumer) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) RESTORE_CACHE_GROUP_SNAPSHOT_START(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_START) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl) Collections(java.util.Collections) IgniteUuid(org.apache.ignite.lang.IgniteUuid) Set(java.util.Set) HashSet(java.util.HashSet) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) Path(java.nio.file.Path) IgniteSnapshotManager.databaseRelativePath(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IOException(java.io.IOException) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class GridClusterStateProcessor method listInMemoryUserCaches.

/**
 * @return Lists in-memory user defined caches.
 */
private List<String> listInMemoryUserCaches() {
    IgniteBiPredicate<DynamicCacheDescriptor, DataRegionConfiguration> inMemoryPred = (desc, dataRegionCfg) -> {
        return !(dataRegionCfg != null && dataRegionCfg.isPersistenceEnabled()) && (!desc.cacheConfiguration().isWriteThrough() || !desc.cacheConfiguration().isReadThrough());
    };
    if (ctx.discovery().localNode().isClient()) {
        // Need to check cache descriptors using server node storage configurations.
        // The reason for this is that client node may not be configured with the required data region configuration.
        List<ClusterNode> srvs = ctx.discovery().discoCache().serverNodes();
        if (F.isEmpty(srvs))
            return Collections.emptyList();
        return ctx.cache().cacheDescriptors().values().stream().filter(desc -> !CU.isSystemCache(desc.cacheName())).filter(desc -> {
            String dataRegionName = desc.cacheConfiguration().getDataRegionName();
            // We always should use server data storage configurations instead of client node config,
            // because it is not validated when the client node joins the cluster
            // and so it cannot be the source of truth.
            DataRegionConfiguration dataRegionCfg = null;
            // Need to find out the first server node that knows about this data region and its configuration.
            for (ClusterNode n : srvs) {
                dataRegionCfg = CU.findRemoteDataRegionConfiguration(n, ctx.marshallerContext().jdkMarshaller(), U.resolveClassLoader(ctx.config()), dataRegionName);
                if (dataRegionCfg != null)
                    break;
            }
            return inMemoryPred.apply(desc, dataRegionCfg);
        }).map(DynamicCacheDescriptor::cacheName).collect(Collectors.toList());
    }
    return ctx.cache().cacheDescriptors().values().stream().filter(desc -> !CU.isSystemCache(desc.cacheName())).filter(desc -> {
        String dataRegionName = desc.cacheConfiguration().getDataRegionName();
        DataRegionConfiguration dataRegionCfg = CU.findDataRegionConfiguration(ctx.config().getDataStorageConfiguration(), dataRegionName);
        if (dataRegionCfg == null) {
            List<ClusterNode> srvs = ctx.discovery().discoCache().serverNodes();
            // Need to find out the first server node that knows about this data region and its configuration.
            for (ClusterNode n : srvs) {
                dataRegionCfg = CU.findRemoteDataRegionConfiguration(n, ctx.marshallerContext().jdkMarshaller(), U.resolveClassLoader(ctx.config()), dataRegionName);
                if (dataRegionCfg != null)
                    break;
            }
        }
        return inMemoryPred.apply(desc, dataRegionCfg);
    }).map(DynamicCacheDescriptor::cacheName).collect(Collectors.toList());
}
Also used : GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) BaselineConfigurationChangedEvent(org.apache.ignite.events.BaselineConfigurationChangedEvent) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) MetastorageLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener) DistributedBaselineConfiguration(org.apache.ignite.internal.cluster.DistributedBaselineConfiguration) ReadOnlyMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage) Map(java.util.Map) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) BaselineNodeView(org.apache.ignite.spi.systemview.view.BaselineNodeView) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) BaselineNodeAttributeViewWalker(org.apache.ignite.internal.managers.systemview.walker.BaselineNodeAttributeViewWalker) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) GridCacheUtils.extractDataStorage(org.apache.ignite.internal.processors.cache.GridCacheUtils.extractDataStorage) Serializable(java.io.Serializable) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BaselineNodeAttributeView(org.apache.ignite.spi.systemview.view.BaselineNodeAttributeView) BaselineAutoAdjustStatus(org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatus) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) CLUSTER_READ_ONLY_MODE(org.apache.ignite.internal.IgniteFeatures.CLUSTER_READ_ONLY_MODE) IgniteCompute(org.apache.ignite.IgniteCompute) ClusterStateChangeStartedEvent(org.apache.ignite.events.ClusterStateChangeStartedEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) DFLT_STATE_ON_START(org.apache.ignite.configuration.IgniteConfiguration.DFLT_STATE_ON_START) IgniteLogger(org.apache.ignite.IgniteLogger) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) ReadWriteMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage) S(org.apache.ignite.internal.util.typedef.internal.S) C1(org.apache.ignite.internal.util.typedef.C1) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) EVT_BASELINE_AUTO_ADJUST_ENABLED_CHANGED(org.apache.ignite.events.EventType.EVT_BASELINE_AUTO_ADJUST_ENABLED_CHANGED) A(org.apache.ignite.internal.util.typedef.internal.A) Field(java.lang.reflect.Field) BaselineNode(org.apache.ignite.cluster.BaselineNode) STATE_PROC(org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.STATE_PROC) IgniteClusterImpl(org.apache.ignite.internal.cluster.IgniteClusterImpl) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl) GridProcessorAdapter(org.apache.ignite.internal.processors.GridProcessorAdapter) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) SYSTEM_POOL(org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL) GridChangeGlobalStateMessageResponse(org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse) SAFE_CLUSTER_DEACTIVATION(org.apache.ignite.internal.IgniteFeatures.SAFE_CLUSTER_DEACTIVATION) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) IgniteFuture(org.apache.ignite.lang.IgniteFuture) DistributePropertyListener(org.apache.ignite.internal.processors.configuration.distributed.DistributePropertyListener) EventType(org.apache.ignite.events.EventType) IgniteFeatures.allNodesSupports(org.apache.ignite.internal.IgniteFeatures.allNodesSupports) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) CU(org.apache.ignite.internal.util.typedef.internal.CU) BaselineTopologyUpdater(org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineTopologyUpdater) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) BaselineNodeViewWalker(org.apache.ignite.internal.managers.systemview.walker.BaselineNodeViewWalker) EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED(org.apache.ignite.events.EventType.EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED) HashMap(java.util.HashMap) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) IgniteNodeValidationResult(org.apache.ignite.spi.IgniteNodeValidationResult) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) ClusterNode(org.apache.ignite.cluster.ClusterNode) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)

Example 8 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class GridContinuousProcessor method processStartRequestV2.

/**
 * @param topVer Current topology version.
 * @param snd Sender.
 * @param msg Start request.
 */
private void processStartRequestV2(final AffinityTopologyVersion topVer, final ClusterNode snd, final StartRoutineDiscoveryMessageV2 msg) {
    StartRequestDataV2 reqData = msg.startRequestData();
    ContinuousRoutineInfo routineInfo = new ContinuousRoutineInfo(snd.id(), msg.routineId(), reqData.handlerBytes(), reqData.nodeFilterBytes(), reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe());
    routinesInfo.addRoutineInfo(routineInfo);
    final DiscoCache discoCache = ctx.discovery().discoCache(topVer);
    // Should not use marshaller and send messages from discovery thread.
    ctx.pools().getSystemExecutorService().execute(new Runnable() {

        @Override
        public void run() {
            if (snd.id().equals(ctx.localNodeId())) {
                StartFuture fut = startFuts.get(msg.routineId());
                if (fut != null)
                    fut.initRemoteNodes(discoCache);
                return;
            }
            StartRequestDataV2 reqData = msg.startRequestData();
            Exception err = null;
            IgnitePredicate<ClusterNode> nodeFilter = null;
            byte[] cntrs = null;
            if (reqData.nodeFilterBytes() != null) {
                try {
                    if (ctx.config().isPeerClassLoadingEnabled() && reqData.className() != null) {
                        String clsName = reqData.className();
                        GridDeploymentInfo depInfo = reqData.deploymentInfo();
                        GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), snd.id(), depInfo.classLoaderId(), depInfo.participants(), null);
                        if (dep == null) {
                            throw new IgniteDeploymentCheckedException("Failed to obtain deployment " + "for class: " + clsName);
                        }
                        nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
                    } else {
                        nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(ctx.config()));
                    }
                    if (nodeFilter != null)
                        ctx.resource().injectGeneric(nodeFilter);
                } catch (Exception e) {
                    err = e;
                    U.error(log, "Failed to unmarshal continuous routine filter [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
                }
            }
            boolean register = err == null && (nodeFilter == null || nodeFilter.apply(ctx.discovery().localNode()));
            if (register) {
                try {
                    GridContinuousHandler hnd = U.unmarshal(marsh, reqData.handlerBytes(), U.resolveClassLoader(ctx.config()));
                    if (ctx.config().isPeerClassLoadingEnabled())
                        hnd.p2pUnmarshal(snd.id(), ctx);
                    if (msg.keepBinary()) {
                        assert hnd instanceof CacheContinuousQueryHandler : hnd;
                        ((CacheContinuousQueryHandler) hnd).keepBinary(true);
                    }
                    registerHandler(snd.id(), msg.routineId, hnd, reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe(), false);
                    if (hnd.isQuery()) {
                        GridCacheProcessor proc = ctx.cache();
                        if (proc != null) {
                            GridCacheAdapter cache = ctx.cache().internalCache(hnd.cacheName());
                            if (cache != null && !cache.isLocal() && cache.context().userCache()) {
                                CachePartitionPartialCountersMap cntrsMap = cache.context().topology().localUpdateCounters(false);
                                cntrs = U.marshal(marsh, cntrsMap);
                            }
                        }
                    }
                } catch (Exception e) {
                    err = e;
                    U.error(log, "Failed to register continuous routine handler [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
                }
            }
            sendMessageStartResult(snd, msg.routineId(), cntrs, err);
        }
    });
}
Also used : DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CacheContinuousQueryHandler(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler) GridDeploymentInfo(org.apache.ignite.internal.managers.deployment.GridDeploymentInfo) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable)

Example 9 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class IgniteDiscoveryCacheReuseSelfTest method assertDiscoCacheReuse.

/**
 * Assert disco cache reuse.
 *
 * @param v1 First version.
 * @param v2 Next version.
 */
private void assertDiscoCacheReuse(AffinityTopologyVersion v1, AffinityTopologyVersion v2) {
    for (Ignite ignite : G.allGrids()) {
        GridBoundedConcurrentLinkedHashMap<AffinityTopologyVersion, DiscoCache> discoCacheHist = U.field(((IgniteEx) ignite).context().discovery(), "discoCacheHist");
        DiscoCache discoCache1 = discoCacheHist.get(v1);
        DiscoCache discoCache2 = discoCacheHist.get(v2);
        assertEquals(v1, discoCache1.version());
        assertEquals(v2, discoCache2.version());
        String[] props = new String[] { "state", "loc", "rmtNodes", "allNodes", "srvNodes", "daemonNodes", "rmtNodesWithCaches", "allCacheNodes", "allCacheNodes", "cacheGrpAffNodes", "nodeMap", "minNodeVer" };
        for (String prop : props) assertSame(U.field(discoCache1, prop), U.field(discoCache2, prop));
        assertNotSame(U.field(discoCache1, "alives"), U.field(discoCache2, "alives"));
        GridConcurrentHashSet alives1 = U.field(discoCache1, "alives");
        GridConcurrentHashSet alives2 = U.field(discoCache2, "alives");
        assertEquals("Discovery caches are not equal", alives1, alives2);
    }
}
Also used : GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite)

Example 10 with DiscoCache

use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.

the class GridCachePartitionExchangeManager method onKernalStart0.

/** {@inheritDoc} */
@Override
protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException {
    super.onKernalStart0(reconnect);
    ClusterNode loc = cctx.localNode();
    long startTime = loc.metrics().getStartTime();
    assert startTime > 0;
    // Generate dummy discovery event for local node joining.
    T2<DiscoveryEvent, DiscoCache> locJoin = cctx.discovery().localJoin();
    DiscoveryEvent discoEvt = locJoin.get1();
    DiscoCache discoCache = locJoin.get2();
    GridDhtPartitionExchangeId exchId = initialExchangeId();
    GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, discoCache, null, null);
    if (reconnect)
        reconnectExchangeFut = new GridFutureAdapter<>();
    exchWorker.addFirstExchangeFuture(fut);
    if (!cctx.kernalContext().clientNode()) {
        for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) {
            final int idx = cnt;
            cctx.io().addOrderedHandler(rebalanceTopic(cnt), new CI2<UUID, GridCacheMessage>() {

                @Override
                public void apply(final UUID id, final GridCacheMessage m) {
                    if (!enterBusy())
                        return;
                    try {
                        GridCacheContext cacheCtx = cctx.cacheContext(m.cacheId);
                        if (cacheCtx != null) {
                            if (m instanceof GridDhtPartitionSupplyMessage)
                                cacheCtx.preloader().handleSupplyMessage(idx, id, (GridDhtPartitionSupplyMessage) m);
                            else if (m instanceof GridDhtPartitionDemandMessage)
                                cacheCtx.preloader().handleDemandMessage(idx, id, (GridDhtPartitionDemandMessage) m);
                            else
                                U.error(log, "Unsupported message type: " + m.getClass().getName());
                        }
                    } finally {
                        leaveBusy();
                    }
                }
            });
        }
    }
    new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
    if (reconnect) {
        fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                try {
                    fut.get();
                    for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(null);
                    reconnectExchangeFut.onDone();
                } catch (IgniteCheckedException e) {
                    for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(e);
                    reconnectExchangeFut.onDone(e);
                }
            }
        });
    } else {
        if (log.isDebugEnabled())
            log.debug("Beginning to wait on local exchange future: " + fut);
        boolean first = true;
        while (true) {
            try {
                fut.get(cctx.preloadExchangeTimeout());
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (first) {
                    U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + "  ^-- Transactions in deadlock." + U.nl() + "  ^-- Long running transactions (ignore if this is the case)." + U.nl() + "  ^-- Unreleased explicit locks.");
                    first = false;
                } else
                    U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
            } catch (IgniteNeedReconnectException e) {
                throw e;
            } catch (Exception e) {
                if (fut.reconnectOnError(e))
                    throw new IgniteNeedReconnectException(cctx.localNode(), e);
                throw e;
            }
        }
        AffinityTopologyVersion nodeStartVer = new AffinityTopologyVersion(discoEvt.topologyVersion(), 0);
        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
            if (nodeStartVer.equals(cacheCtx.startTopologyVersion()))
                cacheCtx.preloader().onInitialExchangeComplete(null);
        }
        if (log.isDebugEnabled())
            log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
    }
}
Also used : DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) UUID(java.util.UUID) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)

Aggregations

DiscoCache (org.apache.ignite.internal.managers.discovery.DiscoCache)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)12 UUID (java.util.UUID)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 HashMap (java.util.HashMap)9 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 ArrayList (java.util.ArrayList)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 Map (java.util.Map)7 IgniteException (org.apache.ignite.IgniteException)7 Collection (java.util.Collection)6 Collections (java.util.Collections)6 List (java.util.List)6 Set (java.util.Set)6 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)6 F (org.apache.ignite.internal.util.typedef.F)6 CU (org.apache.ignite.internal.util.typedef.internal.CU)6 U (org.apache.ignite.internal.util.typedef.internal.U)6