Search in sources :

Example 1 with ConnectorMetadataUpdateHandle

use of com.facebook.presto.spi.ConnectorMetadataUpdateHandle in project presto by prestodb.

the class TestHiveFileRenamer method testMultiThreadedRequests.

@Test
public void testMultiThreadedRequests() throws InterruptedException {
    ExecutorService service = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
    List<String> fileNames = new CopyOnWriteArrayList<>();
    HiveFileRenamer hiveFileRenamer = new HiveFileRenamer();
    // Spawn THREAD_COUNT threads. And each thread will send REQUEST_COUNT requests to HiveFileRenamer
    for (int i = 0; i < THREAD_COUNT; i++) {
        service.execute(() -> {
            List<ConnectorMetadataUpdateHandle> requests = createHiveMetadataUpdateRequests(TEST_SCHEMA_NAME, TEST_TABLE_NAME, TEST_PARTITION_NAME);
            fileNames.addAll(getFileNames(hiveFileRenamer, requests));
            latch.countDown();
        });
    }
    // wait for all threads to finish
    latch.await();
    // Assert the # of filenames
    assertEquals(fileNames.size(), THREAD_COUNT * REQUEST_COUNT);
    // Assert that the filenames are an increasing sequence
    assertTrue(areFileNamesIncreasingSequentially(fileNames));
}
Also used : ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 2 with ConnectorMetadataUpdateHandle

use of com.facebook.presto.spi.ConnectorMetadataUpdateHandle in project presto by prestodb.

the class HiveFileRenamer method getMetadataUpdateResults.

public List<ConnectorMetadataUpdateHandle> getMetadataUpdateResults(List<ConnectorMetadataUpdateHandle> metadataUpdateRequests, QueryId queryId) {
    ImmutableList.Builder<ConnectorMetadataUpdateHandle> metadataUpdateResults = ImmutableList.builder();
    for (ConnectorMetadataUpdateHandle connectorMetadataUpdateHandle : metadataUpdateRequests) {
        HiveMetadataUpdateHandle request = (HiveMetadataUpdateHandle) connectorMetadataUpdateHandle;
        String fileName = getFileName(request, queryId);
        metadataUpdateResults.add(new HiveMetadataUpdateHandle(request.getRequestId(), request.getSchemaTableName(), request.getPartitionName(), Optional.of(fileName)));
    }
    return metadataUpdateResults.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle)

Example 3 with ConnectorMetadataUpdateHandle

use of com.facebook.presto.spi.ConnectorMetadataUpdateHandle in project presto by prestodb.

the class HiveMetadataUpdater method updateResultAsync.

private void updateResultAsync(List<ConnectorMetadataUpdateHandle> results) {
    for (ConnectorMetadataUpdateHandle connectorMetadataUpdateHandle : results) {
        HiveMetadataUpdateHandle updateResult = (HiveMetadataUpdateHandle) connectorMetadataUpdateHandle;
        UUID requestId = updateResult.getRequestId();
        if (!requestFutureMap.containsKey(requestId)) {
            continue;
        }
        Optional<String> fileName = updateResult.getMetadataUpdate();
        if (fileName.isPresent()) {
            // remove the request from queue
            hiveMetadataRequestQueue.removeIf(metadataUpdateRequest -> metadataUpdateRequest.getRequestId().equals(requestId));
            // Set the fileName future
            requestFutureMap.get(requestId).set(fileName.get());
        }
    }
}
Also used : ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) UUID(java.util.UUID)

Example 4 with ConnectorMetadataUpdateHandle

use of com.facebook.presto.spi.ConnectorMetadataUpdateHandle in project presto by prestodb.

the class SqlTask method getMetadataUpdateRequests.

private MetadataUpdates getMetadataUpdateRequests(TaskHolder taskHolder) {
    ConnectorId connectorId = null;
    ImmutableList.Builder<ConnectorMetadataUpdateHandle> connectorMetadataUpdatesBuilder = ImmutableList.builder();
    if (taskHolder.getTaskExecution() != null) {
        TaskMetadataContext taskMetadataContext = taskHolder.getTaskExecution().getTaskContext().getTaskMetadataContext();
        if (!taskMetadataContext.getMetadataUpdaters().isEmpty()) {
            connectorId = taskMetadataContext.getConnectorId();
            for (ConnectorMetadataUpdater metadataUpdater : taskMetadataContext.getMetadataUpdaters()) {
                connectorMetadataUpdatesBuilder.addAll(metadataUpdater.getPendingMetadataUpdateRequests());
            }
        }
    }
    return new MetadataUpdates(connectorId, connectorMetadataUpdatesBuilder.build());
}
Also used : MetadataUpdates(com.facebook.presto.metadata.MetadataUpdates) ConnectorMetadataUpdater(com.facebook.presto.spi.connector.ConnectorMetadataUpdater) ImmutableList(com.google.common.collect.ImmutableList) ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 5 with ConnectorMetadataUpdateHandle

use of com.facebook.presto.spi.ConnectorMetadataUpdateHandle in project presto by prestodb.

the class MetadataManager method getMetadataUpdateResults.

@Override
public MetadataUpdates getMetadataUpdateResults(Session session, QueryManager queryManager, MetadataUpdates metadataUpdateRequests, QueryId queryId) {
    ConnectorId connectorId = metadataUpdateRequests.getConnectorId();
    ConnectorMetadata metadata = getCatalogMetadata(session, connectorId).getMetadata();
    if (queryManager != null && !queriesWithRegisteredCallbacks.contains(queryId)) {
        // This is the first time we are getting requests for queryId.
        // Register a callback, so the we do the cleanup when query fails/finishes.
        queryManager.addStateChangeListener(queryId, state -> {
            if (state.isDone()) {
                metadata.doMetadataUpdateCleanup(queryId);
                queriesWithRegisteredCallbacks.remove(queryId);
            }
        });
        queriesWithRegisteredCallbacks.add(queryId);
    }
    List<ConnectorMetadataUpdateHandle> metadataResults = metadata.getMetadataUpdateResults(metadataUpdateRequests.getMetadataUpdates(), queryId);
    return new MetadataUpdates(connectorId, metadataResults);
}
Also used : ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

ConnectorMetadataUpdateHandle (com.facebook.presto.spi.ConnectorMetadataUpdateHandle)5 ConnectorId (com.facebook.presto.spi.ConnectorId)2 ImmutableList (com.google.common.collect.ImmutableList)2 MetadataUpdates (com.facebook.presto.metadata.MetadataUpdates)1 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)1 ConnectorMetadataUpdater (com.facebook.presto.spi.connector.ConnectorMetadataUpdater)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.testng.annotations.Test)1