Search in sources :

Example 1 with TableSizeInfo

use of com.linkedin.pinot.common.restlet.resources.TableSizeInfo in project pinot by linkedin.

the class ServerTableSizeReaderTest method createTableSizeInfo.

private TableSizeInfo createTableSizeInfo(String tableName, List<Integer> segmentIndexes) {
    TableSizeInfo tableSizeInfo = new TableSizeInfo();
    tableSizeInfo.tableName = tableName;
    tableSizeInfo.diskSizeInBytes = 0;
    for (int segmentIndex : segmentIndexes) {
        long size = segmentIndexToSize(segmentIndex);
        tableSizeInfo.diskSizeInBytes += size;
        SegmentSizeInfo s = new SegmentSizeInfo("seg" + segmentIndex, size);
        tableSizeInfo.segments.add(s);
    }
    return tableSizeInfo;
}
Also used : SegmentSizeInfo(com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo)

Example 2 with TableSizeInfo

use of com.linkedin.pinot.common.restlet.resources.TableSizeInfo in project pinot by linkedin.

the class TableSizeResource method getTableSize.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/tables/{tableName}/size")
@ApiOperation(value = "Show table storage size", notes = "Lists size of all the segments of the table")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code = 404, message = "Table not found") })
public TableSizeInfo getTableSize(@ApiParam(value = "Table Name with type", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "Provide detailed information", required = false) @DefaultValue("true") @QueryParam("detailed") boolean detailed) throws WebApplicationException {
    InstanceDataManager dataManager = (InstanceDataManager) serverInstance.getInstanceDataManager();
    if (dataManager == null) {
        throw new WebApplicationException("Invalid server initialization", Response.Status.INTERNAL_SERVER_ERROR);
    }
    TableDataManager tableDataManager = dataManager.getTableDataManager(tableName);
    if (tableDataManager == null) {
        throw new WebApplicationException("Table: " + tableName + " is not found", Response.Status.NOT_FOUND);
    }
    TableSizeInfo tableSizeInfo = new TableSizeInfo();
    tableSizeInfo.tableName = tableDataManager.getTableName();
    tableSizeInfo.diskSizeInBytes = 0L;
    ImmutableList<SegmentDataManager> segmentDataManagers = tableDataManager.acquireAllSegments();
    try {
        for (SegmentDataManager segmentDataManager : segmentDataManagers) {
            IndexSegment segment = segmentDataManager.getSegment();
            long segmentSizeBytes = segment.getDiskSizeBytes();
            if (detailed) {
                SegmentSizeInfo segmentSizeInfo = new SegmentSizeInfo(segment.getSegmentName(), segmentSizeBytes);
                tableSizeInfo.segments.add(segmentSizeInfo);
            }
            tableSizeInfo.diskSizeInBytes += segmentSizeBytes;
        }
    } finally {
        // executes fast so duration of holding segments is not a concern
        for (SegmentDataManager segmentDataManager : segmentDataManagers) {
            tableDataManager.releaseSegment(segmentDataManager);
        }
    }
    //invalid to use the segmentDataManagers below
    return tableSizeInfo;
}
Also used : SegmentDataManager(com.linkedin.pinot.core.data.manager.offline.SegmentDataManager) WebApplicationException(javax.ws.rs.WebApplicationException) IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) TableDataManager(com.linkedin.pinot.core.data.manager.offline.TableDataManager) InstanceDataManager(com.linkedin.pinot.core.data.manager.offline.InstanceDataManager) SegmentSizeInfo(com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with TableSizeInfo

use of com.linkedin.pinot.common.restlet.resources.TableSizeInfo in project pinot by linkedin.

the class TableSizeResourceTest method testTableSizeDetailed.

@Test
public void testTableSizeDetailed() {
    TableSizeInfo tableSizeInfo = target.path(TABLE_SIZE_PATH).request().get(TableSizeInfo.class);
    IndexSegment indexSegment = testHelper.indexSegment;
    Assert.assertEquals(tableSizeInfo.tableName, TABLE_NAME);
    Assert.assertEquals(tableSizeInfo.diskSizeInBytes, indexSegment.getDiskSizeBytes());
    Assert.assertEquals(tableSizeInfo.segments.size(), 1);
    Assert.assertEquals(tableSizeInfo.segments.get(0).segmentName, indexSegment.getSegmentName());
    Assert.assertEquals(tableSizeInfo.segments.get(0).diskSizeInBytes, indexSegment.getDiskSizeBytes());
    Assert.assertEquals(tableSizeInfo.diskSizeInBytes, indexSegment.getDiskSizeBytes());
}
Also used : IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 4 with TableSizeInfo

use of com.linkedin.pinot.common.restlet.resources.TableSizeInfo in project pinot by linkedin.

the class ServerTableSizeReader method getSizeDetailsFromServers.

public Map<String, List<SegmentSizeInfo>> getSizeDetailsFromServers(BiMap<String, String> serverEndPoints, String table, int timeoutMsec) {
    List<String> serverUrls = new ArrayList<>(serverEndPoints.size());
    BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
    for (String endpoint : endpointsToServers.keySet()) {
        String tableSizeUri = "http://" + endpoint + "/table/" + table + "/size";
        serverUrls.add(tableSizeUri);
    }
    MultiGetRequest mget = new MultiGetRequest(executor, connectionManager);
    LOGGER.info("Reading segment sizes from servers for table: {}, timeoutMsec: {}", table, timeoutMsec);
    CompletionService<GetMethod> completionService = mget.execute(serverUrls, timeoutMsec);
    Map<String, List<SegmentSizeInfo>> serverSegmentSizes = new HashMap<>(serverEndPoints.size());
    for (int i = 0; i < serverUrls.size(); i++) {
        GetMethod getMethod = null;
        try {
            getMethod = completionService.take().get();
            URI uri = getMethod.getURI();
            String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort());
            if (getMethod.getStatusCode() >= 300) {
                LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode());
                continue;
            }
            TableSizeInfo tableSizeInfo = new ObjectMapper().readValue(getMethod.getResponseBodyAsString(), TableSizeInfo.class);
            serverSegmentSizes.put(instance, tableSizeInfo.segments);
        } catch (InterruptedException e) {
            LOGGER.warn("Interrupted exception while reading segment size for table: {}", table, e);
        } catch (ExecutionException e) {
            if (Throwables.getRootCause(e) instanceof SocketTimeoutException) {
                LOGGER.warn("Server request to read table size was timed out for table: {}", table, e);
            } else if (Throwables.getRootCause(e) instanceof ConnectTimeoutException) {
                LOGGER.warn("Server request to read table size timed out waiting for connection. table: {}", table, e);
            } else if (Throwables.getRootCause(e) instanceof ConnectionPoolTimeoutException) {
                LOGGER.warn("Server request to read table size timed out on getting a connection from pool, table: {}", table, e);
            } else {
                LOGGER.warn("Execution exception while reading segment sizes for table: {}", table, e);
            }
        } catch (Exception e) {
            LOGGER.warn("Error while reading segment sizes for table: {}", table);
        } finally {
            if (getMethod != null) {
                getMethod.releaseConnection();
            }
        }
    }
    LOGGER.info("Finished reading segment sizes for table: {}", table);
    return serverSegmentSizes;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(org.apache.commons.httpclient.URI) ExecutionException(java.util.concurrent.ExecutionException) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionPoolTimeoutException(org.apache.commons.httpclient.ConnectionPoolTimeoutException) MultiGetRequest(com.linkedin.pinot.common.http.MultiGetRequest) ConnectionPoolTimeoutException(org.apache.commons.httpclient.ConnectionPoolTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) List(java.util.List) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) ExecutionException(java.util.concurrent.ExecutionException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException)

Example 5 with TableSizeInfo

use of com.linkedin.pinot.common.restlet.resources.TableSizeInfo in project pinot by linkedin.

the class TableSizeReaderTest method createHandler.

private HttpHandler createHandler(final int status, final List<SegmentSizeInfo> segmentSizes, final int sleepTimeMs) {
    return new HttpHandler() {

        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            if (sleepTimeMs > 0) {
                try {
                    Thread.sleep(sleepTimeMs);
                } catch (InterruptedException e) {
                    LOGGER.info("Handler interrupted during sleep");
                }
            }
            TableSizeInfo tableInfo = new TableSizeInfo("myTable", 0);
            tableInfo.segments = segmentSizes;
            for (SegmentSizeInfo segmentSize : segmentSizes) {
                tableInfo.diskSizeInBytes += segmentSize.diskSizeInBytes;
            }
            String json = new ObjectMapper().writeValueAsString(tableInfo);
            httpExchange.sendResponseHeaders(status, json.length());
            OutputStream responseBody = httpExchange.getResponseBody();
            responseBody.write(json.getBytes());
            responseBody.close();
        }
    };
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) OutputStream(java.io.OutputStream) HttpExchange(com.sun.net.httpserver.HttpExchange) SegmentSizeInfo(com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) Matchers.anyString(org.mockito.Matchers.anyString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TableSizeInfo (com.linkedin.pinot.common.restlet.resources.TableSizeInfo)7 SegmentSizeInfo (com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo)3 IndexSegment (com.linkedin.pinot.core.indexsegment.IndexSegment)3 AfterTest (org.testng.annotations.AfterTest)3 Test (org.testng.annotations.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MultiGetRequest (com.linkedin.pinot.common.http.MultiGetRequest)1 InstanceDataManager (com.linkedin.pinot.core.data.manager.offline.InstanceDataManager)1 SegmentDataManager (com.linkedin.pinot.core.data.manager.offline.SegmentDataManager)1 TableDataManager (com.linkedin.pinot.core.data.manager.offline.TableDataManager)1 HttpExchange (com.sun.net.httpserver.HttpExchange)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 OutputStream (java.io.OutputStream)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1