Search in sources :

Example 11 with MappedName

use of org.apache.ignite.internal.processors.marshaller.MappedName in project ignite by apache.

the class MarshallerContextImpl method onMissedMappingResolved.

/**
 * @param item Item.
 * @param resolvedClsName Resolved class name.
 */
public void onMissedMappingResolved(final MarshallerMappingItem item, String resolvedClsName) {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(item.platformId());
    int typeId = item.typeId();
    MappedName mappedName = cache.get(typeId);
    if (mappedName != null)
        assert resolvedClsName.equals(mappedName.className()) : "Class name resolved from cluster: " + resolvedClsName + ", class name from local cache: " + mappedName.className();
    else {
        mappedName = new MappedName(resolvedClsName, true);
        cache.putIfAbsent(typeId, mappedName);
        closProc.runLocalSafe(new MappingStoreTask(fileStore, item.platformId(), item.typeId(), resolvedClsName));
    }
}
Also used : MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Example 12 with MappedName

use of org.apache.ignite.internal.processors.marshaller.MappedName in project ignite by apache.

the class MarshallerContextImpl method addPlatformMappings.

/**
 * @param mappings Map of marshaller mappings.
 * @param mappedCache Cache to attach new mappings to.
 * @param cacheAddPred Check mapping can be added.
 * @param writer Persistence mapping writer.
 */
private static void addPlatformMappings(IgniteLogger log, List<Map<Integer, MappedName>> mappings, Function<Byte, ConcurrentMap<Integer, MappedName>> mappedCache, BiPredicate<MappedName, String> cacheAddPred, MarshallerMappingFileStore writer) {
    if (mappings == null)
        return;
    for (byte platformId = 0; platformId < mappings.size(); platformId++) {
        Map<Integer, MappedName> attach = mappings.get(platformId);
        if (attach == null)
            continue;
        ConcurrentMap<Integer, MappedName> cached = mappedCache.apply(platformId);
        for (Map.Entry<Integer, MappedName> e : attach.entrySet()) {
            Integer typeId = e.getKey();
            String clsName = e.getValue().className();
            if (cacheAddPred.test(cached.get(typeId), clsName)) {
                try {
                    cached.put(typeId, new MappedName(clsName, true));
                    writer.mergeAndWriteMapping(platformId, typeId, clsName);
                } catch (IgniteCheckedException ex) {
                    U.error(log, "Failed to write marshaller mapping data", ex);
                }
            }
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) AbstractMap(java.util.AbstractMap)

Example 13 with MappedName

use of org.apache.ignite.internal.processors.marshaller.MappedName in project ignite by apache.

the class MarshallerContextImpl method getCachedMappings.

/**
 */
public ArrayList<Map<Integer, MappedName>> getCachedMappings() {
    int size = allCaches.size();
    ArrayList<Map<Integer, MappedName>> result = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        Map res;
        if (i == JAVA_ID)
            res = ((CombinedMap) allCaches.get(JAVA_ID)).userMap;
        else
            res = allCaches.get(i);
        if (res != null && !res.isEmpty())
            result.add(res);
        else
            result.add(Collections.<Integer, MappedName>emptyMap());
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) AbstractMap(java.util.AbstractMap)

Example 14 with MappedName

use of org.apache.ignite.internal.processors.marshaller.MappedName in project ignite by apache.

the class SnapshotFutureTask method onCheckpointBegin.

/**
 * {@inheritDoc}
 */
@Override
public void onCheckpointBegin(Context ctx) {
    if (stopping())
        return;
    assert !processed.isEmpty() : "Partitions to process must be collected under checkpoint mark phase";
    wrapExceptionIfStarted(() -> snpSndr.init(processed.values().stream().mapToInt(Set::size).sum())).run();
    // there is no error happen on task init.
    if (!startedFut.onDone())
        return;
    // Submit all tasks for partitions and deltas processing.
    List<CompletableFuture<Void>> futs = new ArrayList<>();
    if (log.isInfoEnabled()) {
        log.info("Submit partition processing tasks to the snapshot execution pool " + "[map=" + compactGroupPartitions(partFileLengths.keySet()) + ", totalSize=" + U.humanReadableByteCount(partFileLengths.values().stream().mapToLong(v -> v).sum()) + ']');
    }
    Collection<BinaryType> binTypesCopy = cctx.kernalContext().cacheObjects().metadata(Collections.emptyList()).values();
    // Process binary meta.
    futs.add(CompletableFuture.runAsync(wrapExceptionIfStarted(() -> snpSndr.sendBinaryMeta(binTypesCopy)), snpSndr.executor()));
    List<Map<Integer, MappedName>> mappingsCopy = cctx.kernalContext().marshallerContext().getCachedMappings();
    // Process marshaller meta.
    futs.add(CompletableFuture.runAsync(wrapExceptionIfStarted(() -> snpSndr.sendMarshallerMeta(mappingsCopy)), snpSndr.executor()));
    // Send configuration files of all cache groups.
    for (CacheConfigurationSender ccfgSndr : ccfgSndrs) futs.add(CompletableFuture.runAsync(wrapExceptionIfStarted(ccfgSndr::sendCacheConfig), snpSndr.executor()));
    try {
        for (Map.Entry<Integer, Set<Integer>> e : processed.entrySet()) {
            int grpId = e.getKey();
            String cacheDirName = pageStore.cacheDirName(grpId);
            // Process partitions for a particular cache group.
            for (int partId : e.getValue()) {
                GroupPartitionId pair = new GroupPartitionId(grpId, partId);
                Long partLen = partFileLengths.get(pair);
                CompletableFuture<Void> fut0 = CompletableFuture.runAsync(wrapExceptionIfStarted(() -> {
                    snpSndr.sendPart(getPartitionFile(pageStore.workDir(), cacheDirName, partId), cacheDirName, pair, partLen);
                    // Stop partition writer.
                    partDeltaWriters.get(pair).markPartitionProcessed();
                }), snpSndr.executor()).runAfterBothAsync(cpEndFut, wrapExceptionIfStarted(() -> {
                    File delta = partDeltaWriters.get(pair).deltaFile;
                    try {
                        // Atomically creates a new, empty delta file if and only if
                        // a file with this name does not yet exist.
                        delta.createNewFile();
                    } catch (IOException ex) {
                        throw new IgniteCheckedException(ex);
                    }
                    snpSndr.sendDelta(delta, cacheDirName, pair);
                    boolean deleted = delta.delete();
                    assert deleted;
                }), snpSndr.executor());
                futs.add(fut0);
            }
        }
        int futsSize = futs.size();
        CompletableFuture.allOf(futs.toArray(new CompletableFuture[futsSize])).whenComplete((res, t) -> {
            assert t == null : "Exception must never be thrown since a wrapper is used " + "for each snapshot task: " + t;
            closeAsync();
        });
    } catch (IgniteCheckedException e) {
        acceptException(e);
    }
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteSnapshotManager.copy(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.copy) ByteBuffer(java.nio.ByteBuffer) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) BooleanSupplier(java.util.function.BooleanSupplier) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) Map(java.util.Map) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) PageWriteListener(org.apache.ignite.internal.pagemem.store.PageWriteListener) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) Objects(java.util.Objects) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) FastCrc(org.apache.ignite.internal.processors.cache.persistence.wal.crc.FastCrc) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) CU(org.apache.ignite.internal.util.typedef.internal.CU) FilePageStoreManager.getPartitionFile(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFile) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IgniteThrowableRunner(org.apache.ignite.internal.util.lang.IgniteThrowableRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) S(org.apache.ignite.internal.util.typedef.internal.S) BiConsumer(java.util.function.BiConsumer) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) DistributedMetaStorageImpl(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl) F(org.apache.ignite.internal.util.typedef.F) GroupPartitionId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) FilePageStoreManager.cacheWorkDir(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheWorkDir) IOException(java.io.IOException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Lock(java.util.concurrent.locks.Lock) IgniteSnapshotManager.partDeltaFile(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.partDeltaFile) BinaryType(org.apache.ignite.binary.BinaryType) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Closeable(java.io.Closeable) Collections(java.util.Collections) Set(java.util.Set) HashSet(java.util.HashSet) BinaryType(org.apache.ignite.binary.BinaryType) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Map(java.util.Map) HashMap(java.util.HashMap) FilePageStoreManager.getPartitionFile(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFile) File(java.io.File) IgniteSnapshotManager.partDeltaFile(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.partDeltaFile) GroupPartitionId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId)

Example 15 with MappedName

use of org.apache.ignite.internal.processors.marshaller.MappedName in project ignite by apache.

the class MarshallerContextSelfTest method testMultiplatformMappingsCollecting.

/**
 * Test for adding non-java mappings (with platformId &gt; 0) to MarshallerContext and collecting them
 * for discovery.
 *
 * @throws Exception If failed.
 */
@Test
public void testMultiplatformMappingsCollecting() throws Exception {
    String nonJavaClassName = "random.platform.Mapping";
    MarshallerContextImpl marshCtx = new MarshallerContextImpl(null, null);
    marshCtx.onMarshallerProcessorStarted(ctx, null);
    MarshallerMappingItem item = new MarshallerMappingItem((byte) 2, 101, nonJavaClassName);
    marshCtx.onMappingProposed(item);
    marshCtx.onMappingAccepted(item);
    ArrayList<Map<Integer, MappedName>> allMappings = marshCtx.getCachedMappings();
    assertEquals(allMappings.size(), 3);
    assertTrue(allMappings.get(0).isEmpty());
    assertTrue(allMappings.get(1).isEmpty());
    Map<Integer, MappedName> nonJavaMappings = allMappings.get(2);
    assertNotNull(nonJavaMappings);
    assertNotNull(nonJavaMappings.get(101));
    assertEquals(nonJavaClassName, nonJavaMappings.get(101).className());
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

MappedName (org.apache.ignite.internal.processors.marshaller.MappedName)15 Map (java.util.Map)5 MarshallerMappingItem (org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem)5 HashMap (java.util.HashMap)4 AbstractMap (java.util.AbstractMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 GridDhtPartitionFullMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)3 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 MappingExchangeResult (org.apache.ignite.internal.processors.marshaller.MappingExchangeResult)2 BufferedReader (java.io.BufferedReader)1 Closeable (java.io.Closeable)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ByteBuffer (java.nio.ByteBuffer)1