Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Explainer] Ignore batch inner locks and support atomic batch updates #228

Merged
merged 5 commits into from
Mar 20, 2025

Conversation

xyaoinum
Copy link
Collaborator

@xyaoinum xyaoinum commented Mar 4, 2025

This change removes the individual method locks within batchUpdate(), enabling transactional behavior.

Rationale:

  • It strengthens data consistency.
  • It avoids potential deadlocks from finer-grained locking.
  • batchUpdate() is designed for single, transactional use cases. Therefore, a single batch-level lock is sufficient.

xyaoinum added 2 commits March 3, 2025 16:44
…tional Behavior

This change switches to ignore internal locks within the `batchUpdate()` method to enable transactional behavior. All updates within a `batchUpdate()` call will now execute as a single unit of work, ensuring data consistency.

This assumes that methods within `batchUpdate()` are logically related and intended for a single use case, making a single `batchUpdate()`-level lock sufficient.
@xyaoinum
Copy link
Collaborator Author

xyaoinum commented Mar 4, 2025

@jkarlin / @pythagoraskitty: PTAL. Thanks!

@xyaoinum xyaoinum changed the title [Explainer] Ignore batch inner locks [Explainer] Ignore batch inner locks and support atomic batch updates Mar 4, 2025
@xyaoinum xyaoinum requested a review from jkarlin March 4, 2025 18:15
Copy link
Collaborator

@pythagoraskitty pythagoraskitty left a comment

Choose a reason for hiding this comment

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

LGTM w/nit

@Kulikowski
Copy link

LGTM

aarongable pushed a commit to chromium/chromium that referenced this pull request Mar 19, 2025
Introduce SharedStorageDatabase::BatchUpdate() method that executes
multiple methods within a sql::Transaction. If any inner method fails,
all changes are rolled back. This is proposed in:
WICG/shared-storage#228

Note that we still accept parameter type
vector<mojom::SharedStorageModifierMethodWithOptionsPtr>, although we
ignore the `with_lock` option:
- Backward compatibility: The inner method locks are still needed in
  other components during the deprecation phase. Reusing the same type
  simplifies the transition.
- Forward compatibility: This parameter may be repurposed/expanded to
  include other options in the future.

Bug: 404568020
Change-Id: I8489083343379cb75cf2c2a538e3fbd9882feaed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6368281
Reviewed-by: Cammie Smith Barnes <[email protected]>
Commit-Queue: Yao Xiao <[email protected]>
Reviewed-by: Tsuyoshi Horo <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1434805}
@xyaoinum xyaoinum merged commit aa9049d into main Mar 20, 2025
1 check passed
xyaoinum added a commit that referenced this pull request Mar 20, 2025
The spec changes for #228

Specifically:
- Add a "batch update entries in the database" algorithm that provides transactional support. Switch to call this algorithm for batchUpdate().
- `batchUpdate()` now explicitly throws an exception when any inner method specifies the `withLock` option, preventing unintended behavior.
- For headers, if `with_lock` is specified for any inner method, the whole batch will be ignored as well. This integrates seamlessly with the existing "handle a Shared-Storage-Write response" algorithm, which invokes `batchUpdate()` in the end and will trigger the failure as intended.
aarongable pushed a commit to chromium/chromium that referenced this pull request Mar 25, 2025
Introduce SharedStorageManager::BatchUpdate() method that forwards
the request to the underlying SharedStorageDatabase.

Explainer PR: WICG/shared-storage#228

Fuchsia-Binary-Size: Size increase is unavoidable.
Bug: 404568020
Change-Id: I39feb84af04f69d6b0d2c4a7432ad5e46b9d3ed7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6384755
Commit-Queue: Yao Xiao <[email protected]>
Reviewed-by: Cammie Smith Barnes <[email protected]>
Reviewed-by: Tsuyoshi Horo <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1437454}
aarongable pushed a commit to chromium/chromium that referenced this pull request Mar 27, 2025
…hUpdate method

Introduce `network::features::kSharedStorageTransactionalBatchUpdate`
and use the new, transactional SharedStorageManager::BatchUpdate() when
the feature is enabled.

Move some unit tests to a separate "TransactionalBatchUpdateDisabled"
suite, as they wouldn't be applicable for the new implementation (i.e.,
inner methods won't contain locks / we'll reject at mojom traits).

PR: WICG/shared-storage#228
Integration CL preview: https://crrev.com/c/6393777

Bug: 404568020
Change-Id: I00821af78107c6b2ff9913e596837544ec8495d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6395183
Reviewed-by: Cammie Smith Barnes <[email protected]>
Reviewed-by: Adam Rice <[email protected]>
Commit-Queue: Yao Xiao <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1438688}
aarongable pushed a commit to chromium/chromium that referenced this pull request Mar 27, 2025
…ment

Introduce mojom::SharedStorageBatchUpdateMethodsArgument, which is type
mapped to
vector<::network::mojom::SharedStorageModifierMethodWithOptionsPtr>.

Currently, the mojom traits perform a trivial conversion and no
validation. When we later switch to disallow the 'withLock' option for
methods within batchUpdate() (PR: [1]; Integration CL preview: [2]),
the mojom traits will be updated to enforce this restriction.

[1] WICG/shared-storage#228
[2] https://crrev.com/c/6393777

Bug: 404568020
Change-Id: I31f87d3ef1c98d7a24ab9d1b9e4cb27bedf4d32c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394820
Commit-Queue: Yao Xiao <[email protected]>
Reviewed-by: Cammie Smith Barnes <[email protected]>
Reviewed-by: Adam Rice <[email protected]>
Reviewed-by: Ken Buchanan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1438964}
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.

4 participants