use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridOffHeapPartitionedMapAbstractSelfTest method testPartitionIterator.
/**
* @throws Exception If failed.
*/
public void testPartitionIterator() throws Exception {
initCap = 10;
map = newMap();
final AtomicInteger rehashes = new AtomicInteger();
final AtomicInteger releases = new AtomicInteger();
map.eventListener(new GridOffHeapEventListener() {
@Override
public void onEvent(GridOffHeapEvent evt) {
switch(evt) {
case REHASH:
rehashes.incrementAndGet();
break;
case RELEASE:
releases.incrementAndGet();
break;
// No-op.
default:
}
}
});
int max = 1024;
for (int p = 0; p < parts; p++) {
Map<String, String> m = new HashMap<>(max);
for (int i = 0; i < max; i++) {
String key = string();
String val = string();
// info("Storing [i=" + i + ", key=" + key + ", val=" + val + ']');
assertTrue(map.put(p, hash(key), key.getBytes(), val.getBytes()));
assertTrue(map.contains(p, hash(key), key.getBytes()));
assertNotNull(map.get(p, hash(key), key.getBytes()));
assertEquals(new String(map.get(p, hash(key), key.getBytes())), val);
m.put(key, val);
int cnt = 0;
try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator(p)) {
while (it.hasNext()) {
IgniteBiTuple<byte[], byte[]> t = it.next();
String k = new String(t.get1());
String v = new String(t.get2());
// info("Entry [k=" + k + ", v=" + v + ']');
assertEquals(m.get(k), v);
cnt++;
}
}
assertEquals(map.size(), p * max + cnt);
}
}
assertEquals(max * parts, map.size());
info("Stats [size=" + map.size() + ", rehashes=" + rehashes + ", releases=" + releases + ']');
assertTrue(rehashes.get() > 0);
assertEquals(rehashes.get(), releases.get());
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridOffHeapPartitionedMapAbstractSelfTest method testPartitionIteratorMultithreaded.
/**
* @throws Exception If failed.
*/
public void testPartitionIteratorMultithreaded() throws Exception {
initCap = 10;
map = newMap();
final AtomicInteger rehashes = new AtomicInteger();
final AtomicInteger releases = new AtomicInteger();
map.eventListener(new GridOffHeapEventListener() {
@Override
public void onEvent(GridOffHeapEvent evt) {
switch(evt) {
case REHASH:
rehashes.incrementAndGet();
break;
case RELEASE:
releases.incrementAndGet();
break;
// No-op.
default:
}
}
});
final int max = 64;
int threads = 5;
final Map<String, String> m = new ConcurrentHashMap8<>(max);
multithreaded(new Callable() {
@Override
public Object call() throws Exception {
for (int p = 0; p < parts; p++) {
for (int i = 0; i < max; i++) {
String key = string();
String val = string();
// info("Storing [i=" + i + ", key=" + key + ", val=" + val + ']');
m.put(key, val);
assertTrue(map.put(p, hash(key), key.getBytes(), val.getBytes()));
assertTrue(map.contains(p, hash(key), key.getBytes()));
assertNotNull(map.get(p, hash(key), key.getBytes()));
assertEquals(new String(map.get(p, hash(key), key.getBytes())), val);
try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator(p)) {
while (it.hasNext()) {
IgniteBiTuple<byte[], byte[]> t = it.next();
String k = new String(t.get1());
String v = new String(t.get2());
// info("Entry [k=" + k + ", v=" + v + ']');
assertEquals(m.get(k), v);
}
}
}
}
return null;
}
}, threads);
assertEquals(max * threads * parts, map.size());
info("Stats [size=" + map.size() + ", rehashes=" + rehashes + ", releases=" + releases + ']');
assertTrue(rehashes.get() > 0);
assertEquals(rehashes.get(), releases.get());
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class HadoopJobTracker method logPlan.
/**
* Log map-reduce plan if needed.
*
* @param info Job info.
* @param plan Plan.
*/
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
private void logPlan(HadoopJobInfo info, HadoopMapReducePlan plan) {
if (log.isDebugEnabled()) {
Map<UUID, IgniteBiTuple<Collection<HadoopInputSplit>, int[]>> map = new HashMap<>();
for (UUID nodeId : plan.mapperNodeIds()) map.put(nodeId, new IgniteBiTuple<Collection<HadoopInputSplit>, int[]>(plan.mappers(nodeId), null));
for (UUID nodeId : plan.reducerNodeIds()) {
int[] reducers = plan.reducers(nodeId);
IgniteBiTuple<Collection<HadoopInputSplit>, int[]> entry = map.get(nodeId);
if (entry == null)
map.put(nodeId, new IgniteBiTuple<Collection<HadoopInputSplit>, int[]>(null, reducers));
else
entry.set2(reducers);
}
StringBuilder details = new StringBuilder("[");
boolean first = true;
for (Map.Entry<UUID, IgniteBiTuple<Collection<HadoopInputSplit>, int[]>> entry : map.entrySet()) {
if (first)
first = false;
else
details.append(", ");
UUID nodeId = entry.getKey();
Collection<HadoopInputSplit> mappers = entry.getValue().get1();
if (mappers == null)
mappers = Collections.emptyList();
int[] reducers = entry.getValue().get2();
if (reducers == null)
reducers = new int[0];
details.append("[nodeId=" + nodeId + ", mappers=" + mappers.size() + ", reducers=" + reducers.length + ", mapperDetails=" + mappers + ", reducerDetails=" + Arrays.toString(reducers) + ']');
}
details.append(']');
log.debug("Prepared map-reduce plan [jobName=" + info.jobName() + ", mappers=" + plan.mappers() + ", reducers=" + plan.reducers() + ", details=" + details + ']');
}
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class WeightedRandomLoadBalancingSpi method onContextInitialized0.
/** {@inheritDoc} */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof TaskEvent || evt instanceof JobEvent;
if (evt.type() == EVT_TASK_FINISHED || evt.type() == EVT_TASK_FAILED) {
IgniteUuid sesId = ((TaskEvent) evt).taskSessionId();
taskTops.remove(sesId);
if (log.isDebugEnabled())
log.debug("Removed task topology from topology cache for session: " + sesId);
} else // Here we set mapped property and later cache will be ignored
if (evt.type() == EVT_JOB_MAPPED) {
IgniteUuid sesId = ((JobEvent) evt).taskSessionId();
IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(sesId);
if (weightedTop != null)
weightedTop.set1(true);
if (log.isDebugEnabled())
log.debug("Job has been mapped. Ignore cache for session: " + sesId);
}
}
}, EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class SparseDistributedMatrixTest method buildKeySet.
/** Build key set for SparseDistributedMatrix. */
private Set<IgniteBiTuple<Integer, IgniteUuid>> buildKeySet(SparseDistributedMatrix m) {
Set<IgniteBiTuple<Integer, IgniteUuid>> set = new HashSet<>();
SparseDistributedMatrixStorage storage = (SparseDistributedMatrixStorage) m.getStorage();
IgniteUuid uuid = storage.getUUID();
int size = storage.storageMode() == StorageConstants.ROW_STORAGE_MODE ? storage.rowSize() : storage.columnSize();
for (int i = 0; i < size; i++) set.add(new IgniteBiTuple<>(i, uuid));
return set;
}
Aggregations