use of org.apache.ignite.lang.IgniteUuid 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.IgniteUuid 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;
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridCacheSetFailoverAbstractSelfTest method testNodeRestart.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("WhileLoopReplaceableByForEach")
public void testNodeRestart() throws Exception {
IgniteSet<Integer> set = grid(0).set(SET_NAME, config(false));
final int ITEMS = 10_000;
Collection<Integer> items = new ArrayList<>(ITEMS);
for (int i = 0; i < ITEMS; i++) items.add(i);
set.addAll(items);
assertEquals(ITEMS, set.size());
AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> killFut = startNodeKiller(stop);
long stopTime = System.currentTimeMillis() + TEST_DURATION;
try {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (System.currentTimeMillis() < stopTime) {
for (int i = 0; i < 10; i++) {
try {
int size = set.size();
// TODO: IGNITE-584, check for equality when IGNITE-584 fixed.
assertTrue(size > 0);
} catch (IgniteException ignore) {
// No-op.
}
try {
Iterator<Integer> iter = set.iterator();
int cnt = 0;
while (iter.hasNext()) {
assertNotNull(iter.next());
cnt++;
}
// TODO: IGNITE-584, check for equality when IGNITE-584 fixed.
assertTrue(cnt > 0);
} catch (IgniteException ignore) {
// No-op.
}
int val = rnd.nextInt(ITEMS);
assertTrue("Not contains: " + val, set.contains(val));
val = ITEMS + rnd.nextInt(ITEMS);
assertFalse("Contains: " + val, set.contains(val));
}
log.info("Remove set.");
set.close();
log.info("Create new set.");
set = grid(0).set(SET_NAME, config(false));
set.addAll(items);
}
} finally {
stop.set(true);
}
killFut.get();
set.close();
if (false) {
// TODO IGNITE-600: enable check when fixed.
int cnt = 0;
Set<IgniteUuid> setIds = new HashSet<>();
for (int i = 0; i < gridCount(); i++) {
Iterator<GridCacheMapEntry> entries = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME).map().entries().iterator();
while (entries.hasNext()) {
GridCacheEntryEx entry = entries.next();
if (entry.hasValue()) {
cnt++;
if (entry.key() instanceof SetItemKey) {
SetItemKey setItem = (SetItemKey) entry.key();
if (setIds.add(setItem.setId()))
log.info("Unexpected set item [setId=" + setItem.setId() + ", grid: " + grid(i).name() + ", entry=" + entry + ']');
}
}
}
}
assertEquals("Found unexpected cache entries", 0, cnt);
}
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class IgfsSizeSelfTest method write.
/**
* Perform write of the files.
*
* @return Collection of written file descriptors.
* @throws Exception If failed.
*/
private Collection<IgfsFile> write() throws Exception {
Collection<IgfsFile> res = new HashSet<>(FILES_CNT, 1.0f);
ThreadLocalRandom8 rand = ThreadLocalRandom8.current();
for (int i = 0; i < FILES_CNT; i++) {
// Create empty file locally.
IgfsPath path = new IgfsPath("/file-" + i);
igfs(0).create(path, false).close();
IgfsMetaManager meta = igfs(0).context().meta();
IgniteUuid fileId = meta.fileId(path);
// Calculate file blocks.
int fileSize = rand.nextInt(MAX_FILE_SIZE);
int fullBlocks = fileSize / BLOCK_SIZE;
int remainderSize = fileSize % BLOCK_SIZE;
Collection<IgfsBlock> blocks = new ArrayList<>(fullBlocks + remainderSize > 0 ? 1 : 0);
for (int j = 0; j < fullBlocks; j++) blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, j), BLOCK_SIZE));
if (remainderSize > 0)
blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, fullBlocks), remainderSize));
IgfsFile file = new IgfsFile(path, fileSize, blocks);
// Actual write.
for (IgfsBlock block : blocks) {
IgfsOutputStream os = igfs(0).append(path, false);
os.write(chunk(block.length()));
os.close();
}
// Add written file to the result set.
res.add(file);
}
return res;
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class IgfsProcessorSelfTest method testDeleteCacheConsistency.
/** @throws Exception If failed. */
@SuppressWarnings("BusyWait")
public void testDeleteCacheConsistency() throws Exception {
IgfsPath path = new IgfsPath("/someFile");
String metaCacheName = grid(0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName();
String dataCacheName = grid(0).igfsx("igfs").configuration().getDataCacheConfiguration().getName();
try (IgfsOutputStream out = igfs.create(path, true)) {
out.write(new byte[10 * 1024 * 1024]);
}
IgniteUuid fileId = U.field(igfs.info(path), "fileId");
GridCacheAdapter<IgniteUuid, IgfsEntryInfo> metaCache = ((IgniteKernal) grid(0)).internalCache(metaCacheName);
GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = ((IgniteKernal) grid(0)).internalCache(dataCacheName);
IgfsEntryInfo info = metaCache.get(fileId);
assertNotNull(info);
assertTrue(info.isFile());
assertNotNull(metaCache.get(info.id()));
IgfsDataManager dataMgr = ((IgfsEx) igfs).context().data();
for (int i = 0; i < info.blocksCount(); i++) assertNotNull(dataCache.get(dataMgr.blockKey(i, info)));
igfs.delete(path, true);
for (int i = 0; i < 25; i++) {
if (metaCache.get(info.id()) == null)
break;
U.sleep(100);
}
assertNull(metaCache.get(info.id()));
for (int i = 0; i < 10; i++) {
boolean doBreak = true;
for (int j = 0; j < info.blocksCount(); j++) {
if (dataCache.get(dataMgr.blockKey(i, info)) != null) {
doBreak = false;
break;
}
}
if (doBreak)
break;
else
Thread.sleep(100);
}
for (int i = 0; i < info.blocksCount(); i++) assertNull(dataCache.get(new IgfsBlockKey(info.id(), null, false, i)));
}
Aggregations