Search in sources :

Example 11 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class GridCacheAdapter method sizeLongAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<Long> sizeLongAsync(final int part, final CachePeekMode[] peekModes) {
    assert peekModes != null;
    final PeekModes modes = parsePeekModes(peekModes, true);
    IgniteClusterEx cluster = ctx.grid().cluster();
    final GridCacheAffinityManager aff = ctx.affinity();
    final AffinityTopologyVersion topVer = aff.affinityTopologyVersion();
    ClusterGroup grp = cluster.forDataNodes(name());
    Collection<ClusterNode> nodes = new ArrayList<>(grp.forPredicate(new IgnitePredicate<ClusterNode>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean apply(ClusterNode clusterNode) {
            return ((modes.primary && aff.primaryByPartition(clusterNode, part, topVer)) || (modes.backup && aff.backupByPartition(clusterNode, part, topVer)));
        }
    }).nodes());
    if (nodes.isEmpty())
        return new GridFinishedFuture<>(0L);
    ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
    return ctx.kernalContext().task().execute(new PartitionSizeLongTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes, part), null);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 12 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class GridBaselineCommandHandler method currentState.

/**
 * Collect baseline topology command result.
 *
 * @return Baseline descriptor.
 */
private GridBaselineCommandResponse currentState() {
    IgniteClusterEx cluster = ctx.grid().cluster();
    Collection<? extends BaselineNode> srvrs = cluster.forServers().nodes();
    return new GridBaselineCommandResponse(cluster.active(), cluster.topologyVersion(), currentBaseLine(), srvrs);
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx)

Example 13 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class GridBaselineCommandHandler method handleAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
    assert req != null;
    assert SUPPORTED_COMMANDS.contains(req.command());
    assert req instanceof GridRestBaselineRequest : "Invalid type of baseline request.";
    if (log.isDebugEnabled())
        log.debug("Handling baseline REST request: " + req);
    GridRestBaselineRequest req0 = (GridRestBaselineRequest) req;
    try {
        IgniteClusterEx cluster = ctx.grid().cluster();
        List<Object> consistentIds = req0.consistentIds();
        switch(req0.command()) {
            case BASELINE_CURRENT_STATE:
                {
                    break;
                }
            case BASELINE_SET:
                {
                    Long topVer = req0.topologyVersion();
                    if (topVer == null && consistentIds == null)
                        throw new IgniteCheckedException("Failed to handle request (either topVer or consistentIds should be specified).");
                    if (topVer != null)
                        cluster.setBaselineTopology(topVer);
                    else
                        cluster.setBaselineTopology(filterServerNodesByConsId(consistentIds));
                    break;
                }
            case BASELINE_ADD:
                {
                    if (consistentIds == null)
                        throw new IgniteCheckedException(missingParameter("consistentIds"));
                    Set<BaselineNode> baselineTop = new HashSet<>(currentBaseLine());
                    baselineTop.addAll(filterServerNodesByConsId(consistentIds));
                    cluster.setBaselineTopology(baselineTop);
                    break;
                }
            case BASELINE_REMOVE:
                {
                    if (consistentIds == null)
                        throw new IgniteCheckedException(missingParameter("consistentIds"));
                    Collection<BaselineNode> baseline = currentBaseLine();
                    Set<BaselineNode> baselineTop = new HashSet<>(baseline);
                    baselineTop.removeAll(filterNodesByConsId(baseline, consistentIds));
                    cluster.setBaselineTopology(baselineTop);
                    break;
                }
            default:
                assert false : "Invalid command for baseline handler: " + req;
        }
        return new GridFinishedFuture<>(new GridRestResponse(currentState()));
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    } finally {
        if (log.isDebugEnabled())
            log.debug("Handled baseline REST request: " + req);
    }
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashSet(java.util.HashSet) Set(java.util.Set) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestBaselineRequest(org.apache.ignite.internal.processors.rest.request.GridRestBaselineRequest) Collection(java.util.Collection) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 14 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class BaselineEventsTest method testChangeAutoAdjustTimeout.

/**
 */
@Test
public void testChangeAutoAdjustTimeout() throws Exception {
    IgniteClusterEx cluster = startGrids(2).cluster();
    cluster.active(true);
    AtomicLong autoAdjustTimeout = new AtomicLong();
    listen(grid(0), event -> {
        BaselineConfigurationChangedEvent bltCfgChangedEvt = (BaselineConfigurationChangedEvent) event;
        autoAdjustTimeout.set(bltCfgChangedEvt.autoAdjustTimeout());
        return true;
    }, EventType.EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED);
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "enable", "timeout", "10", "--yes")));
    assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 10L, 3_000));
    cluster.baselineAutoAdjustTimeout(50);
    assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 50L, 3_000));
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 15 with IgniteClusterEx

use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.

the class IgniteIndexReaderTest method populateData.

/**
 * Filling node with data.
 *
 * @param node Node.
 * @param insert {@code True} for inserting some data and creating tables and indexes,
 *      {@code false} for inserting, updating and deleting data and deleting indexes, {@code null} for all data processing.
 * {@code True} if only insert data, {@code false} if delete from {@link #DEFAULT_CACHE_NAME} and {@code null} all at once.
 * @throws Exception If fails.
 */
protected void populateData(IgniteEx node, @Nullable Boolean insert) throws Exception {
    requireNonNull(node);
    IgniteClusterEx cluster = node.cluster();
    if (!cluster.active())
        cluster.active(true);
    IgniteCache<Integer, Object> qryCache = node.cache(QUERY_CACHE_NAME);
    int s = isNull(insert) || insert ? 0 : 70;
    int e = isNull(insert) || !insert ? 100 : 80;
    for (int i = s; i < e; i++) qryCache.put(i, new TestClass1(i, valueOf(i)));
    s = isNull(insert) || insert ? 0 : 50;
    e = isNull(insert) || !insert ? 70 : 60;
    for (int i = s; i < e; i++) qryCache.put(i, new TestClass2(i, valueOf(i)));
    IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < CREATED_TABLES_CNT; i++) createAndFillTable(cache, TableInfo.generate(i), insert);
    forceCheckpoint(node);
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx)

Aggregations

IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)18 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 Test (org.junit.Test)7 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 ArrayList (java.util.ArrayList)4 CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)3 IgniteClusterNode (org.apache.ignite.internal.managers.discovery.IgniteClusterNode)3 UUID (java.util.UUID)2 GridStringLogger (org.apache.ignite.testframework.GridStringLogger)2 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1