use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class IgniteIndexReader method getPageListsInfo.
/**
* Gets info about page lists.
*
* @param metaPageListId Page list meta id.
* @return Page list info.
*/
private PageListsInfo getPageListsInfo(long metaPageListId) {
Map<IgniteBiTuple<Long, Integer>, List<Long>> bucketsData = new HashMap<>();
Set<Long> allPages = new HashSet<>();
Map<Class, Long> pageListStat = new HashMap<>();
Map<Long, List<Throwable>> errors = new HashMap<>();
try {
doWithBuffer((buf, addr) -> {
long nextMetaId = metaPageListId;
while (nextMetaId != 0) {
try {
buf.rewind();
readPage(idxStore, nextMetaId, buf);
PagesListMetaIO io = PageIO.getPageIO(addr);
Map<Integer, GridLongList> data = new HashMap<>();
io.getBucketsData(addr, data);
final long fNextMetaId = nextMetaId;
data.forEach((k, v) -> {
List<Long> listIds = LongStream.of(v.array()).map(IgniteIndexReader::normalizePageId).boxed().collect(toList());
for (Long listId : listIds) {
try {
allPages.addAll(getPageList(listId, pageListStat));
} catch (Exception e) {
errors.put(listId, singletonList(e));
}
}
bucketsData.put(new IgniteBiTuple<>(fNextMetaId, k), listIds);
});
nextMetaId = io.getNextMetaPageId(addr);
} catch (Exception e) {
errors.put(nextMetaId, singletonList(e));
nextMetaId = 0;
}
}
return null;
});
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
return new PageListsInfo(bucketsData, allPages, pageListStat, errors);
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class RobinHoodBackwardShiftHashMap method removeIf.
/**
* {@inheritDoc}
*/
@Override
public GridLongList removeIf(int startIdxToClear, int endIdxToClear, KeyPredicate keyPred) {
assert endIdxToClear >= startIdxToClear : "Start and end indexes are not consistent: {" + startIdxToClear + ", " + endIdxToClear + "}";
int sz = endIdxToClear - startIdxToClear;
GridLongList list = new GridLongList(sz);
for (int idx = startIdxToClear; idx < endIdxToClear; idx++) {
long base = entryBase(idx);
int grpId = getGrpId(base);
long pageId = getPageId(base);
if (isEmpty(grpId, pageId))
// absent value, no removal required
continue;
if (!keyPred.test(grpId, pageId))
// not matched value, no removal required
continue;
long valAt = getValue(base);
setSize(size() - 1);
doBackwardShift(idx);
list.add(valAt);
// Need recheck current cell because of backward shift
idx--;
}
return list;
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class ZookeeperDiscoveryImpl method onCommunicationErrorResolveStatusReceived.
/**
* @param rtState Runtime state.
* @throws Exception If failed.
*/
private void onCommunicationErrorResolveStatusReceived(final ZkRuntimeState rtState) throws Exception {
ZkDiscoveryEventsData evtsData = rtState.evtsData;
UUID futId = evtsData.communicationErrorResolveFutureId();
if (log.isInfoEnabled())
log.info("Received communication status from all nodes [reqId=" + futId + ']');
assert futId != null;
String futPath = zkPaths.distributedFutureBasePath(futId);
List<ClusterNode> initialNodes = rtState.commErrProcNodes;
assert initialNodes != null;
rtState.commErrProcNodes = null;
List<ClusterNode> topSnapshot = rtState.top.topologySnapshot();
Map<UUID, BitSet> nodesRes = U.newHashMap(topSnapshot.size());
Exception err = null;
for (ClusterNode node : topSnapshot) {
byte[] stateBytes = ZkDistributedCollectDataFuture.readNodeResult(futPath, rtState.zkClient, node.order());
ZkCommunicationErrorNodeState nodeState = unmarshalZip(stateBytes);
if (nodeState.err != null) {
if (err == null)
err = new Exception("Failed to resolve communication error.");
err.addSuppressed(nodeState.err);
} else {
assert nodeState.commState != null;
nodesRes.put(node.id(), nodeState.commState);
}
}
long topVer = evtsData.topVer;
GridLongList killedNodesList = null;
if (err == null) {
boolean fullyConnected = true;
for (Map.Entry<UUID, BitSet> e : nodesRes.entrySet()) {
if (!checkFullyConnected(e.getValue(), initialNodes, rtState.top)) {
fullyConnected = false;
break;
}
}
if (fullyConnected) {
if (log.isInfoEnabled()) {
log.info("Finish communication error resolve process automatically, there are no " + "communication errors [reqId=" + futId + ']');
}
} else {
CommunicationFailureResolver rslvr = spi.ignite().configuration().getCommunicationFailureResolver();
if (rslvr != null) {
if (log.isInfoEnabled()) {
log.info("Call communication error resolver [reqId=" + futId + ", rslvr=" + rslvr.getClass().getSimpleName() + ']');
}
ZkCommunicationFailureContext ctx = new ZkCommunicationFailureContext(((IgniteKernal) spi.ignite()).context().cache().context(), topSnapshot, initialNodes, nodesRes);
try {
rslvr.resolve(ctx);
Set<ClusterNode> killedNodes = ctx.killedNodes();
if (killedNodes != null) {
if (log.isInfoEnabled()) {
log.info("Communication error resolver forced nodes stop [reqId=" + futId + ", killNodeCnt=" + killedNodes.size() + ", nodeIds=" + U.nodeIds(killedNodes) + ']');
}
killedNodesList = new GridLongList(killedNodes.size());
for (ClusterNode killedNode : killedNodes) {
killedNodesList.add(((ZookeeperClusterNode) killedNode).internalId());
evtsData.topVer++;
}
}
} catch (Exception e) {
err = e;
U.error(log, "Failed to resolve communication error with configured resolver [reqId=" + futId + ']', e);
}
}
}
}
evtsData.communicationErrorResolveFutureId(null);
ZkCommunicationErrorResolveResult res = new ZkCommunicationErrorResolveResult(killedNodesList, err);
ZkCommunicationErrorResolveFinishMessage msg = new ZkCommunicationErrorResolveFinishMessage(futId, topVer);
msg.res = res;
ZkDistributedCollectDataFuture.saveResult(zkPaths.distributedFutureResultPath(futId), rtState.zkClient, marshalZip(res));
evtsData.evtIdGen++;
ZkDiscoveryCustomEventData evtData = new ZkDiscoveryCustomEventData(evtsData.evtIdGen, 0L, topVer, locNode.id(), msg, null);
evtData.resolvedMsg = msg;
evtsData.addEvent(rtState.top.nodesByOrder.values(), evtData);
saveAndProcessNewEvents();
// Need re-check alive nodes in case join was delayed.
rtState.zkClient.getChildrenAsync(zkPaths.aliveNodesDir, rtState.watcher, rtState.watcher);
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class GridLongListSelfTest method testSerializationCopyConstructor.
/**
*/
@Test
public void testSerializationCopyConstructor() {
MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
ByteBuffer buf = ByteBuffer.allocate(4096);
GridLongList ll = new GridLongList(new long[] { 1L, 2L, 3L });
{
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 25 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.add(2L);
ll.add(4L);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 41 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 33 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
for (int i = 0; i < 300; i++) ll.add(i);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 2434 + /* array */
2, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.clear();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class GridLongListSelfTest method testSerializationDefaultConstructor.
/**
*/
@Test
public void testSerializationDefaultConstructor() {
MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
ByteBuffer buf = ByteBuffer.allocate(4096);
GridLongList ll = new GridLongList();
{
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.add(2L);
ll.add(4L);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 17 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 9 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
for (int i = 0; i < 300; i++) ll.add(i);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(300, ll.size());
Assert.assertEquals(HEADER_SIZE + 2402 + /* array */
2, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.clear();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
}
Aggregations