Skip to content
Draft
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ to docs, or any other relevant information.
- `@TemporalOperation` methods can return their output directly for synchronous completion.
Existing methods returning `TemporalOperationResult`, including asynchronous results, remain
supported.
- **Experimental**: Opt-in payload caching for External Storage is now available. To enable it,
call `setPayloadCache` on your client options with a cache (e.g. `InMemoryPayloadCache`) or
`PayloadCache.disabled()` to disable caching.

### Changed
- Updated Cloud API bindings to v0.27.0, including opt-in user group memberships, projects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ActivityClientImpl implements ActivityClient, ActivityClientInternal {
ExternalStorageRunner externalStorage =
options.getExternalStorage() == null
? null
: ExternalStorageRunner.create(options.getExternalStorage(), options.getNamespace());
: ExternalStorageRunner.create(
options.getExternalStorage(), options.getNamespace(), options.getPayloadCache());
DataConverter internalDataConverter =
ClientDataConverterFactory.forClient(options.getDataConverter());
this.stubs = stubs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import io.temporal.common.converter.GlobalDataConverter;
import io.temporal.common.interceptors.ActivityClientInterceptor;
import io.temporal.payload.storage.ExternalStorage;
import io.temporal.payload.storage.PayloadCache;
import java.lang.management.ManagementFactory;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/** Options for {@link ActivityClient} configuration. */
Expand Down Expand Up @@ -50,6 +52,7 @@ public static final class Builder {
private List<ContextPropagator> contextPropagators;
private List<ActivityClientInterceptor> interceptors;
private ExternalStorage externalStorage;
private PayloadCache payloadCache;

private Builder() {}

Expand All @@ -63,6 +66,7 @@ private Builder(ActivityClientOptions options) {
contextPropagators = options.contextPropagators;
interceptors = options.interceptors;
externalStorage = options.externalStorage;
payloadCache = options.payloadCache;
}

/** Set the namespace this client will operate on. */
Expand Down Expand Up @@ -118,6 +122,18 @@ public Builder setExternalStorage(@Nullable ExternalStorage externalStorage) {
return this;
}

/**
* Cache for payloads that external storage uploads and downloads. Used only when external
* storage is set. Calls made through this client report no cache metrics.
*
* <p>Pass {@link PayloadCache#disabled()} to turn caching off explicitly. Defaults to off.
*/
@Experimental
public Builder setPayloadCache(@Nullable PayloadCache payloadCache) {
this.payloadCache = payloadCache;
return this;
}

public ActivityClientOptions build() {
String name = identity == null ? ManagementFactory.getRuntimeMXBean().getName() : identity;
return new ActivityClientOptions(
Expand All @@ -126,7 +142,8 @@ public ActivityClientOptions build() {
name,
contextPropagators == null ? EMPTY_CONTEXT_PROPAGATORS : contextPropagators,
interceptors == null ? EMPTY_INTERCEPTORS : interceptors,
externalStorage);
externalStorage,
payloadCache == null ? PayloadCache.disabled() : payloadCache);
}
}

Expand All @@ -136,20 +153,23 @@ public ActivityClientOptions build() {
private final List<ContextPropagator> contextPropagators;
private final List<ActivityClientInterceptor> interceptors;
private final @Nullable ExternalStorage externalStorage;
private final @Nonnull PayloadCache payloadCache;

private ActivityClientOptions(
String namespace,
DataConverter dataConverter,
String identity,
List<ContextPropagator> contextPropagators,
List<ActivityClientInterceptor> interceptors,
@Nullable ExternalStorage externalStorage) {
@Nullable ExternalStorage externalStorage,
@Nonnull PayloadCache payloadCache) {
this.namespace = namespace;
this.dataConverter = dataConverter;
this.identity = identity;
this.contextPropagators = contextPropagators;
this.interceptors = interceptors;
this.externalStorage = externalStorage;
this.payloadCache = payloadCache;
}

/**
Expand Down Expand Up @@ -204,6 +224,15 @@ public ExternalStorage getExternalStorage() {
return externalStorage;
}

/**
* Cache for external storage payloads, or {@link PayloadCache#disabled()} when caching is off.
*/
@Experimental
@Nonnull
public PayloadCache getPayloadCache() {
return payloadCache;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -214,13 +243,20 @@ public boolean equals(Object o) {
&& Objects.equals(identity, that.identity)
&& Objects.equals(contextPropagators, that.contextPropagators)
&& Objects.equals(interceptors, that.interceptors)
&& Objects.equals(externalStorage, that.externalStorage);
&& Objects.equals(externalStorage, that.externalStorage)
&& Objects.equals(payloadCache, that.payloadCache);
}

@Override
public int hashCode() {
return Objects.hash(
namespace, dataConverter, identity, contextPropagators, interceptors, externalStorage);
namespace,
dataConverter,
identity,
contextPropagators,
interceptors,
externalStorage,
payloadCache);
}

@Override
Expand All @@ -240,6 +276,8 @@ public String toString() {
+ interceptors
+ ", externalStorage="
+ externalStorage
+ ", payloadCache="
+ payloadCache
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public static NexusClient newInstance(WorkflowServiceStubs service, NexusClientO
: ClientDataConverterFactory.forClient(
clientOptions.getDataConverter(),
ExternalStorageRunner.create(
clientOptions.getExternalStorage(), clientOptions.getNamespace())));
clientOptions.getExternalStorage(),
clientOptions.getNamespace(),
clientOptions.getPayloadCache())));
workflowServiceStubs =
new NamespaceInjectWorkflowServiceStubs(workflowServiceStubs, options.getNamespace());
this.workflowServiceStubs = workflowServiceStubs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import io.temporal.common.interceptors.NexusClientInterceptor;
import io.temporal.internal.client.NexusClientResolvedOptions;
import io.temporal.payload.storage.ExternalStorage;
import io.temporal.payload.storage.PayloadCache;
import java.lang.management.ManagementFactory;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -40,18 +42,21 @@ public class NexusClientOptions {
private final DataConverter dataConverter;
private final String identity;
private final @Nullable ExternalStorage externalStorage;
private final @Nonnull PayloadCache payloadCache;

private NexusClientOptions(
String namespace,
List<NexusClientInterceptor> interceptors,
DataConverter dataConverter,
String identity,
@Nullable ExternalStorage externalStorage) {
@Nullable ExternalStorage externalStorage,
@Nonnull PayloadCache payloadCache) {
this.namespace = namespace;
this.interceptors = interceptors;
this.dataConverter = dataConverter;
this.identity = identity;
this.externalStorage = externalStorage;
this.payloadCache = payloadCache;
}

/** Get the namespace this client will operate on. */
Expand All @@ -78,6 +83,14 @@ public ExternalStorage getExternalStorage() {
return externalStorage;
}

/**
* Cache for external storage payloads, or {@link PayloadCache#disabled()} when caching is off.
*/
@Nonnull
public PayloadCache getPayloadCache() {
return payloadCache;
}

/**
* Human-readable identity of this client. Stamped onto outgoing write requests (start, cancel,
* terminate) so server-side history and audit trails can attribute the action to a caller.
Expand Down Expand Up @@ -128,6 +141,7 @@ public static class Builder {
private DataConverter dataConverter = GlobalDataConverter.get();
private String identity;
private ExternalStorage externalStorage;
private PayloadCache payloadCache;

private Builder() {}

Expand All @@ -140,6 +154,7 @@ private Builder(NexusClientOptions options) {
dataConverter = options.dataConverter;
identity = options.identity;
externalStorage = options.externalStorage;
payloadCache = options.payloadCache;
}

/** Set the namespace this client will operate on. */
Expand Down Expand Up @@ -188,6 +203,17 @@ public NexusClientOptions.Builder setExternalStorage(
return this;
}

/**
* Cache for payloads that external storage uploads and downloads. Used only when external
* storage is set. Calls made through this client report no cache metrics.
*
* <p>Pass {@link PayloadCache#disabled()} to turn caching off explicitly. Defaults to off.
*/
public NexusClientOptions.Builder setPayloadCache(@Nullable PayloadCache payloadCache) {
this.payloadCache = payloadCache;
return this;
}

public NexusClientOptions build() {
String resolvedIdentity =
identity == null ? ManagementFactory.getRuntimeMXBean().getName() : identity;
Expand All @@ -196,7 +222,8 @@ public NexusClientOptions build() {
interceptors,
dataConverter,
resolvedIdentity,
externalStorage);
externalStorage,
payloadCache == null ? PayloadCache.disabled() : payloadCache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public static WorkflowClient newInstance(
ExternalStorageRunner externalStorageRunner =
externalStorage == null
? null
: ExternalStorageRunner.create(externalStorage, options.getNamespace());
: ExternalStorageRunner.create(
externalStorage, options.getNamespace(), options.getPayloadCache());
this.externalStorageRunner = externalStorageRunner;
this.genericClient = new GenericWorkflowClientImpl(workflowServiceStubs, metricsScope);
this.interceptors = options.getInterceptors();
Expand Down
Loading
Loading