private PrestoThriftService openClient(PrestoThriftSplit split) { if (split.getHosts().isEmpty()) { return client.get(thriftHeaders); } String hosts = split.getHosts().stream() .map(host -> host.toHostAddress().toString()) .collect(joining(",")); return client.get(Optional.of(hosts), thriftHeaders); }
@Override public void configure(Binder binder) { driftClientBinder(binder) .bindDriftClient(PrestoThriftService.class) .withExceptionClassifier(t -> { if (t instanceof PrestoThriftServiceException) { boolean retryable = ((PrestoThriftServiceException) t).isRetryable(); return new ExceptionClassification(Optional.of(retryable), HostStatus.NORMAL); } return NORMAL_EXCEPTION; }); binder.bind(ThriftConnector.class).in(Scopes.SINGLETON); binder.bind(ThriftMetadata.class).in(Scopes.SINGLETON); binder.bind(ThriftSplitManager.class).in(Scopes.SINGLETON); binder.bind(ThriftPageSourceProvider.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(ThriftConnectorConfig.class); binder.bind(ThriftSessionProperties.class).in(Scopes.SINGLETON); binder.bind(ThriftIndexProvider.class).in(Scopes.SINGLETON); binder.bind(ThriftConnectorStats.class).in(Scopes.SINGLETON); newExporter(binder).export(ThriftConnectorStats.class) .as(generatedNameOf(ThriftConnectorStats.class, connectorId)); }
@Override public ListenableFuture<Object> invoke(InvokeRequest request) { return filter.invoke(request, next); }
public ExceptionClassification toExceptionClassification() { return new ExceptionClassification(retry, hostStatus); }
public void add(ExceptionClassification classification) { retry = mergeRetry(retry, classification.isRetry()); hostStatus = natural().max(hostStatus, classification.getHostStatus()); }
private static void assertRetriesFailedInformation(Throwable exception, int expectedFailedConnections, int expectedInvocationAttempts, int expectedOverloaded) { RetriesFailedException retriesFailedException = getRetriesFailedException(exception); assertEquals(retriesFailedException.getFailedConnections(), expectedFailedConnections); assertEquals(retriesFailedException.getInvocationAttempts(), expectedInvocationAttempts); assertEquals(retriesFailedException.getOverloadedRejects(), expectedOverloaded); }
public boolean checkWasInterrupted() { return wasInterrupted(); } }
private static void testConnectionFailedDelay(int numberOfAddresses, int numberOfRetriesPerAddress, int expectedDelays) throws Exception { testConnectionFailedDelay(false, numberOfAddresses, numberOfRetriesPerAddress, expectedDelays); testConnectionFailedDelay(true, numberOfAddresses, numberOfRetriesPerAddress, expectedDelays); }
public static Exception createClassifiedException(boolean retry, HostStatus hostStatus) { return createClassifiedException(retry, hostStatus, true); }
public TestingAddressSelector(int maxAddresses) { this(createAddresses(maxAddresses)); }
public MockMethodInvokerFactory(Supplier<ListenableFuture<Object>> resultsSupplier) { this.methodInvoker = new MockMethodInvoker(resultsSupplier); }
@Override public List<String> listSchemaNames(ConnectorSession session) { try { return client.get(thriftHeaderProvider.getHeaders(session)).listSchemaNames(); } catch (PrestoThriftServiceException | TException e) { throw toPrestoException(e); } }
public ExceptionClassification toExceptionClassification() { return new ExceptionClassification(retry, hostStatus); }
public void add(ExceptionClassification classification) { retry = mergeRetry(retry, classification.isRetry()); hostStatus = natural().max(hostStatus, classification.getHostStatus()); }
@Override public ListenableFuture<Object> invoke(InvokeRequest request) { return filter.invoke(request, next); }
private ListenableFuture<PrestoThriftSplitBatch> sendSplitRequest(@Nullable PrestoThriftId nextToken) { long start = System.nanoTime(); ListenableFuture<PrestoThriftSplitBatch> future = client.get(thriftHeaders).getIndexSplits( schemaTableName, lookupColumnNames, outputColumnNames, keys, outputConstraint, MAX_SPLIT_COUNT, new PrestoThriftNullableToken(nextToken)); future = catchingThriftException(future); future.addListener(() -> readTimeNanos.addAndGet(System.nanoTime() - start), directExecutor()); return future; }
@Override public List<SchemaTableName> listTables(ConnectorSession session, String schemaNameOrNull) { try { return client.get(thriftHeaderProvider.getHeaders(session)).listTables(new PrestoThriftNullableSchemaName(schemaNameOrNull)).stream() .map(PrestoThriftSchemaTableName::toSchemaTableName) .collect(toImmutableList()); } catch (PrestoThriftServiceException | TException e) { throw toPrestoException(e); } }
private PrestoThriftNullableTableMetadata getTableMetadata(SchemaTableName schemaTableName) { // treat invalid names as not found PrestoThriftSchemaTableName name; try { name = new PrestoThriftSchemaTableName(schemaTableName); } catch (IllegalArgumentException e) { return new PrestoThriftNullableTableMetadata(null); } try { return client.get().getTableMetadata(name); } catch (PrestoThriftServiceException | TException e) { throw toPrestoException(e); } } }
@Override public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy) { ThriftTableLayoutHandle layoutHandle = (ThriftTableLayoutHandle) layout; return new ThriftSplitSource( client.get(thriftHeaderProvider.getHeaders(session)), new PrestoThriftSchemaTableName(layoutHandle.getSchemaName(), layoutHandle.getTableName()), layoutHandle.getColumns().map(ThriftSplitManager::columnNames), tupleDomainToThriftTupleDomain(layoutHandle.getConstraint())); }