use of org.apache.ignite.ml.environment.deploy.DeployingContext in project ignite by apache.
the class ComputeUtils method initContext.
/**
* Initializes partition {@code context} by loading it from a partition {@code upstream}.
* @param ignite Ignite instance.
* @param upstreamCacheName Name of an {@code upstream} cache.
* @param filter Filter for {@code upstream} data.
* @param transformerBuilder Upstream transformer builder.
* @param ctxBuilder Partition {@code context} builder.
* @param envBuilder Environment builder.
* @param isKeepBinary Support of binary objects.
* @param deployingCtx Deploy context.
* @param <K> Type of a key in {@code upstream} data.
* @param <V> Type of a value in {@code upstream} data.
* @param <C> Type of a partition {@code context}.
*/
public static <K, V, C extends Serializable> void initContext(Ignite ignite, String upstreamCacheName, UpstreamTransformerBuilder transformerBuilder, IgniteBiPredicate<K, V> filter, String datasetCacheName, PartitionContextBuilder<K, V, C> ctxBuilder, LearningEnvironmentBuilder envBuilder, int retries, int interval, boolean isKeepBinary, DeployingContext deployingCtx) {
affinityCallWithRetries(ignite, Arrays.asList(datasetCacheName, upstreamCacheName), part -> {
Ignite locIgnite = Ignition.localIgnite();
LearningEnvironment env = envBuilder.buildForWorker(part);
IgniteCache<K, V> locUpstreamCache = locIgnite.cache(upstreamCacheName);
if (isKeepBinary)
locUpstreamCache = locUpstreamCache.withKeepBinary();
ScanQuery<K, V> qry = new ScanQuery<>();
qry.setLocal(true);
qry.setPartition(part);
qry.setFilter(filter);
C ctx;
UpstreamTransformer transformer = transformerBuilder.build(env);
UpstreamTransformer transformerCp = Utils.copy(transformer);
long cnt = computeCount(locUpstreamCache, qry, transformer);
try (QueryCursor<UpstreamEntry<K, V>> cursor = locUpstreamCache.query(qry, e -> new UpstreamEntry<>(e.getKey(), e.getValue()))) {
Iterator<UpstreamEntry<K, V>> it = cursor.iterator();
Stream<UpstreamEntry> transformedStream = transformerCp.transform(Utils.asStream(it, cnt).map(x -> (UpstreamEntry) x));
it = Utils.asStream(transformedStream.iterator()).map(x -> (UpstreamEntry<K, V>) x).iterator();
Iterator<UpstreamEntry<K, V>> iter = new IteratorWithConcurrentModificationChecker<>(it, cnt, "Cache expected to be not modified during dataset data building [partition=" + part + ']');
ctx = ctxBuilder.build(env, iter, cnt);
}
IgniteCache<Integer, C> datasetCache = locIgnite.cache(datasetCacheName);
datasetCache.put(part, ctx);
return part;
}, retries, interval, deployingCtx);
}
Aggregations