use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.
the class CacheAffinitySharedManager method initCoordinatorCaches.
/**
* @param fut Exchange future.
* @param newAff {@code True} if there are no older nodes with affinity info available.
* @throws IgniteCheckedException If failed.
* @return Future completed when caches initialization is done.
*/
public IgniteInternalFuture<?> initCoordinatorCaches(final GridDhtPartitionsExchangeFuture fut, final boolean newAff) throws IgniteCheckedException {
final List<IgniteInternalFuture<AffinityTopologyVersion>> futs = new ArrayList<>();
final AffinityTopologyVersion topVer = fut.initialVersion();
forAllRegisteredCacheGroups(new IgniteInClosureX<CacheGroupDescriptor>() {
@Override
public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException {
CacheGroupHolder grpHolder = grpHolders.get(desc.groupId());
if (grpHolder != null)
return;
// Need initialize holders and affinity if this node became coordinator during this exchange.
int grpId = desc.groupId();
CacheGroupContext grp = cctx.cache().cacheGroup(grpId);
if (grp == null) {
cctx.io().addCacheGroupHandler(desc.groupId(), GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure<UUID, GridDhtAffinityAssignmentResponse>() {
@Override
public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) {
processAffinityAssignmentResponse(nodeId, res);
}
});
grpHolder = CacheGroupHolder2.create(cctx, desc, topVer, null);
final GridAffinityAssignmentCache aff = grpHolder.affinity();
if (newAff) {
if (!aff.lastVersion().equals(topVer))
calculateAndInit(fut.events(), aff, topVer);
grpHolder.topology(fut.context().events().discoveryCache()).beforeExchange(fut, true, false);
} else {
List<GridDhtPartitionsExchangeFuture> exchFuts = cctx.exchange().exchangeFutures();
int idx = exchFuts.indexOf(fut);
assert idx >= 0 && idx < exchFuts.size() - 1 : "Invalid exchange futures state [cur=" + idx + ", total=" + exchFuts.size() + ']';
final GridDhtPartitionsExchangeFuture prev = exchFuts.get(idx + 1);
assert prev.isDone() && prev.topologyVersion().compareTo(topVer) < 0 : prev;
if (log.isDebugEnabled()) {
log.debug("Need initialize affinity on coordinator [" + "cacheGrp=" + desc.cacheOrGroupName() + "prevAff=" + prev.topologyVersion() + ']');
}
GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, desc.groupId(), prev.topologyVersion(), prev.events().discoveryCache());
fetchFut.init(false);
final GridFutureAdapter<AffinityTopologyVersion> affFut = new GridFutureAdapter<>();
fetchFut.listen(new IgniteInClosureX<IgniteInternalFuture<GridDhtAffinityAssignmentResponse>>() {
@Override
public void applyx(IgniteInternalFuture<GridDhtAffinityAssignmentResponse> fetchFut) throws IgniteCheckedException {
fetchAffinity(prev.topologyVersion(), prev.events().lastEvent(), prev.events().discoveryCache(), aff, (GridDhtAssignmentFetchFuture) fetchFut);
aff.calculate(topVer, fut.events().lastEvent(), fut.events().discoveryCache());
affFut.onDone(topVer);
}
});
futs.add(affFut);
}
} else {
grpHolder = new CacheGroupHolder1(grp, null);
if (newAff) {
GridAffinityAssignmentCache aff = grpHolder.affinity();
if (!aff.lastVersion().equals(topVer))
calculateAndInit(fut.events(), aff, topVer);
grpHolder.topology(fut.context().events().discoveryCache()).beforeExchange(fut, true, false);
}
}
CacheGroupHolder old = grpHolders.put(grpHolder.groupId(), grpHolder);
assert old == null : old;
}
});
if (!futs.isEmpty()) {
GridCompoundFuture<AffinityTopologyVersion, ?> affFut = new GridCompoundFuture<>();
for (IgniteInternalFuture<AffinityTopologyVersion> f : futs) affFut.add(f);
affFut.markInitialized();
return affFut;
}
return null;
}
use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.
the class GridCacheIoManager method addHandler.
/**
* @param hndId Message handler ID.
* @param type Type of message.
* @param c Handler.
* @param msgHandlers Message handlers.
*/
@SuppressWarnings({ "unchecked" })
private void addHandler(int hndId, Class<? extends GridCacheMessage> type, IgniteBiInClosure<UUID, ? extends GridCacheMessage> c, MessageHandlers msgHandlers) {
int msgIdx = messageIndex(type);
if (msgIdx != -1) {
Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = msgHandlers.idxClsHandlers;
IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(hndId);
if (cacheClsHandlers == null) {
cacheClsHandlers = new IgniteBiInClosure[GridCacheMessage.MAX_CACHE_MSG_LOOKUP_INDEX];
idxClsHandlers0.put(hndId, cacheClsHandlers);
}
if (cacheClsHandlers[msgIdx] != null)
throw new IgniteException("Duplicate cache message ID found [hndId=" + hndId + ", type=" + type + ']');
cacheClsHandlers[msgIdx] = c;
msgHandlers.idxClsHandlers = idxClsHandlers0;
return;
} else {
ListenerKey key = new ListenerKey(hndId, type);
if (msgHandlers.clsHandlers.putIfAbsent(key, (IgniteBiInClosure<UUID, GridCacheMessage>) c) != null)
assert false : "Handler for class already registered [hndId=" + hndId + ", cls=" + type + ", old=" + msgHandlers.clsHandlers.get(key) + ", new=" + c + ']';
}
IgniteLogger log0 = log;
if (log0 != null && log0.isTraceEnabled())
log0.trace("Registered cache communication handler [hndId=" + hndId + ", type=" + type + ", msgIdx=" + msgIdx + ", handler=" + c + ']');
}
use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.
the class IgniteWalReaderTest method testTxFillWalAndExtractDataRecords.
/**
* Places records under transaction, checks its value using WAL.
*
* @throws Exception if failed.
*/
public void testTxFillWalAndExtractDataRecords() throws Exception {
final int cntEntries = 1000;
final int txCnt = 100;
final Ignite ignite0 = startGrid("node0");
ignite0.active(true);
final IgniteCache<Object, Object> entries = txPutDummyRecords(ignite0, cntEntries, txCnt);
final Map<Object, Object> ctrlMap = new HashMap<>();
for (Cache.Entry<Object, Object> next : entries) ctrlMap.put(next.getKey(), next.getValue());
final String subfolderName = genDbSubfolderName(ignite0, 0);
stopGrid("node0");
final String workDir = U.defaultWorkDirectory();
final File binaryMeta = U.resolveWorkDirectory(workDir, "binary_meta", false);
final File binaryMetaWithConsId = new File(binaryMeta, subfolderName);
final File marshallerMapping = U.resolveWorkDirectory(workDir, "marshaller", false);
final IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log, PAGE_SIZE, binaryMetaWithConsId, marshallerMapping);
final IgniteBiInClosure<Object, Object> objConsumer = new IgniteBiInClosure<Object, Object>() {
@Override
public void apply(Object key, Object val) {
boolean rmv = remove(ctrlMap, key, val);
if (!rmv)
log.error("Unable to remove Key and value from control Map K:[" + key + "] V: [" + val + "]");
if (val instanceof IndexedObject) {
IndexedObject indexedObj = (IndexedObject) val;
assertEquals(indexedObj.iVal, indexedObj.jVal);
assertEquals(indexedObj.iVal, key);
for (byte datum : indexedObj.getData()) assertTrue(datum >= 'A' && datum <= 'A' + 10);
}
}
};
scanIterateAndCount(factory, workDir, subfolderName, cntEntries, txCnt, objConsumer, null);
assertTrue(" Control Map is not empty after reading entries " + ctrlMap, ctrlMap.isEmpty());
}
use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.
the class IgfsLocalSecondaryFileSystemDualAbstractSelfTest method testUsedSpaceSize.
/**
* @throws Exception If failed.
*/
public void testUsedSpaceSize() throws Exception {
final int DIRS_COUNT = 5;
final int DIRS_MAX_DEEP = 3;
final int FILES_COUNT = 10;
final AtomicLong totalSize = new AtomicLong();
IgniteBiInClosure<Integer, IgfsPath> createHierarchy = new IgniteBiInClosure<Integer, IgfsPath>() {
@Override
public void apply(Integer level, IgfsPath levelDir) {
try {
for (int i = 0; i < FILES_COUNT; ++i) {
IgfsPath filePath = new IgfsPath(levelDir, "file" + Integer.toString(i));
createFile(igfs, filePath, true, chunk);
totalSize.getAndAdd(chunk.length);
}
if (level < DIRS_MAX_DEEP) {
for (int dir = 0; dir < DIRS_COUNT; dir++) {
IgfsPath dirPath = new IgfsPath(levelDir, "dir" + Integer.toString(dir));
igfs.mkdirs(dirPath);
apply(level + 1, dirPath);
}
}
} catch (Exception e) {
fail(e.getMessage());
}
}
};
createHierarchy.apply(1, new IgfsPath("/dir"));
assertEquals(totalSize.get(), igfs.metrics().secondarySpaceSize());
}
use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.
the class IgfsLocalSecondaryFileSystemProxySelfTest method testUsedSpaceSize.
/**
* @throws Exception If failed.
*/
public void testUsedSpaceSize() throws Exception {
final int DIRS_COUNT = 5;
final int DIRS_MAX_DEEP = 3;
final int FILES_COUNT = 10;
final AtomicLong totalSize = new AtomicLong();
IgniteBiInClosure<Integer, IgfsPath> createHierarchy = new IgniteBiInClosure<Integer, IgfsPath>() {
@Override
public void apply(Integer level, IgfsPath levelDir) {
try {
for (int i = 0; i < FILES_COUNT; ++i) {
IgfsPath filePath = new IgfsPath(levelDir, "file" + Integer.toString(i));
createFile(igfs, filePath, true, chunk);
totalSize.getAndAdd(chunk.length);
}
if (level < DIRS_MAX_DEEP) {
for (int dir = 0; dir < DIRS_COUNT; dir++) {
IgfsPath dirPath = new IgfsPath(levelDir, "dir" + Integer.toString(dir));
igfs.mkdirs(dirPath);
apply(level + 1, dirPath);
}
}
} catch (Exception e) {
fail(e.getMessage());
}
}
};
createHierarchy.apply(1, new IgfsPath("/dir"));
assertEquals(totalSize.get(), igfs.metrics().secondarySpaceSize());
}
Aggregations