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));
}
}
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);
}
}
}
}
}
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;
}
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);
}
}
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 > 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());
}
Aggregations