Search in sources :

Example 1 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class ItJraftCounterServerTest method before.

/**
 * Before each.
 */
@BeforeEach
void before() {
    LOG.info(">>>>>>>>>>>>>>> Start test method: {}", testInfo.getTestMethod().orElseThrow().getName());
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class SingleThreadExecutorBenchmark method defaultSingleThreadPollExecutorWithMpscBlockingQueue.

@Benchmark
public void defaultSingleThreadPollExecutorWithMpscBlockingQueue() throws InterruptedException {
    ThreadPoolExecutor pool = // 
    ThreadPoolUtil.newBuilder().coreThreads(// 
    1).maximumThreads(// 
    1).poolName(// 
    "default").enableMetric(// 
    false).workQueue(// TODO asch IGNITE-15997
    new MpscBlockingConsumerArrayQueue<>(TIMES)).keepAliveSeconds(// 
    60L).threadFactory(// 
    new NamedThreadFactory("default", true)).build();
    execute(new DefaultSingleThreadExecutor(pool));
}
Also used : MpscBlockingConsumerArrayQueue(org.jctools.queues.MpscBlockingConsumerArrayQueue) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 3 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class ItInternalTableScanTest method setUp.

/**
 * Prepare test environment.
 * <ol>
 * <li>Start network node.</li>
 * <li>Start raft server.</li>
 * <li>Prepare partitioned raft group.</li>
 * <li>Prepare partitioned raft group service.</li>
 * <li>Prepare internal table as a test object.</li>
 * </ol>
 *
 * @throws Exception If any.
 */
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
    NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
    network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
    network.start();
    raftSrv = new RaftServerImpl(network, FACTORY);
    raftSrv.start();
    String grpName = "test_part_grp";
    List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
    mockStorage = mock(PartitionStorage.class);
    txManager = new TxManagerImpl(network, new HeapLockManager());
    txManager.start();
    UUID tblId = UUID.randomUUID();
    raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {

        @Override
        protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
            // Return as is.
            return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
        }
    }), conf);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
    internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) Timestamp(org.apache.ignite.internal.tx.Timestamp) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable) PartitionStorage(org.apache.ignite.internal.storage.PartitionStorage) Pair(org.apache.ignite.internal.util.Pair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class DefaultFixedThreadsExecutorGroupFactory method newExecutorGroup.

@Override
public FixedThreadsExecutorGroup newExecutorGroup(final int nThreads, final String poolName, final int maxPendingTasksPerThread, final boolean useMpscQueue) {
    Requires.requireTrue(nThreads > 0, "nThreads must > 0");
    final boolean mpsc = useMpscQueue && Utils.USE_MPSC_SINGLE_THREAD_EXECUTOR;
    final SingleThreadExecutor[] children = new SingleThreadExecutor[nThreads];
    final ThreadFactory threadFactory = mpsc ? new NamedThreadFactory(poolName, true) : null;
    for (int i = 0; i < nThreads; i++) {
        if (mpsc) {
            children[i] = new MpscSingleThreadExecutor(maxPendingTasksPerThread, threadFactory);
        } else {
            children[i] = new DefaultSingleThreadExecutor(poolName, maxPendingTasksPerThread);
        }
    }
    return new DefaultFixedThreadsExecutorGroup(children);
}
Also used : NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory)

Example 5 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class ItMetaStorageRaftGroupTest method beforeTest.

/**
 * Run {@code NODES} cluster nodes.
 */
@BeforeEach
public void beforeTest(TestInfo testInfo) {
    List<NetworkAddress> localAddresses = findLocalAddresses(NODE_PORT_BASE, NODE_PORT_BASE + NODES);
    var nodeFinder = new StaticNodeFinder(localAddresses);
    localAddresses.stream().map(addr -> ClusterServiceTestUtils.clusterService(testInfo, addr.port(), nodeFinder, NETWORK_FACTORY)).forEach(clusterService -> {
        clusterService.start();
        cluster.add(clusterService);
    });
    for (ClusterService node : cluster) {
        assertTrue(waitForTopology(node, NODES, 1000));
    }
    LOG.info("Cluster started.");
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) Path(java.nio.file.Path) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) Cursor(org.apache.ignite.internal.util.Cursor) Status(org.apache.ignite.raft.jraft.Status) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) Collectors(java.util.stream.Collectors) TestUtils(org.apache.ignite.raft.jraft.test.TestUtils) TestInfo(org.junit.jupiter.api.TestInfo) RaftServer(org.apache.ignite.internal.raft.server.RaftServer) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Replicator(org.apache.ignite.raft.jraft.core.Replicator) NotNull(org.jetbrains.annotations.NotNull) RaftGroupServiceImpl(org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl) ClusterServiceTestUtils.findLocalAddresses(org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ClusterServiceTestUtils(org.apache.ignite.utils.ClusterServiceTestUtils) Mock(org.mockito.Mock) Loza(org.apache.ignite.internal.raft.Loza) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) ArrayList(java.util.ArrayList) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) TestUtils.waitForTopology(org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Iterator(java.util.Iterator) ByteArray(org.apache.ignite.lang.ByteArray) Mockito.when(org.mockito.Mockito.when) WorkDirectory(org.apache.ignite.internal.testframework.WorkDirectory) NetworkAddress(org.apache.ignite.network.NetworkAddress) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) ClusterService(org.apache.ignite.network.ClusterService) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)12 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 NetworkAddress (org.apache.ignite.network.NetworkAddress)5 Peer (org.apache.ignite.raft.client.Peer)5 ClusterService (org.apache.ignite.network.ClusterService)4 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)4 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Loza (org.apache.ignite.internal.raft.Loza)3 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)3 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)3 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)3 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)3 RaftGroupServiceImpl (org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl)3 TestUtils.waitForTopology (org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology)3 ClusterServiceTestUtils (org.apache.ignite.utils.ClusterServiceTestUtils)3 ClusterServiceTestUtils.findLocalAddresses (org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses)3