Search in sources :

Example 6 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class ScatterGatherTest method testMultipleServerHappy.

@Test
public void testMultipleServerHappy() throws Exception {
    MetricsRegistry registry = new MetricsRegistry();
    // Server start
    int serverPort1 = 7071;
    int serverPort2 = 7072;
    int serverPort3 = 7073;
    int serverPort4 = 7074;
    NettyTCPServer server1 = new NettyTCPServer(serverPort1, new TestRequestHandlerFactory(0, 1), null);
    NettyTCPServer server2 = new NettyTCPServer(serverPort2, new TestRequestHandlerFactory(1, 1), null);
    NettyTCPServer server3 = new NettyTCPServer(serverPort3, new TestRequestHandlerFactory(2, 1), null);
    NettyTCPServer server4 = new NettyTCPServer(serverPort4, new TestRequestHandlerFactory(3, 1), null);
    Thread t1 = new Thread(server1);
    Thread t2 = new Thread(server2);
    Thread t3 = new Thread(server3);
    Thread t4 = new Thread(server4);
    t1.start();
    t2.start();
    t3.start();
    t4.start();
    //Client setup
    ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
    ExecutorService poolExecutor = MoreExecutors.sameThreadExecutor();
    ExecutorService service = new ThreadPoolExecutor(1, 1, 1, TimeUnit.DAYS, new LinkedBlockingDeque<Runnable>());
    EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
    NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_");
    PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(eventLoopGroup, new HashedWheelTimer(), clientMetrics);
    KeyedPoolImpl<ServerInstance, NettyClientConnection> pool = new KeyedPoolImpl<ServerInstance, NettyClientConnection>(1, 1, 300000, 1, rm, timedExecutor, poolExecutor, registry);
    rm.setPool(pool);
    SegmentIdSet pg1 = new SegmentIdSet();
    pg1.addSegment(new SegmentId("0"));
    SegmentIdSet pg2 = new SegmentIdSet();
    pg2.addSegment(new SegmentId("1"));
    SegmentIdSet pg3 = new SegmentIdSet();
    pg3.addSegment(new SegmentId("2"));
    SegmentIdSet pg4 = new SegmentIdSet();
    pg4.addSegment(new SegmentId("3"));
    ServerInstance serverInstance1 = new ServerInstance("localhost", serverPort1);
    ServerInstance serverInstance2 = new ServerInstance("localhost", serverPort2);
    ServerInstance serverInstance3 = new ServerInstance("localhost", serverPort3);
    ServerInstance serverInstance4 = new ServerInstance("localhost", serverPort4);
    Map<ServerInstance, SegmentIdSet> pgMap = new HashMap<ServerInstance, SegmentIdSet>();
    pgMap.put(serverInstance1, pg1);
    pgMap.put(serverInstance2, pg2);
    pgMap.put(serverInstance3, pg3);
    pgMap.put(serverInstance4, pg4);
    String request1 = "request_0";
    String request2 = "request_1";
    String request3 = "request_2";
    String request4 = "request_3";
    Map<SegmentIdSet, String> pgMapStr = new HashMap<SegmentIdSet, String>();
    pgMapStr.put(pg1, request1);
    pgMapStr.put(pg2, request2);
    pgMapStr.put(pg3, request3);
    pgMapStr.put(pg4, request4);
    ScatterGatherRequest req = new TestScatterGatherRequest(pgMap, pgMapStr);
    ScatterGatherImpl scImpl = new ScatterGatherImpl(pool, service);
    final ScatterGatherStats scatterGatherStats = new ScatterGatherStats();
    BrokerMetrics brokerMetrics = new BrokerMetrics(new MetricsRegistry());
    CompositeFuture<ServerInstance, ByteBuf> fut = scImpl.scatterGather(req, scatterGatherStats, brokerMetrics);
    Map<ServerInstance, ByteBuf> v = fut.get();
    Assert.assertEquals(v.size(), 4);
    ByteBuf b = v.get(serverInstance1);
    byte[] b2 = new byte[b.readableBytes()];
    b.readBytes(b2);
    String response = new String(b2);
    Assert.assertEquals(response, "response_0_0");
    b = v.get(serverInstance2);
    b2 = new byte[b.readableBytes()];
    b.readBytes(b2);
    response = new String(b2);
    Assert.assertEquals(response, "response_1_0");
    b = v.get(serverInstance3);
    b2 = new byte[b.readableBytes()];
    b.readBytes(b2);
    response = new String(b2);
    Assert.assertEquals(response, "response_2_0");
    b = v.get(serverInstance4);
    b2 = new byte[b.readableBytes()];
    b.readBytes(b2);
    response = new String(b2);
    Assert.assertEquals(response, "response_3_0");
    server1.shutdownGracefully();
    server2.shutdownGracefully();
    server3.shutdownGracefully();
    server4.shutdownGracefully();
    pool.shutdown();
    service.shutdown();
    eventLoopGroup.shutdownGracefully();
}
Also used : HashMap(java.util.HashMap) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) PooledNettyClientResourceManager(com.linkedin.pinot.transport.netty.PooledNettyClientResourceManager) ByteBuf(io.netty.buffer.ByteBuf) SegmentIdSet(com.linkedin.pinot.transport.common.SegmentIdSet) ServerInstance(com.linkedin.pinot.common.response.ServerInstance) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NettyClientMetrics(com.linkedin.pinot.transport.metrics.NettyClientMetrics) SegmentId(com.linkedin.pinot.transport.common.SegmentId) HashedWheelTimer(io.netty.util.HashedWheelTimer) NettyClientConnection(com.linkedin.pinot.transport.netty.NettyClientConnection) KeyedPoolImpl(com.linkedin.pinot.transport.pool.KeyedPoolImpl) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) NettyTCPServer(com.linkedin.pinot.transport.netty.NettyTCPServer) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BrokerMetrics(com.linkedin.pinot.common.metrics.BrokerMetrics) Test(org.testng.annotations.Test)

Example 7 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class ScatterGatherPerfClient method sendRequestAndGetResponse.

/**
   * Helper to send request to server and get back response
   * @param request
   * @return
   * @throws InterruptedException
   * @throws ExecutionException
   * @throws IOException
   * @throws ClassNotFoundException
   */
private String sendRequestAndGetResponse(SimpleScatterGatherRequest request, final ScatterGatherStats scatterGatherStats) throws InterruptedException, ExecutionException, IOException, ClassNotFoundException {
    BrokerMetrics brokerMetrics = new BrokerMetrics(new MetricsRegistry());
    CompositeFuture<ServerInstance, ByteBuf> future = _scatterGather.scatterGather(request, scatterGatherStats, brokerMetrics);
    ByteBuf b = future.getOne();
    String r = null;
    if (null != b) {
        byte[] b2 = new byte[b.readableBytes()];
        b.readBytes(b2);
        r = new String(b2);
    }
    return r;
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) BrokerMetrics(com.linkedin.pinot.common.metrics.BrokerMetrics) ServerInstance(com.linkedin.pinot.common.response.ServerInstance) ByteBuf(io.netty.buffer.ByteBuf)

Example 8 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class MetricsHelper method addMetricsRegistryRegistrationListener.

/**
   * Adds a metrics registry registration listener. When adding a metrics registry registration listener, events are
   * fired to add all previously registered metrics registries to the newly added metrics registry registration
   * listener.
   *
   * @param listener The listener to add
   */
public static void addMetricsRegistryRegistrationListener(MetricsRegistryRegistrationListener listener) {
    synchronized (MetricsHelper.class) {
        metricsRegistryRegistrationListenersMap.put(listener, null);
        // Fire events to register all previously registered metrics registries
        Set<MetricsRegistry> metricsRegistries = metricsRegistryMap.keySet();
        for (MetricsRegistry metricsRegistry : metricsRegistries) {
            listener.onMetricsRegistryRegistered(metricsRegistry);
        }
    }
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry)

Example 9 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class LLCSegmentCommitTest method testSegmentCommit.

@Test
public void testSegmentCommit() throws Exception {
    SegmentCompletionManager.create(createMockHelixManager(), null, new ControllerConf(), new ControllerMetrics(new MetricsRegistry()));
    FakeLLCSegmentCommit segmentCommit = new FakeLLCSegmentCommit();
    Representation representation;
    String strResponse;
    JSONObject jsonResponse;
    // If commitStart returns failed, upload should not be called, and the client should get 'failed'
    segmentCommit._uploadCalled = false;
    segmentCommit._scm.commitStartResponse = SegmentCompletionProtocol.RESP_FAILED;
    representation = segmentCommit.post(null);
    strResponse = representation.getText();
    jsonResponse = JSONObject.parseObject(strResponse);
    Assert.assertEquals(jsonResponse.get(SegmentCompletionProtocol.STATUS_KEY), SegmentCompletionProtocol.ControllerResponseStatus.FAILED.toString());
    Assert.assertFalse(segmentCommit._uploadCalled);
    // if commitStart returns continue, and upload fails, then commitEnd should indicate upload failure.
    segmentCommit._uploadCalled = false;
    segmentCommit._scm.commitStartResponse = SegmentCompletionProtocol.RESP_COMMIT_CONTINUE;
    segmentCommit._scm.commitEndResponse = SegmentCompletionProtocol.RESP_FAILED;
    segmentCommit._uploadReturnValue = false;
    representation = segmentCommit.post(null);
    strResponse = representation.getText();
    jsonResponse = JSONObject.parseObject(strResponse);
    Assert.assertEquals(jsonResponse.get(SegmentCompletionProtocol.STATUS_KEY), SegmentCompletionProtocol.ControllerResponseStatus.FAILED.toString());
    Assert.assertTrue(segmentCommit._uploadCalled);
    Assert.assertFalse(segmentCommit._scm.uploadSuccess);
    // If commitstart returns CONINUE and upload succeeds, we should return whatever commitEnd returns.
    segmentCommit._uploadCalled = false;
    segmentCommit._scm.commitStartResponse = SegmentCompletionProtocol.RESP_COMMIT_CONTINUE;
    segmentCommit._scm.commitEndResponse = SegmentCompletionProtocol.RESP_COMMIT_SUCCESS;
    segmentCommit._uploadReturnValue = true;
    representation = segmentCommit.post(null);
    strResponse = representation.getText();
    jsonResponse = JSONObject.parseObject(strResponse);
    Assert.assertEquals(jsonResponse.get(SegmentCompletionProtocol.STATUS_KEY), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT_SUCCESS.toString());
    Assert.assertTrue(segmentCommit._uploadCalled);
    Assert.assertTrue(segmentCommit._scm.uploadSuccess);
}
Also used : ControllerConf(com.linkedin.pinot.controller.ControllerConf) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) JSONObject(com.alibaba.fastjson.JSONObject) Representation(org.restlet.representation.Representation) ControllerMetrics(com.linkedin.pinot.common.metrics.ControllerMetrics) Test(org.testng.annotations.Test)

Example 10 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class SegmentStatusCheckerTest method nonLeaderTest.

@Test
public void nonLeaderTest() throws Exception {
    final String tableName = "myTable_REALTIME";
    List<String> allTableNames = new ArrayList<String>();
    allTableNames.add(tableName);
    HelixAdmin helixAdmin;
    {
        helixAdmin = mock(HelixAdmin.class);
    }
    {
        helixResourceManager = mock(PinotHelixResourceManager.class);
        when(helixResourceManager.isLeader()).thenReturn(false);
        when(helixResourceManager.getAllPinotTableNames()).thenReturn(allTableNames);
        when(helixResourceManager.getHelixClusterName()).thenReturn("StatusChecker");
        when(helixResourceManager.getHelixAdmin()).thenReturn(helixAdmin);
    }
    {
        config = mock(ControllerConf.class);
        when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
        when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
    }
    metricsRegistry = new MetricsRegistry();
    controllerMetrics = new ControllerMetrics(metricsRegistry);
    segmentStatusChecker = new SegmentStatusChecker(helixResourceManager, config);
    segmentStatusChecker.setMetricsRegistry(controllerMetrics);
    segmentStatusChecker.runSegmentMetrics();
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.SEGMENTS_IN_ERROR_STATE), 0);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.NUMBER_OF_REPLICAS), 0);
    segmentStatusChecker.stop();
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) ArrayList(java.util.ArrayList) HelixAdmin(org.apache.helix.HelixAdmin) ControllerMetrics(com.linkedin.pinot.common.metrics.ControllerMetrics) Test(org.testng.annotations.Test)

Aggregations

MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)45 Test (org.testng.annotations.Test)20 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 ControllerMetrics (com.linkedin.pinot.common.metrics.ControllerMetrics)10 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)9 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)9 HelixAdmin (org.apache.helix.HelixAdmin)9 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 HashedWheelTimer (io.netty.util.HashedWheelTimer)8 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)8 IdealState (org.apache.helix.model.IdealState)8 BrokerMetrics (com.linkedin.pinot.common.metrics.BrokerMetrics)7 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)6 NettyClientConnection (com.linkedin.pinot.transport.netty.NettyClientConnection)6 PooledNettyClientResourceManager (com.linkedin.pinot.transport.netty.PooledNettyClientResourceManager)6 EventLoopGroup (io.netty.channel.EventLoopGroup)6 HashMap (java.util.HashMap)6