Search in sources :

Example 6 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class GridCacheDatabaseSharedManager method readCheckpointAndRestoreMemory.

/**
 * {@inheritDoc}
 */
@Override
public void readCheckpointAndRestoreMemory(List<DynamicCacheDescriptor> cachesToStart) throws IgniteCheckedException {
    assert !cctx.localNode().isClient();
    checkpointReadLock();
    try {
        if (!F.isEmpty(cachesToStart)) {
            for (DynamicCacheDescriptor desc : cachesToStart) {
                if (CU.affinityNode(cctx.localNode(), desc.cacheConfiguration().getNodeFilter()))
                    storeMgr.initializeForCache(desc.groupDescriptor(), new StoredCacheData(desc.cacheConfiguration()));
            }
        }
        CheckpointStatus status = readCheckpointStatus();
        cctx.pageStore().initializeForMetastorage();
        metaStorage = new MetaStorage(cctx, dataRegionMap.get(METASTORE_DATA_REGION_NAME), (DataRegionMetricsImpl) memMetricsMap.get(METASTORE_DATA_REGION_NAME));
        WALPointer restore = restoreMemory(status);
        // First, bring memory to the last consistent checkpoint state if needed.
        // This method should return a pointer to the last valid record in the WAL.
        cctx.wal().resumeLogging(restore);
        WALPointer ptr = cctx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));
        if (ptr != null) {
            cctx.wal().fsync(ptr);
            nodeStart(ptr);
        }
        metaStorage.init(this);
        notifyMetastorageReadyForReadWrite();
    } catch (StorageException e) {
        throw new IgniteCheckedException(e);
    } finally {
        checkpointReadUnlock();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException)

Example 7 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class FilePageStoreManager method readCacheConfigurations.

/**
 * @param dir Cache (group) directory.
 * @param ccfgs Cache configurations.
 * @throws IgniteCheckedException If failed.
 */
public void readCacheConfigurations(File dir, Map<String, StoredCacheData> ccfgs) throws IgniteCheckedException {
    if (dir.getName().startsWith(CACHE_DIR_PREFIX)) {
        File conf = new File(dir, CACHE_DATA_FILENAME);
        if (conf.exists() && conf.length() > 0) {
            StoredCacheData cacheData = readCacheData(conf);
            String cacheName = cacheData.config().getName();
            if (!ccfgs.containsKey(cacheName))
                ccfgs.put(cacheName, cacheData);
            else {
                U.warn(log, "Cache with name=" + cacheName + " is already registered, skipping config file " + dir.getName());
            }
        }
    } else if (dir.getName().startsWith(CACHE_GRP_DIR_PREFIX))
        readCacheGroupCaches(dir, ccfgs);
}
Also used : File(java.io.File) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData)

Example 8 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class FilePageStoreManager method readCacheConfigurations.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, StoredCacheData> readCacheConfigurations() throws IgniteCheckedException {
    if (cctx.kernalContext().clientNode())
        return Collections.emptyMap();
    File[] files = storeWorkDir.listFiles();
    if (files == null)
        return Collections.emptyMap();
    Map<String, StoredCacheData> ccfgs = new HashMap<>();
    Arrays.sort(files);
    for (File file : files) {
        if (file.isDirectory())
            readCacheConfigurations(file, ccfgs);
    }
    return ccfgs;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData)

Example 9 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class SnapshotRestoreProcess method finishPrepare.

/**
 * @param reqId Request ID.
 * @param res Results.
 * @param errs Errors.
 */
private void finishPrepare(UUID reqId, Map<UUID, SnapshotRestoreOperationResponse> res, Map<UUID, Exception> errs) {
    if (ctx.clientNode())
        return;
    SnapshotRestoreContext opCtx0 = opCtx;
    Exception failure = F.first(errs.values());
    assert opCtx0 != null || failure != null : "Context has not been created on the node " + ctx.localNodeId();
    if (opCtx0 == null || !reqId.equals(opCtx0.reqId)) {
        finishProcess(reqId, failure);
        return;
    }
    if (failure == null)
        failure = checkNodeLeft(opCtx0.nodes(), res.keySet());
    // Context has been created - should rollback changes cluster-wide.
    if (failure != null) {
        opCtx0.errHnd.accept(failure);
        return;
    }
    Map<Integer, StoredCacheData> globalCfgs = new HashMap<>();
    for (Map.Entry<UUID, SnapshotRestoreOperationResponse> e : res.entrySet()) {
        if (e.getValue().ccfgs != null) {
            for (StoredCacheData cacheData : e.getValue().ccfgs) {
                globalCfgs.put(CU.cacheId(cacheData.config().getName()), cacheData);
                opCtx0.dirs.add(((FilePageStoreManager) ctx.cache().context().pageStore()).cacheWorkDir(cacheData.config()));
            }
        }
        opCtx0.metasPerNode.put(e.getKey(), new ArrayList<>(e.getValue().metas));
    }
    opCtx0.cfgs = globalCfgs;
    if (U.isLocalNodeCoordinator(ctx.discovery()))
        preloadProc.start(reqId, reqId);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UUID(java.util.UUID) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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)

Example 10 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class SnapshotRestoreProcess method prepareContext.

/**
 * @param req Request to prepare cache group restore from the snapshot.
 * @param metas Local snapshot metadatas.
 * @return Snapshot restore operation context.
 * @throws IgniteCheckedException If failed.
 */
private SnapshotRestoreContext prepareContext(SnapshotOperationRequest req, Collection<SnapshotMetadata> metas) throws IgniteCheckedException {
    if (opCtx != null) {
        throw new IgniteCheckedException(OP_REJECT_MSG + "The previous snapshot restore operation was not completed.");
    }
    GridCacheSharedContext<?, ?> cctx = ctx.cache().context();
    // Collection of baseline nodes that must survive and additional discovery data required for the affinity calculation.
    DiscoCache discoCache = ctx.discovery().discoCache();
    if (!F.transform(discoCache.aliveBaselineNodes(), F.node2id()).containsAll(req.nodes()))
        throw new IgniteCheckedException("Restore context cannot be inited since the required baseline nodes missed: " + discoCache);
    DiscoCache discoCache0 = discoCache.copy(discoCache.version(), null);
    if (F.isEmpty(metas))
        return new SnapshotRestoreContext(req, discoCache0, Collections.emptyMap());
    if (F.first(metas).pageSize() != cctx.database().pageSize()) {
        throw new IgniteCheckedException("Incompatible memory page size " + "[snapshotPageSize=" + F.first(metas).pageSize() + ", local=" + cctx.database().pageSize() + ", snapshot=" + req.snapshotName() + ", nodeId=" + cctx.localNodeId() + ']');
    }
    Map<String, StoredCacheData> cfgsByName = new HashMap<>();
    FilePageStoreManager pageStore = (FilePageStoreManager) cctx.pageStore();
    // Metastorage can be restored only manually by directly copying files.
    for (SnapshotMetadata meta : metas) {
        for (File snpCacheDir : cctx.snapshotMgr().snapshotCacheDirectories(req.snapshotName(), meta.folderName(), name -> !METASTORAGE_CACHE_NAME.equals(name))) {
            String grpName = FilePageStoreManager.cacheGroupName(snpCacheDir);
            if (!F.isEmpty(req.groups()) && !req.groups().contains(grpName))
                continue;
            File cacheDir = pageStore.cacheWorkDir(snpCacheDir.getName().startsWith(CACHE_GRP_DIR_PREFIX), grpName);
            if (cacheDir.exists()) {
                if (!cacheDir.isDirectory()) {
                    throw new IgniteCheckedException("Unable to restore cache group, file with required directory " + "name already exists [group=" + grpName + ", file=" + cacheDir + ']');
                }
                if (cacheDir.list().length > 0) {
                    throw new IgniteCheckedException("Unable to restore cache group - directory is not empty. " + "Cache group should be destroyed manually before perform restore operation " + "[group=" + grpName + ", dir=" + cacheDir + ']');
                }
                if (!cacheDir.delete()) {
                    throw new IgniteCheckedException("Unable to remove empty cache directory " + "[group=" + grpName + ", dir=" + cacheDir + ']');
                }
            }
            File tmpCacheDir = formatTmpDirName(cacheDir);
            if (tmpCacheDir.exists()) {
                throw new IgniteCheckedException("Unable to restore cache group, temp directory already exists " + "[group=" + grpName + ", dir=" + tmpCacheDir + ']');
            }
            pageStore.readCacheConfigurations(snpCacheDir, cfgsByName);
        }
    }
    Map<Integer, StoredCacheData> cfgsById = cfgsByName.values().stream().collect(Collectors.toMap(v -> CU.cacheId(v.config().getName()), v -> v));
    return new SnapshotRestoreContext(req, discoCache0, cfgsById);
}
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) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) File(java.io.File)

Aggregations

StoredCacheData (org.apache.ignite.internal.processors.cache.StoredCacheData)14 File (java.io.File)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)5 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)4 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)4 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)4 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 DataOutputStream (java.io.DataOutputStream)2