Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ var ServiceDefinition.Configurator.ingressPrivate: Boolean?
this.ingressPrivate(value)
}

/**
* When set to `false`, Restate never preempts invocations to this service, with all its handlers.
* Preemption means that when the restate-server runs out of concurrency capacity, it can eagerly
* suspend an invocation that is waiting on an await point (e.g. a timer, a call response, an
* awakeable), to free up capacity for other invocations. Non-preemptable invocations still suspend
* when the [inactivityTimeout] fires.
*
* Use this when suspending and later replaying invocations of this service is undesirable, e.g.
* because resuming them is expensive.
*
* If unset, the restate-server treats the service as preemptable (`true`). A handler can override
* this value with [HandlerDefinition.Configurator.preemptable].
*
* *NOTE:* This setting requires a restate-server supporting the service discovery protocol V6. When
* registering against an older restate-server, this setting is ignored, as older restate-server
* versions never preempt invocations.
*/
var ServiceDefinition.Configurator.preemptable: Boolean?
get() {
return this.preemptable()
}
set(value) {
this.preemptable(value)
}

/**
* Retry policy used by Restate when invoking this service.
*
Expand Down Expand Up @@ -315,6 +340,31 @@ var HandlerDefinition.Configurator.ingressPrivate: Boolean?
this.ingressPrivate(value)
}

/**
* When set to `false`, Restate never preempts invocations to this handler. Preemption means that
* when the restate-server runs out of concurrency capacity, it can eagerly suspend an invocation
* that is waiting on an await point (e.g. a timer, a call response, an awakeable), to free up
* capacity for other invocations. Non-preemptable invocations still suspend when the
* [inactivityTimeout] fires.
*
* Use this when suspending and later replaying invocations of this handler is undesirable, e.g.
* because resuming them is expensive.
*
* This overrides the value set for the service. If unset both here and on the service, the
* restate-server treats the handler as preemptable (`true`).
*
* *NOTE:* This setting requires a restate-server supporting the service discovery protocol V6. When
* registering against an older restate-server, this setting is ignored, as older restate-server
* versions never preempt invocations.
*/
var HandlerDefinition.Configurator.preemptable: Boolean?
get() {
return this.preemptable()
}
set(value) {
this.preemptable(value)
}

/**
* When set to `true`, lazy state will be enabled for all invocations to this handler. This is
* relevant only for workflows and virtual objects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class HandlerDefinition<REQ, RES> {
private final @Nullable Duration workflowRetention;
private final @Nullable Duration journalRetention;
private final @Nullable Boolean ingressPrivate;
private final @Nullable Boolean preemptable;
private final @Nullable Boolean enableLazyState;
private final @Nullable InvocationRetryPolicy invocationRetryPolicy;

Expand All @@ -52,6 +53,7 @@ public final class HandlerDefinition<REQ, RES> {
@Nullable Duration workflowRetention,
@Nullable Duration journalRetention,
@Nullable Boolean ingressPrivate,
@Nullable Boolean preemptable,
@Nullable Boolean enableLazyState,
@Nullable InvocationRetryPolicy invocationRetryPolicy) {
this.name = name;
Expand All @@ -68,6 +70,7 @@ public final class HandlerDefinition<REQ, RES> {
this.workflowRetention = workflowRetention;
this.journalRetention = journalRetention;
this.ingressPrivate = ingressPrivate;
this.preemptable = preemptable;
this.enableLazyState = enableLazyState;
this.invocationRetryPolicy = invocationRetryPolicy;
}
Expand Down Expand Up @@ -176,6 +179,15 @@ public HandlerRunner<REQ, RES> getRunner() {
return ingressPrivate;
}

/**
* @return false if the restate-server must never preempt (eagerly suspend) invocations to this
* handler. Null if unset, meaning the service-level setting applies.
* @see Configurator#preemptable(Boolean)
*/
public @Nullable Boolean getPreemptable() {
return preemptable;
}

/**
* @return true if this handler will use lazy state.
* @see Configurator#enableLazyState(Boolean)
Expand Down Expand Up @@ -208,6 +220,7 @@ public HandlerDefinition<REQ, RES> withAcceptContentType(String acceptContentTyp
workflowRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
}
Expand All @@ -228,6 +241,7 @@ public HandlerDefinition<REQ, RES> withDocumentation(@Nullable String documentat
workflowRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
}
Expand All @@ -248,6 +262,7 @@ public HandlerDefinition<REQ, RES> withMetadata(Map<String, String> metadata) {
workflowRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
}
Expand All @@ -269,6 +284,7 @@ public HandlerDefinition<REQ, RES> configure(
workflowRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
configurator.accept(configuratorObj);
Expand All @@ -288,6 +304,7 @@ public HandlerDefinition<REQ, RES> configure(
configuratorObj.workflowRetention,
configuratorObj.journalRetention,
configuratorObj.ingressPrivate,
configuratorObj.preemptable,
configuratorObj.enableLazyState,
configuratorObj.invocationRetryPolicy);
}
Expand All @@ -305,6 +322,7 @@ public static final class Configurator {
private @Nullable Duration workflowRetention;
private @Nullable Duration journalRetention;
private @Nullable Boolean ingressPrivate;
private @Nullable Boolean preemptable;
private @Nullable Boolean enableLazyState;
private @Nullable InvocationRetryPolicy invocationRetryPolicy;

Expand All @@ -319,6 +337,7 @@ private Configurator(
@Nullable Duration workflowRetention,
@Nullable Duration journalRetention,
@Nullable Boolean ingressPrivate,
@Nullable Boolean preemptable,
@Nullable Boolean enableLazyState,
@Nullable InvocationRetryPolicy invocationRetryPolicy) {
this.handlerType = handlerType;
Expand All @@ -331,6 +350,7 @@ private Configurator(
this.workflowRetention = workflowRetention;
this.journalRetention = journalRetention;
this.ingressPrivate = ingressPrivate;
this.preemptable = preemptable;
this.enableLazyState = enableLazyState;
this.invocationRetryPolicy = invocationRetryPolicy;
}
Expand Down Expand Up @@ -553,6 +573,38 @@ public Configurator ingressPrivate(@Nullable Boolean ingressPrivate) {
return this;
}

/**
* @return configured preemptable.
* @see #preemptable(Boolean)
*/
public @Nullable Boolean preemptable() {
return preemptable;
}

/**
* When set to {@code false}, Restate never preempts invocations to this handler. Preemption
* means that when the restate-server runs out of concurrency capacity, it can eagerly suspend
* an invocation that is waiting on an await point (e.g. a timer, a call response, an
* awakeable), to free up capacity for other invocations. Non-preemptable invocations still
* suspend when the {@link #inactivityTimeout(Duration)} fires.
*
* <p>Use this when suspending and later replaying invocations of this handler is undesirable,
* e.g. because resuming them is expensive.
*
* <p>This overrides the value set for the service. If unset both here and on the service, the
* restate-server treats the handler as preemptable ({@code true}).
*
* <p><b>NOTE:</b> This setting requires a restate-server supporting the service discovery
* protocol V6. When registering against an older restate-server, this setting is ignored, as
* older restate-server versions never preempt invocations.
*
* @return this
*/
public Configurator preemptable(@Nullable Boolean preemptable) {
this.preemptable = preemptable;
return this;
}

/**
* @return configured enable lazy state.
* @see #enableLazyState(Boolean)
Expand Down Expand Up @@ -629,6 +681,7 @@ public static <REQ, RES> HandlerDefinition<REQ, RES> of(
null,
null,
null,
null,
null);
}

Expand All @@ -649,6 +702,7 @@ && getHandlerType() == that.getHandlerType()
&& Objects.equals(getWorkflowRetention(), that.getWorkflowRetention())
&& Objects.equals(getJournalRetention(), that.getJournalRetention())
&& Objects.equals(getIngressPrivate(), that.getIngressPrivate())
&& Objects.equals(getPreemptable(), that.getPreemptable())
&& Objects.equals(getEnableLazyState(), that.getEnableLazyState())
&& Objects.equals(getInvocationRetryPolicy(), that.getInvocationRetryPolicy());
}
Expand All @@ -670,6 +724,7 @@ public int hashCode() {
getWorkflowRetention(),
getJournalRetention(),
getIngressPrivate(),
getPreemptable(),
getEnableLazyState(),
getInvocationRetryPolicy());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class ServiceDefinition {
private final @Nullable Duration idempotencyRetention;
private final @Nullable Duration journalRetention;
private final @Nullable Boolean ingressPrivate;
private final @Nullable Boolean preemptable;
private final @Nullable Boolean enableLazyState;
private final @Nullable InvocationRetryPolicy invocationRetryPolicy;

Expand All @@ -42,6 +43,7 @@ private ServiceDefinition(
@Nullable Duration idempotencyRetention,
@Nullable Duration journalRetention,
@Nullable Boolean ingressPrivate,
@Nullable Boolean preemptable,
@Nullable Boolean enableLazyState,
@Nullable InvocationRetryPolicy invocationRetryPolicy) {
this.serviceName = serviceName;
Expand All @@ -54,6 +56,7 @@ private ServiceDefinition(
this.idempotencyRetention = idempotencyRetention;
this.journalRetention = journalRetention;
this.ingressPrivate = ingressPrivate;
this.preemptable = preemptable;
this.enableLazyState = enableLazyState;
this.invocationRetryPolicy = invocationRetryPolicy;
}
Expand Down Expand Up @@ -142,6 +145,15 @@ public Map<String, String> getMetadata() {
return ingressPrivate;
}

/**
* @return false if the restate-server must never preempt (eagerly suspend) invocations to this
* service, with all its handlers. Null if unset, meaning preemptable.
* @see Configurator#preemptable(Boolean)
*/
public @Nullable Boolean getPreemptable() {
return preemptable;
}

/**
* @return true if the service, with all its handlers, will use lazy state.
* @see Configurator#enableLazyState(Boolean)
Expand Down Expand Up @@ -170,6 +182,7 @@ public ServiceDefinition withDocumentation(@Nullable String documentation) {
idempotencyRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
}
Expand All @@ -186,6 +199,7 @@ public ServiceDefinition withMetadata(Map<String, String> metadata) {
idempotencyRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
}
Expand All @@ -204,6 +218,7 @@ public ServiceDefinition configure(Consumer<Configurator> configurator) {
idempotencyRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
configurator.accept(configuratorObj);
Expand All @@ -218,6 +233,7 @@ public ServiceDefinition configure(Consumer<Configurator> configurator) {
configuratorObj.idempotencyRetention,
configuratorObj.journalRetention,
configuratorObj.ingressPrivate,
configuratorObj.preemptable,
configuratorObj.enableLazyState,
configuratorObj.invocationRetryPolicy);
}
Expand All @@ -233,6 +249,7 @@ public static final class Configurator {
private @Nullable Duration idempotencyRetention;
private @Nullable Duration journalRetention;
private @Nullable Boolean ingressPrivate;
private @Nullable Boolean preemptable;
private @Nullable Boolean enableLazyState;
private @Nullable InvocationRetryPolicy invocationRetryPolicy;

Expand All @@ -245,6 +262,7 @@ private Configurator(
@Nullable Duration idempotencyRetention,
@Nullable Duration journalRetention,
@Nullable Boolean ingressPrivate,
@Nullable Boolean preemptable,
@Nullable Boolean enableLazyState,
@Nullable InvocationRetryPolicy invocationRetryPolicy) {
this.handlers = new HashMap<>(handlers);
Expand All @@ -255,6 +273,7 @@ private Configurator(
this.idempotencyRetention = idempotencyRetention;
this.journalRetention = journalRetention;
this.ingressPrivate = ingressPrivate;
this.preemptable = preemptable;
this.enableLazyState = enableLazyState;
this.invocationRetryPolicy = invocationRetryPolicy;
}
Expand Down Expand Up @@ -467,6 +486,38 @@ public Configurator ingressPrivate(@Nullable Boolean ingressPrivate) {
return this;
}

/**
* @return configured preemptable.
* @see #preemptable(Boolean)
*/
public @Nullable Boolean preemptable() {
return preemptable;
}

/**
* When set to {@code false}, Restate never preempts invocations to this service, with all its
* handlers. Preemption means that when the restate-server runs out of concurrency capacity, it
* can eagerly suspend an invocation that is waiting on an await point (e.g. a timer, a call
* response, an awakeable), to free up capacity for other invocations. Non-preemptable
* invocations still suspend when the {@link #inactivityTimeout(Duration)} fires.
*
* <p>Use this when suspending and later replaying invocations of this service is undesirable,
* e.g. because resuming them is expensive.
*
* <p>If unset, the restate-server treats the service as preemptable ({@code true}). A handler
* can override this value with {@link HandlerDefinition.Configurator#preemptable(Boolean)}.
*
* <p><b>NOTE:</b> This setting requires a restate-server supporting the service discovery
* protocol V6. When registering against an older restate-server, this setting is ignored, as
* older restate-server versions never preempt invocations.
*
* @return this
*/
public Configurator preemptable(@Nullable Boolean preemptable) {
this.preemptable = preemptable;
return this;
}

/**
* @return configured enable lazy state.
* @see #enableLazyState(Boolean)
Expand Down Expand Up @@ -548,6 +599,7 @@ && getServiceType() == that.getServiceType()
&& Objects.equals(idempotencyRetention, that.idempotencyRetention)
&& Objects.equals(journalRetention, that.journalRetention)
&& Objects.equals(ingressPrivate, that.ingressPrivate)
&& Objects.equals(preemptable, that.preemptable)
&& Objects.equals(enableLazyState, that.enableLazyState)
&& Objects.equals(invocationRetryPolicy, that.invocationRetryPolicy);
}
Expand All @@ -565,6 +617,7 @@ public int hashCode() {
idempotencyRetention,
journalRetention,
ingressPrivate,
preemptable,
enableLazyState,
invocationRetryPolicy);
}
Expand All @@ -584,6 +637,7 @@ public static ServiceDefinition of(
null,
null,
null,
null,
null);
}
}
Loading
Loading