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));
}
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();
}
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());
}
}
}
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());
}
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);
}
Aggregations