use of org.apache.ignite.internal.processors.hadoop.HadoopTaskContext in project ignite by apache.
the class HadoopConcurrentHashMultimapSelftest method testMultiThreaded.
/**
* @throws Exception if failed.
*/
public void testMultiThreaded() throws Exception {
GridUnsafeMemory mem = new GridUnsafeMemory(0);
X.println("___ Started");
Random rnd = new GridRandom();
for (int i = 0; i < 20; i++) {
HadoopJobInfo job = new JobInfo();
final HadoopTaskContext taskCtx = new TaskContext();
final HadoopConcurrentHashMultimap m = new HadoopConcurrentHashMultimap(job, mem, 16);
final ConcurrentMap<Integer, Collection<Integer>> mm = new ConcurrentHashMap<>();
X.println("___ MT");
multithreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
X.println("___ TH in");
Random rnd = new GridRandom();
IntWritable key = new IntWritable();
IntWritable val = new IntWritable();
HadoopMultimap.Adder a = m.startAdding(taskCtx);
for (int i = 0; i < 50000; i++) {
int k = rnd.nextInt(32000);
int v = rnd.nextInt();
key.set(k);
val.set(v);
a.write(key, val);
Collection<Integer> list = mm.get(k);
if (list == null) {
list = new ConcurrentLinkedQueue<>();
Collection<Integer> old = mm.putIfAbsent(k, list);
if (old != null)
list = old;
}
list.add(v);
}
a.close();
X.println("___ TH out");
return null;
}
}, 3 + rnd.nextInt(27));
X.println("___ Check: " + m.capacity());
assertEquals(mm.size(), m.keys());
assertTrue(m.capacity() > 32000);
HadoopTaskInput in = m.input(taskCtx);
while (in.next()) {
IntWritable key = (IntWritable) in.key();
Iterator<?> valsIter = in.values();
Collection<Integer> vals = mm.remove(key.get());
assertNotNull(vals);
while (valsIter.hasNext()) {
IntWritable val = (IntWritable) valsIter.next();
assertTrue(vals.remove(val.get()));
}
assertTrue(vals.isEmpty());
}
in.close();
m.close();
assertEquals(0, mem.allocatedSize());
}
}
use of org.apache.ignite.internal.processors.hadoop.HadoopTaskContext in project ignite by apache.
the class HadoopConcurrentHashMultimapSelftest method testMapSimple.
/** */
public void testMapSimple() throws Exception {
GridUnsafeMemory mem = new GridUnsafeMemory(0);
// mem.listen(new GridOffHeapEventListener() {
// @Override public void onEvent(GridOffHeapEvent evt) {
// if (evt == GridOffHeapEvent.ALLOCATE)
// U.dumpStack();
// }
// });
Random rnd = new Random();
int mapSize = 16 << rnd.nextInt(3);
HadoopJobInfo job = new JobInfo();
HadoopTaskContext taskCtx = new TaskContext();
HadoopConcurrentHashMultimap m = new HadoopConcurrentHashMultimap(job, mem, mapSize);
HadoopConcurrentHashMultimap.Adder a = m.startAdding(taskCtx);
Multimap<Integer, Integer> mm = ArrayListMultimap.create();
Multimap<Integer, Integer> vis = ArrayListMultimap.create();
for (int i = 0, vals = 4 * mapSize + rnd.nextInt(25); i < vals; i++) {
int key = rnd.nextInt(mapSize);
int val = rnd.nextInt();
a.write(new IntWritable(key), new IntWritable(val));
mm.put(key, val);
X.println("k: " + key + " v: " + val);
a.close();
check(m, mm, vis, taskCtx);
a = m.startAdding(taskCtx);
}
// a.add(new IntWritable(10), new IntWritable(2));
// mm.put(10, 2);
// check(m, mm);
a.close();
X.println("Alloc: " + mem.allocatedSize());
m.close();
assertEquals(0, mem.allocatedSize());
}
use of org.apache.ignite.internal.processors.hadoop.HadoopTaskContext in project ignite by apache.
the class HadoopSkipListSelfTest method testMapSimple.
/**
* @throws Exception On error.
*/
public void testMapSimple() throws Exception {
GridUnsafeMemory mem = new GridUnsafeMemory(0);
// mem.listen(new GridOffHeapEventListener() {
// @Override public void onEvent(GridOffHeapEvent evt) {
// if (evt == GridOffHeapEvent.ALLOCATE)
// U.dumpStack();
// }
// });
Random rnd = new Random();
int mapSize = 16 << rnd.nextInt(6);
HadoopJobInfo job = new JobInfo();
HadoopTaskContext taskCtx = new TaskContext();
HadoopMultimap m = new HadoopSkipList(job, mem);
HadoopMultimap.Adder a = m.startAdding(taskCtx);
Multimap<Integer, Integer> mm = ArrayListMultimap.create();
Multimap<Integer, Integer> vis = ArrayListMultimap.create();
for (int i = 0, vals = 4 * mapSize + rnd.nextInt(25); i < vals; i++) {
int key = rnd.nextInt(mapSize);
int val = rnd.nextInt();
a.write(new IntWritable(key), new IntWritable(val));
mm.put(key, val);
X.println("k: " + key + " v: " + val);
a.close();
check(m, mm, vis, taskCtx);
a = m.startAdding(taskCtx);
}
// a.add(new IntWritable(10), new IntWritable(2));
// mm.put(10, 2);
// check(m, mm);
a.close();
X.println("Alloc: " + mem.allocatedSize());
m.close();
assertEquals(0, mem.allocatedSize());
}
use of org.apache.ignite.internal.processors.hadoop.HadoopTaskContext in project ignite by apache.
the class HadoopV2JobSelfTest method testCustomSerializationApplying.
/**
* Tests that {@link HadoopJobEx} provides wrapped serializer if it's set in configuration.
*
* @throws IgniteCheckedException If fails.
*/
public void testCustomSerializationApplying() throws IgniteCheckedException {
JobConf cfg = new JobConf();
cfg.setMapOutputKeyClass(IntWritable.class);
cfg.setMapOutputValueClass(Text.class);
cfg.set(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY, CustomSerialization.class.getName());
HadoopDefaultJobInfo info = createJobInfo(cfg);
final UUID uuid = UUID.randomUUID();
HadoopJobId id = new HadoopJobId(uuid, 1);
HadoopJobEx job = info.createJob(HadoopV2Job.class, id, log, null, new HadoopHelperImpl());
HadoopTaskContext taskCtx = job.getTaskContext(new HadoopTaskInfo(HadoopTaskType.MAP, null, 0, 0, null));
HadoopSerialization ser = taskCtx.keySerialization();
assertEquals(HadoopSerializationWrapper.class.getName(), ser.getClass().getName());
DataInput in = new DataInputStream(new ByteArrayInputStream(new byte[0]));
assertEquals(TEST_SERIALIZED_VALUE, ser.read(in, null).toString());
ser = taskCtx.valueSerialization();
assertEquals(HadoopSerializationWrapper.class.getName(), ser.getClass().getName());
assertEquals(TEST_SERIALIZED_VALUE, ser.read(in, null).toString());
}
use of org.apache.ignite.internal.processors.hadoop.HadoopTaskContext in project ignite by apache.
the class HadoopShuffleJob method onShuffleMessage.
/**
* @param src Source.
* @param msg Message.
* @throws IgniteCheckedException Exception.
*/
public void onShuffleMessage(T src, HadoopShuffleMessage msg) throws IgniteCheckedException {
assert msg.buffer() != null;
assert msg.offset() > 0;
HadoopTaskContext taskCtx = locReducersCtx.get(msg.reducer()).get();
HadoopPerformanceCounter perfCntr = HadoopPerformanceCounter.getCounter(taskCtx.counters(), null);
perfCntr.onShuffleMessage(msg.reducer(), U.currentTimeMillis());
HadoopMultimap map = getOrCreateMap(locMaps, msg.reducer());
// Add data from message to the map.
try (HadoopMultimap.Adder adder = map.startAdding(taskCtx)) {
final GridUnsafeDataInput dataInput = new GridUnsafeDataInput();
final UnsafeValue val = new UnsafeValue(msg.buffer());
msg.visit(new HadoopShuffleMessage.Visitor() {
/** */
private HadoopMultimap.Key key;
@Override
public void onKey(byte[] buf, int off, int len) throws IgniteCheckedException {
dataInput.bytes(buf, off, off + len);
key = adder.addKey(dataInput, key);
}
@Override
public void onValue(byte[] buf, int off, int len) {
val.off = off;
val.size = len;
key.add(val);
}
});
}
if (embedded) {
// No immediate response.
if (localShuffleState(src).onShuffleMessage())
sendFinishResponse(src, msg.jobId());
} else
// Response for every message.
io.apply(src, new HadoopShuffleAck(msg.id(), msg.jobId()));
}
Aggregations