state: native bulk ops and DeleteWithPrefix#4358
Open
Conversation
Improves the workflow and actor state paths by cutting avoidable round
trips on the backends most commonly used with Dapr workflows. Each
change is additive with existing call sites and defaults are unchanged.
postgresql/v2:
* Native BulkSet using a single multi-row UPSERT over UNNEST arrays
(keys, values, TTL seconds). TTL is computed server-side via
now() + make_interval(secs => $n) so the expires_at column has
the same semantics as doSet's single-item path. BulkSet falls
back to the default per-item path when any request carries an
ETag or first-write concurrency option — per-row CAS can't be
expressed as a multi-row upsert without losing atomicity.
* Native BulkDelete with key = ANY($1), same ETag fallback.
* DeleteWithPrefix via `LIKE $1 || '%' AND NOT LIKE $1 || '%||%'`
to match the in-memory store's direct-children semantics.
* Advertises FeatureDeleteWithPrefix.
sqlserver/v2:
* Native BulkGet builds a dynamic IN clause chunked at 2000
parameters (SQL Server's 2100-parameter ceiling with headroom).
The [Key] column is in the SELECT projection so rows map back to
request order without relying on driver row ordering.
* DeleteWithPrefix via `[Key] LIKE @Prefix + N'%' AND NOT LIKE
@Prefix + N'%||%'`.
* Advertises FeatureDeleteWithPrefix.
mysql:
* DeleteWithPrefix via `id LIKE CONCAT(?, '%') AND NOT LIKE
CONCAT(?, '%||%')`.
* Advertises FeatureDeleteWithPrefix.
sqlite:
* DeleteWithPrefix threaded through the DBAccess interface and
exposed on the store.
* Advertises FeatureDeleteWithPrefix.
etcd:
* DeleteWithPrefix uses a range-get + filtered batched delete so
the result matches the in-memory "direct children only" contract
— etcd's server-side WithPrefix() alone would over-delete nested
keys (those containing a further DaprSeparator after the prefix).
Batching respects the configured maxTxnOps.
* Advertises FeatureDeleteWithPrefix.
* Scaffolding for a future native BulkGet is in place (one-Txn,
N-OpGet pattern, chunked by maxTxnOps) but the per-key Op
construction is not yet wired, so BulkGet currently still
delegates to the default fan-out. Tracked for follow-up.
Signed-off-by: joshvanl <me@joshvanl.dev>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds native bulk operations and DeleteWithPrefix support across multiple state backends to reduce round trips in workflow/actor state paths, while keeping existing call sites and defaults unchanged.
Changes:
- Implement native bulk operations (notably Postgres v2
BulkSet/BulkDelete, SQL Server v2BulkGet, etcdBulkGet) to cut backend round trips. - Add
DeleteWithPrefiximplementations matching the in-memory “direct children only” semantics and advertiseFeatureDeleteWithPrefixacross supported backends. - Extend unit/config coverage to exercise feature advertising and empty-input short-circuits.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/config/state/tests.yml | Enables delete-with-prefix in the conformance test matrix for supported components. |
| state/sqlserver/v2/sqlserver.go | Adds BulkGet (chunked IN clause) and DeleteWithPrefix; advertises the feature. |
| state/sqlserver/v2/sqlserver_test.go | Adds tests for feature advertisement and empty BulkGet short-circuit. |
| state/sqlite/sqlite_dbaccess.go | Threads DeleteWithPrefix through DBAccess and implements SQL deletion logic. |
| state/sqlite/sqlite.go | Exposes DeleteWithPrefix on the store and advertises the feature. |
| state/sqlite/sqlite_test.go | Adds routing/feature tests and extends the fake DBAccess. |
| state/postgresql/v2/postgresql.go | Adds native BulkSet, native BulkDelete, DeleteWithPrefix, and advertises the feature. |
| state/postgresql/v2/bulk_test.go | Adds unit tests for short-circuiting and feature advertisement (and a fallback-path test). |
| state/mysql/mysql.go | Adds DeleteWithPrefix and advertises the feature. |
| state/mysql/mysql_test.go | Adds tests validating DeleteWithPrefix query semantics and feature advertisement. |
| state/etcd/etcd.go | Adds native BulkGet, DeleteWithPrefix, and advertises the feature. |
| state/etcd/etcd_test.go | Adds tests for empty BulkGet short-circuit and feature advertisement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: joshvanl <me@joshvanl.dev>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: joshvanl <me@joshvanl.dev>
Signed-off-by: joshvanl <me@joshvanl.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves the workflow and actor state paths by cutting avoidable round trips on the backends most commonly used with Dapr workflows. Each change is additive; existing call sites and defaults are unchanged.
postgresql/v2:
single-item path. Validates each request through state.CheckRequestOptions and rejects empty keys, matching the per-item path. Falls back to the default per-item path when any request carries an ETag or
first-write concurrency option — per-row CAS can't be expressed as a multi-row upsert without losing atomicity.
sqlserver/v2:
driver row ordering. Duplicate keys in the input are supported — the implementation fetches distinct keys over the wire and builds the response by iterating the original request slice, so every occurrence receives
the same data.
mysql:
verbatim).
sqlite:
etcd:
in-memory:
Conformance / certification:
sharing that prefix; unrelated keys whose names merely contain the prefix as a substring are unaffected).
exercised end-to-end against the docker-compose'd backends.
Semantics note:
appID||actorType||actorID|| — and every key beginning with that prefix is removed. LIKE metacharacters in the prefix are always escaped so they match literally.