Skip to content

Commit

Permalink
Merge pull request #719 from FgForrest/717-client-and-server-timeouts…
Browse files Browse the repository at this point in the history
…-are-not-aligned

fix(#717): Client and server timeouts are not aligned
  • Loading branch information
novoj authored Oct 25, 2024
2 parents 0764838 + 6ab2bae commit 324f182
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 134 deletions.
35 changes: 1 addition & 34 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public class EvitaClient implements EvitaContract {
/**
* Created evita service stub that returns futures.
*/
private final StubTimeoutProxy<EvitaServiceFutureStub> evitaServiceFutureStub;
private final EvitaServiceFutureStub evitaServiceFutureStub;
/**
* The configuration of the evitaDB client.
*/
Expand Down Expand Up @@ -311,7 +311,7 @@ public EvitaClient(

ofNullable(grpcConfigurator).ifPresent(it -> it.accept(grpcClientBuilder));
this.grpcClientBuilder = grpcClientBuilder;
this.evitaServiceFutureStub = new StubTimeoutProxy<>(grpcClientBuilder.build(EvitaServiceFutureStub.class));
this.evitaServiceFutureStub = grpcClientBuilder.build(EvitaServiceFutureStub.class);
this.reflectionLookup = new ReflectionLookup(configuration.reflectionLookupBehaviour());
this.timeout = ThreadLocal.withInitial(() -> {
final LinkedList<Timeout> timeouts = new LinkedList<>();
Expand Down Expand Up @@ -789,7 +789,7 @@ private <T> T executeWithEvitaService(
) {
final Timeout timeout = this.timeout.get().peek();
try {
return lambda.apply(this.evitaServiceFutureStub.get(timeout))
return lambda.apply(this.evitaServiceFutureStub.withDeadlineAfter(timeout.timeout(), timeout.timeoutUnit()))
.get(timeout.timeout(), timeout.timeoutUnit());
} catch (ExecutionException e) {
throw EvitaClient.transformException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public class EvitaClientManagement implements EvitaManagementContract, Closeable
/**
* Created evita service stub.
*/
private final StubTimeoutProxy<EvitaManagementServiceStub> evitaManagementServiceStub;
private final EvitaManagementServiceStub evitaManagementServiceStub;
/**
* Created evita service stub that returns futures.
*/
private final StubTimeoutProxy<EvitaManagementServiceFutureStub> evitaManagementServiceFutureStub;
private final EvitaManagementServiceFutureStub evitaManagementServiceFutureStub;

public EvitaClientManagement(@Nonnull EvitaClient evitaClient, @Nonnull GrpcClientBuilder grpcClientBuilder) {
this.evitaClient = evitaClient;
Expand All @@ -109,8 +109,8 @@ public EvitaClientManagement(@Nonnull EvitaClient evitaClient, @Nonnull GrpcClie
evitaClient.getConfiguration().trackedTaskLimit(),
2000
);
this.evitaManagementServiceStub = new StubTimeoutProxy<>(grpcClientBuilder.build(EvitaManagementServiceStub.class));
this.evitaManagementServiceFutureStub = new StubTimeoutProxy<>(grpcClientBuilder.build(EvitaManagementServiceFutureStub.class));
this.evitaManagementServiceStub = grpcClientBuilder.build(EvitaManagementServiceStub.class);
this.evitaManagementServiceFutureStub = grpcClientBuilder.build(EvitaManagementServiceFutureStub.class);
}

@Nonnull
Expand Down Expand Up @@ -513,7 +513,7 @@ private <T> T executeWithEvitaBlockingService(
final Timeout timeout = this.evitaClient.timeout.get().peek();
try {
return lambda.apply(
this.evitaManagementServiceStub.get(timeout)
this.evitaManagementServiceStub.withDeadlineAfter(timeout.timeout(), timeout.timeoutUnit())
);
} catch (ExecutionException e) {
throw EvitaClient.transformException(
Expand Down Expand Up @@ -543,7 +543,7 @@ private <T> T executeWithEvitaService(
) {
final Timeout timeout = this.evitaClient.timeout.get().peek();
try {
return lambda.apply(this.evitaManagementServiceFutureStub.get(timeout))
return lambda.apply(this.evitaManagementServiceFutureStub.withDeadlineAfter(timeout.timeout(), timeout.timeoutUnit()))
.get(timeout.timeout(), timeout.timeoutUnit());
} catch (ExecutionException e) {
throw EvitaClient.transformException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ public class EvitaClientSession implements EvitaSessionContract {
/**
* Entity session service that works with futures.
*/
private final StubTimeoutProxy<EvitaSessionServiceFutureStub> evitaSessionServiceFutureStub;
private final EvitaSessionServiceFutureStub evitaSessionServiceFutureStub;
/**
* Entity session service.
*/
private final StubTimeoutProxy<EvitaSessionServiceStub> evitaSessionServiceStub;
private final EvitaSessionServiceStub evitaSessionServiceStub;
/**
* Contains reference to the catalog name targeted by queries / mutations from this session.
*/
Expand Down Expand Up @@ -292,8 +292,8 @@ public EvitaClientSession(
this.reflectionLookup = evita.getReflectionLookup();
this.proxyFactory = schemaCache.getProxyFactory();
this.schemaCache = schemaCache;
this.evitaSessionServiceFutureStub = new StubTimeoutProxy<>(grpcClientBuilder.build(EvitaSessionServiceFutureStub.class));
this.evitaSessionServiceStub = new StubTimeoutProxy<>(grpcClientBuilder.build(EvitaSessionServiceStub.class));
this.evitaSessionServiceFutureStub = grpcClientBuilder.build(EvitaSessionServiceFutureStub.class);
this.evitaSessionServiceStub = grpcClientBuilder.build(EvitaSessionServiceStub.class);
this.catalogName = catalogName;
this.catalogState = catalogState;
this.commitBehaviour = commitBehaviour;
Expand Down Expand Up @@ -1647,7 +1647,7 @@ private <T> T executeWithBlockingEvitaSessionService(
final Timeout timeout = this.callTimeout.peek();
try {
SessionIdHolder.setSessionId(getId().toString());
return lambda.apply(this.evitaSessionServiceFutureStub.get(timeout))
return lambda.apply(this.evitaSessionServiceFutureStub.withDeadlineAfter(timeout.timeout(), timeout.timeoutUnit()))
.get(timeout.timeout(), timeout.timeoutUnit());
} catch (ExecutionException e) {
throw EvitaClient.transformException(
Expand Down Expand Up @@ -1682,7 +1682,7 @@ private <T> T executeWithAsyncEvitaSessionService(
final Timeout timeout = this.callTimeout.peek();
try {
SessionIdHolder.setSessionId(getId().toString());
return lambda.apply(this.evitaSessionServiceStub.get(timeout));
return lambda.apply(this.evitaSessionServiceStub.withDeadlineAfter(timeout.timeout(), timeout.timeoutUnit()));
} catch (ExecutionException e) {
throw EvitaClient.transformException(
e.getCause() == null ? e : e.getCause(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1759,8 +1759,7 @@ private static EvitaManagementServiceFutureStub getManagementStubInternal(
final EvitaManagementContract management = evitaClient.management();
final Field evitaManagementServiceStub = management.getClass().getDeclaredField("evitaManagementServiceFutureStub");
evitaManagementServiceStub.setAccessible(true);
return ((StubTimeoutProxy<EvitaManagementServiceFutureStub>) evitaManagementServiceStub.get(management))
.get(evitaClient.timeout.get().peek());
return (EvitaManagementServiceFutureStub) evitaManagementServiceStub.get(management);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down

0 comments on commit 324f182

Please sign in to comment.