Search in sources :

Example 11 with GridLongList

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);
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) PagesListMetaIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO) GridLongList(org.apache.ignite.internal.util.GridLongList) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException) IgniteException(org.apache.ignite.IgniteException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) LinkedList(java.util.LinkedList) Collectors.toList(java.util.stream.Collectors.toList) HashSet(java.util.HashSet)

Example 12 with GridLongList

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;
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList)

Example 13 with GridLongList

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CommunicationFailureResolver(org.apache.ignite.configuration.CommunicationFailureResolver) BitSet(java.util.BitSet) GridLongList(org.apache.ignite.internal.util.GridLongList) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) DataFormatException(java.util.zip.DataFormatException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 14 with GridLongList

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());
    }
}
Also used : DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) GridLongList(org.apache.ignite.internal.util.GridLongList) DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) MessageWriter(org.apache.ignite.plugin.extensions.communication.MessageWriter) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 15 with GridLongList

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());
    }
}
Also used : DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) GridLongList(org.apache.ignite.internal.util.GridLongList) DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) MessageWriter(org.apache.ignite.plugin.extensions.communication.MessageWriter) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

GridLongList (org.apache.ignite.internal.util.GridLongList)39 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ByteBuffer (java.nio.ByteBuffer)5 DirectMessageWriter (org.apache.ignite.internal.direct.DirectMessageWriter)5 MessageWriter (org.apache.ignite.plugin.extensions.communication.MessageWriter)5 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteException (org.apache.ignite.IgniteException)3 PagesListAddPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord)3 PagesListInitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)3 PagesListSetNextRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PagesListMetaIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO)2