Skip to content

Gate INSERT activating-merge behind the INSERT_MERGE feature - #415

Merged
em3s merged 1 commit into
mainfrom
feature/add-v3-upsert
Jul 20, 2026
Merged

em3s merged 1 commit into
mainfrom
feature/add-v3-upsert

Conversation

@em3s

@em3s em3s commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

For a database enabled for INSERT_MERGE via actionbase.feature-flags (#432), INSERT becomes an activating merge: an omitted field keeps its existing value, an explicit null clears it, and only INSERT activates the row. This lets multi-source fan-in writers each INSERT the subset of fields they own without clobbering each other.

Without the feature (default), INSERT keeps snapshot semantics — ungated databases are unaffected, pre-gate WAL entries replay identically, and the completeness check keeps its original IllegalArgumentException (surfaced as ERROR).

actionbase:
  feature-flags:
    - feature: INSERT_MERGE
      scope:
        databases: [fanin]

Behavior on an existing row, email = "[email protected]" (nullable):

client input INSERT (default, snapshot) INSERT (INSERT_MERGE) UPDATE
{email:"b"} "b" "b" "b"
{email:null} null (clear) null (clear) null
{} (omitted) null (cleared) "[email protected]" (kept) kept

Changes

  • StateExtensions.transit(insertMerge): INSERT branches between merge and snapshot property handling. The active-row completeness check throws InvalidMutationException only under insertMerge; the default path keeps its original IllegalArgumentException, so ungated behavior is unchanged
  • MutationRequestValidator: with the feature, INSERT relaxes to present-only nullability validation; explicit null on a non-nullable field still fails pre-WAL. Completeness of an activated row is enforced at transit (permanent)
  • MutationService: resolves the feature once per request via the injected FeatureFlags (has(Scope(database), INSERT_MERGE)); a permanently invalid mutation surfaces as a per-item INVALID status (vs transient ERROR), detected across the exception cause chain
  • GraphConfiguration: wires MutationService to Graph.featureFlags
  • Tests: snapshot goldens unchanged from main; merge goldens in new InsertMergeTest; new EdgeMutationInsertMergeTest pins the gated pipeline end to end

How to Test

  • ./gradlew :core:test --tests "*InsertMergeTest" — merge goldens
  • ./gradlew :engine:test --tests "com.kakao.actionbase.v2.engine.v3.MutationServiceSpec" — per-item INVALID and fan-in merge through the RMW pipeline
  • ./gradlew :server:test --tests "com.kakao.actionbase.server.api.graph.v3.EdgeMutationInsertMergeTest" — E2E with the feature enabled via config

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Code (Opus 4.8, 1M context)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 14, 2026
@em3s em3s self-assigned this Jul 15, 2026
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 16, 2026
@em3s
em3s force-pushed the feature/add-v3-upsert branch from 777a840 to ee1a454 Compare July 16, 2026 09:52
@em3s em3s changed the title Add v3 UPSERT operation for multi-source fan-in writes Make INSERT an activating merge for multi-source fan-in writes Jul 16, 2026
@em3s

em3s commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up concern: loss of payload-deterministic (pre-WAL) INSERT validation

Folding merge into INSERT surfaces a trade-off worth flagging — and it is likely the very reason v3 chose a snapshot INSERT in the first place.

Snapshot INSERT made completeness payload-deterministic: since every field is defined from the payload, an incomplete row could be rejected from the payload alone — before touching state, before the WAL. That bought:

  • fail-fast pre-WAL rejection (a bad request never reaches the WAL/CDC stream),
  • bulk all-or-nothing atomicity,
  • the invariant that the stream never carries an INSERT that produces an incomplete active row.

Merge INSERT makes completeness state-dependent (an omitted field may be supplied by a prior write), so it cannot be validated from the payload — only in transit, after the WAL, per item. This cannot be recovered without a pre-WAL state read, which would break the WAL-first durability model. (Explicit-null and type errors are still caught pre-WAL; only the completeness dimension moves downstream.)

The only way to keep both properties is to keep them as two operations: snapshot INSERT (payload-deterministic, atomic validation) plus a separate activating-merge op (fan-in). Folding them into one sacrifices the atomic guarantee.

Open question for reviewers: does any WAL/CDC consumer or bulk client actually rely on "INSERT atomically produces a complete row before the WAL"? If yes, the two-operation design should be reconsidered. If no, this trade-off is acceptable and this PR stands as is.

@em3s
em3s force-pushed the feature/add-v3-upsert branch 2 times, most recently from 60a1d12 to ec907e5 Compare July 16, 2026 10:16
@em3s

em3s commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

INSERT / UPDATE / DELETE: v2 vs v3 (before) vs v3 (this PR), summarized

v2 v3 (before) v3 (this PR)
INSERT — value present update update update
INSERT — explicit null clear clear clear
INSERT — omitted kept (merge) cleared (snapshot) kept (merge) ← now matches v2
INSERT — activation yes yes yes
UPDATE — value present update update update (unchanged)
UPDATE — explicit null clear clear clear (unchanged)
UPDATE — omitted kept kept kept (unchanged)
UPDATE — activation no no no
DELETE — field handling all fields → null all fields → DELETED sentinel unchanged
DELETE — UNSET vs DELETED not distinguished (both null) distinguished unchanged
DELETE — reorder guard gated by insertTs none unchanged
DELETE — activation (deactivates row) yes yes yes

This PR touches exactly one cell — INSERT's "omitted" row, snapshot → merge — which is what brings INSERT back in line with v2. UPDATE and DELETE were already identical between v2 and v3 and stay that way. The two remaining structural v2/v3 differences are both on DELETE and are pre-existing, out of scope for this PR: v3 keeps DELETED distinct from UNSET (v2 doesn't), and v2 has a reorder guard on field clearing that v3 doesn't.

@em3s
em3s force-pushed the feature/add-v3-upsert branch from ec907e5 to 6a05971 Compare July 19, 2026 14:15
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 19, 2026
@em3s em3s changed the title Make INSERT an activating merge for multi-source fan-in writes Gate INSERT activating-merge behind the INSERT_MERGE database feature Jul 19, 2026
@em3s
em3s force-pushed the feature/add-v3-upsert branch from 6a05971 to 024a321 Compare July 19, 2026 14:24
@em3s

em3s commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Rollout note: #430 added the database-level feature gate, and this PR puts the INSERT merge semantics behind it — enabled per database via actionbase.database-level-features. Ungated databases keep the existing snapshot behavior byte-for-byte, so we can validate existing workloads and migrate incrementally instead of flipping the semantics everywhere at once.

@em3s
em3s force-pushed the feature/add-v3-upsert branch 2 times, most recently from 975b153 to d06c262 Compare July 20, 2026 01:31
For a database enabled for INSERT_MERGE via actionbase.feature-flags, INSERT
becomes an activating merge: an omitted field keeps its value, an explicit null
clears it, and only INSERT activates the row. Without the feature, INSERT keeps
snapshot semantics, so ungated databases are unaffected and pre-gate WAL entries
replay identically.

- StateExtensions.transit(insertMerge): INSERT branches between merge and snapshot
- MutationRequestValidator: INSERT_MERGE relaxes INSERT to present-only nullability;
  an activated row left incomplete fails at transit (InvalidMutationException)
- MutationService: resolves the feature once per request via the injected
  FeatureFlags; permanent failures surface as a per-item INVALID status
- Wire MutationService to Graph.featureFlags in GraphConfiguration

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@em3s
em3s force-pushed the feature/add-v3-upsert branch from d06c262 to 815e39c Compare July 20, 2026 01:43
@em3s em3s changed the title Gate INSERT activating-merge behind the INSERT_MERGE database feature Gate INSERT activating-merge behind the INSERT_MERGE feature Jul 20, 2026
@em3s

em3s commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Optimistic

@em3s
em3s merged commit b5daf9f into main Jul 20, 2026
2 checks passed
@em3s
em3s deleted the feature/add-v3-upsert branch July 20, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant