Skip to content

state: native bulk ops and DeleteWithPrefix#4358

Open
JoshVanL wants to merge 5 commits intodapr:mainfrom
JoshVanL:state-native-bulk
Open

state: native bulk ops and DeleteWithPrefix#4358
JoshVanL wants to merge 5 commits intodapr:mainfrom
JoshVanL:state-native-bulk

Conversation

@JoshVanL
Copy link
Copy Markdown
Contributor

@JoshVanL JoshVanL commented Apr 23, 2026

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:

  • 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 expires_at has the same semantics as doSet's
    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.
  • Native BulkDelete with key = ANY($1), same ETag fallback; rejects empty keys.
  • DeleteWithPrefix — single DELETE ... WHERE key LIKE $1 server-side. LIKE metacharacters (%, _, ) in the caller-supplied prefix are escaped so a prefix containing them cannot widen the delete set.
  • Advertises FeatureDeleteWithPrefix.

sqlserver/v2:

  • Native BulkGet builds a dynamic IN clause chunked at 2000 parameters (SQL Server's 2100-parameter ceiling with headroom). [Key] is in the SELECT projection so rows map back to request order without relying on
    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.
  • DeleteWithPrefix — single DELETE ... WHERE [Key] LIKE @Prefix ESCAPE ''. Metacharacters (%, _, [, ], ) are escaped.
  • Advertises FeatureDeleteWithPrefix.

mysql:

  • DeleteWithPrefix — single DELETE ... WHERE id LIKE ?. LIKE metacharacters are escaped; relies on MySQL's default \ LIKE escape char (no explicit ESCAPE clause needed since parameter binding delivers the pattern
    verbatim).
  • Advertises FeatureDeleteWithPrefix.

sqlite:

  • DeleteWithPrefix threaded through the DBAccess interface and exposed on the store. Single DELETE ... WHERE key LIKE ? ESCAPE '' (SQLite has no default LIKE escape char, so the clause is required).
  • Advertises FeatureDeleteWithPrefix.

etcd:

  • Native BulkGet batches N OpGet into a single Txn RPC, respecting the configured maxTxnOps by chunking serially with a fresh per-chunk timeout context.
  • DeleteWithPrefix — single server-side range delete via client.Delete(prefix, WithPrefix()).
  • Advertises FeatureDeleteWithPrefix.

in-memory:

  • DeleteWithPrefix simplified to match the server-side prefix semantics (straight HasPrefix match, no separator filter).

Conformance / certification:

  • tests/conformance/state/state.go — the delete with prefix case now exercises the server-side prefix contract (keys whose names begin with the supplied prefix are all removed, including nested-looking keys
    sharing that prefix; unrelated keys whose names merely contain the prefix as a substring are unaffected).
  • tests/config/state/tests.yml — opts postgresql.v2., mysql., sqlite, etcd.v1/v2, and sqlserver.v2(.docker) into the existing delete-with-prefix conformance operation, so all the new implementations are
    exercised end-to-end against the docker-compose'd backends.

Semantics note:

  • DeleteWithPrefix is defined as a literal-prefix server-side delete on every backend. The caller is expected to pass a fully-qualified prefix ending with DaprSeparator (||) — typically the actor's composite key
    appID||actorType||actorID|| — and every key beginning with that prefix is removed. LIKE metacharacters in the prefix are always escaped so they match literally.

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>
Copilot AI review requested due to automatic review settings April 23, 2026 18:11
@JoshVanL JoshVanL requested review from a team as code owners April 23, 2026 18:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 v2 BulkGet, etcd BulkGet) to cut backend round trips.
  • Add DeleteWithPrefix implementations matching the in-memory “direct children only” semantics and advertise FeatureDeleteWithPrefix across 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.

Comment thread state/sqlserver/v2/sqlserver.go Outdated
Comment thread state/postgresql/v2/postgresql.go
Comment thread state/postgresql/v2/postgresql.go
Comment thread state/postgresql/v2/bulk_test.go Outdated
Signed-off-by: joshvanl <me@joshvanl.dev>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread state/etcd/etcd.go
Comment thread state/sqlserver/v2/sqlserver.go Outdated
Comment thread state/sqlite/sqlite_dbaccess.go Outdated
Comment thread state/mysql/mysql.go
Comment thread state/postgresql/v2/postgresql.go Outdated
Comment thread state/etcd/etcd.go Outdated
Comment thread state/etcd/etcd.go Outdated
Signed-off-by: joshvanl <me@joshvanl.dev>
Signed-off-by: joshvanl <me@joshvanl.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants