Skip to content

Add lock to shared editing and integration with user system - #1427

Merged
Xiao-zhen-Liu merged 64 commits into
masterfrom
xiaozhen-workflow-collab-lock
Feb 15, 2022
Merged

Xiao-zhen-Liu merged 64 commits into
masterfrom
xiaozhen-workflow-collab-lock

Conversation

@Xiao-zhen-Liu

@Xiao-zhen-Liu Xiao-zhen-Liu commented Feb 2, 2022 •

Copy link
Copy Markdown
Contributor

Introduction

This PR does several things, among which the key is introducing workflow-level locking and integration with user system to shared editing.

#1392 only migrates #758 to our current codebase, but did not consider user system so any change from any client will be propagated to all other clients. This PR fixes this and ensures only workflows of the same id can propagate changes to each other.

On top of that, this PR introduces a locking mechanism on the workflow graph so that at the same time only one client can "write" the frontend workflow graph and propagate changes to others.

Other changes include redesigning the collab websocket messages to support more operations, and some refactoring work requested in #1392.

Demos

All the changes require workflowCollabEnabled in the environment to be true, otherwise the frontend behavior will not be affected. (Except one place - when workflowModificationEnabled is set to false, operator dragging will also be disabled, previously we allow it to be enabled. I'm not introducing another level of "disableModification" here for simplicity, but this is doable.)

  • Depending on wId, only sessions on the same workflow will have "collaboration" and "lock", so this images shows two different workflows will both have write access (indicated by a newly added button).

image

  • When more than two sessions are both on the same workflow, only one will have write privilege, all other session will see the button as "Readonly mode - click to request write access".

  • Multiple users who share the same workflow will also work here, and for a workflow that is shared and "readonly" to a user, that user will never have the lock.

  • For now, to simplify matters and prevent deadlock, whichever session that clicks the button will get the lock, shown in the below gif (note the bottom-right window shows a different user that only has read access to this workflow):

Screen Recording 2022-02-15 at 14 09 24-3

  • When a lock-holding session closes, the server will give the lock to other sessions still open, in particular, the first session in server's list.

  • I also implemented a simple function to allow a session to notify other sessions to reload the workflow, and in particular this is what will happen when a particular workflow version is loaded, so reverting version will be propagated.

Limitations

  1. For now only changes on the workflow graph will be propagated (and locked). Other elements, like workflow name, PythonUDF's "edit code" button, "Run" button, etc., cannot be locked or changed with CommandMessages (but PythonUDF's code changes can indeed be propagated), so will not be affected.
  2. Enabling/Disabling operators will not be locked/propagated because somehow this is not included in WorkflowActionService, but directly in WorkflowGraph.
  3. Since undo/redo stacks are local to each session, potential issues might arise.

Code Explanation

Collab WebSocket requests/events

The "lock" is really a value in the server (see wIdLockHolderIdMap). I redesigned WebSocket messages to incorporate functionalities needed in this PR. In particular, I mostly followed WorkflowWebSocket, and below are the Request/Events added here:

  • CommandRequest: sent by lock-holding session to notify the server and propagate commands (changes) to other target sessions.

  • CommandEvent: Server sends commands to target sessions.

  • WIdRequest: similar to WorkflowWebSocket's RegisterWIdRequest, but instead of registering, this just tells the server a sessions wId.

  • TryLockRequest: When a session first opens it sends this request to see if the lock is already held by this session, or if there are no other sessions of the same wId, and can be subsequently granted lock.

  • AcquireLockRequest: When the new button is clicked this request will be sent.

  • LockGrantedEvent: Server grants the lock.

  • ReleaseLockEvent: Server asks lock holder to give up the lock.

  • LockRejectedEvent: Response to TryLockRequest when the sender session is not the lock holder.

  • RestoreVersionRequest and RestoreVersionEvent: similar to CommandRequest and CommandEvent, but instead this pair simply propagates workflow reloading.

  • WorkflowAccessEvent: Server tells client whether the workflow is readonly (shared by others with read access).

Refactoring

For WorkflowActionService,

  1. Types related to command and commandMessage are extracted.
  2. Sending commandMessage is merged into executeAndStoreCommand.

Other potentially confusing codes, especially those related in WorkflowCollabService, are documented.

kerryqliu and others added 30 commits April 10, 2020 16:05
# Conflicts:
#	core/new-gui/src/app/workspace/service/undo-redo/undo-redo.service.ts
@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor Author

@Yicong-Huang @zuozhiw I've made changes according to our discussion. I also did some bug fixes, mostly related to logging in/out. Please have another look.

@zuozhiw zuozhiw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks goooooood 👍

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we have already discussed the logic, left some minor comments.

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes, LGTM.

@Xiao-zhen-Liu
Xiao-zhen-Liu merged commit 07429ca into master Feb 15, 2022
@Xiao-zhen-Liu
Xiao-zhen-Liu deleted the xiaozhen-workflow-collab-lock branch February 15, 2022 19:42
@Yicong-Huang Yicong-Huang added frontend Changes related to the frontend GUI and removed gui labels Jul 6, 2025
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
)

## Introduction
This PR does several things, among which the key is introducing workflow-level locking and integration with user system to shared editing. 

apache#1392 only migrates apache#758 to our current codebase, but did not consider user system so any change from any client will be propagated to all other clients. This PR fixes this and ensures only workflows of the same id can propagate changes to each other. 

On top of that, this PR introduces a locking mechanism on the workflow graph so that at the same time only one client can "write" the frontend workflow graph and propagate changes to others.

Other changes include redesigning the collab websocket messages to support more operations, and some refactoring work requested in apache#1392.

## Demos

All the changes require `workflowCollabEnabled` in the environment to be true, otherwise the frontend behavior will not be affected. (Except one place - when `workflowModificationEnabled` is set to false, operator dragging will also be disabled, previously we allow it to be enabled. I'm not introducing another level of "disableModification" here for simplicity, but this is doable.)

- Depending on `wId`, only sessions on the same workflow will have "collaboration" and "lock", so this images shows two different workflows will both have write access (indicated by a newly added button).

<img width="1392" alt="image" src="https://user-images.githubusercontent.com/36582710/152084809-b9f15e67-cdd2-47c5-80b8-44018cce78bb.png">

- When more than two sessions are both on the same workflow, only one will have write privilege, all other session will see the button as "Readonly mode - click to request write access".

- For now, to simplify matters and prevent deadlock, whichever session that clicks the button will get the lock, shown in the below gif:

![Screen Recording 2022-02-01 at 18 44 22](https://user-images.githubusercontent.com/36582710/152085577-52ccd6a9-9caa-4061-af9f-d82864cc5926.gif)

- When a lock-holding session closes, the server will give the lock to other sessions still open, in particular, the first session in server's list.

- I also implemented a simple function to allow a session to notify other sessions to reload the workflow,  and in particular this is what will happen when a particular workflow version is loaded, so reverting version will be propagated.

## Limitations
1. For now only changes on the workflow graph will be propagated (and locked). Other elements, like workflow name, PythonUDF's "edit code" button, "Run" button, etc., cannot be **locked** or changed with `CommandMessages` (but PythonUDF's code changes can indeed be propagated), so will not be affected.
2. Enabling/Disabling operators will not be locked/propagated because somehow this is not included in `WorkflowActionService`, but directly in `WorkflowGraph`.
3. Since undo/redo stacks are local to each session, potential issues might arise.

## Code Explanation

### Collab WebSocket requests/events

The "lock" is really a value in the server (see `wIdLockHolderIdMap`). I redesigned WebSocket messages to incorporate functionalities needed in this PR. In particular, I mostly followed `WorkflowWebSocket`, and below are the Request/Events added here:

- `CommandRequest`: sent by lock-holding session to notify the server and propagate commands (changes) to other target sessions.
- `CommandEvent`: Server sends commands to target sessions.

- `WIdRequest`: similar to `WorkflowWebSocket`'s `RegisterWIdRequest`, but instead of registering, this just tells the server a sessions `wId`.

- `TryLockRequest`: When a session first opens it sends this request to see if the lock is already held by this session, or if there are no other sessions of the same `wId`, and can be subsequently granted lock.
- `AcquireLockRequest`: When the new button is clicked this request will be sent.
- `LockGrantedEvent`: Server grants the lock.
- `ReleaseLockEvent`: Server asks lock holder to give up the lock.
- `LockRejectedEvent`: Response to `TryLockRequest` when the sender session is not the lock holder.

- `RestoreVersionRequest` and `RestoreVersionEvent`: similar to `CommandRequest` and `CommandEvent`, but instead this pair simply propagates workflow reloading.
- `WorkflowAccessEvent`: Server tells client whether the workflow is readonly (shared by others with read access).

### Refactoring

For `WorkflowActionService`,
1. Types related to `command` and  `commandMessage` are extracted.
2. Sending `commandMessage` is merged into `executeAndStoreCommand`.

Other potentially confusing codes, especially those related in `WorkflowCollabService`, are documented.

Co-authored-by: kerryqliu <[email protected]>
Co-authored-by: zuozhiw <[email protected]>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 26, 2026
### What changes were proposed in this PR?

Remove code that nothing uses, or that repeats work already done, across
16 files in the frontend, Amber, the shared config and observability
modules, and the sbt license helper (**+22/−152 lines**). There is no
behavior change.

- **`PresetService`:** `getOperatorPreset`,
`filterOperatorPresetProperties` and the private `ajvStrip` validator
they share have no caller outside their own spec. Their two spec blocks
go with them.
- **`UserConfigService`:** `set` and `delete` return their request
observables, and no caller reads them; `PresetService`, the only caller,
discards both. They now return `void`, so the `shareReplay` carriers and
the `of` import go. Each call still sends its request once and updates
the local dictionary when the request succeeds.
- **Resource registry:** `ResourceDescriptor.setCover` and its dataset
and model implementations have no caller outside the registry's own
spec. The dataset and model pages set a cover through
`DatasetService.updateDatasetCoverImage` and
`ModelService.updateModelCoverImage` directly. The spec drops its
`setCover` call, the matching assertion and the `updateModelCoverImage`
stub, and the workflow descriptor's comment stops naming the hook.
- **`StorageConfig`:** 12 JDBC, Iceberg and S3 name constants that
nothing reads. Every reader, such as `ComputingUnitManagingResource`,
uses the same names from `EnvironmentalVariable`. The four cleanup and
warehouse constants stay, because `StorageConfigSpec` reads them.
- **Telemetry:** `WorkflowMetricsRecorder.init` calls
`WorkflowMetrics.ensureBound()` right after
`setActiveExecutionsSupplier`, which already calls it.
`OtelInit.initialized` only ever holds an `OpenTelemetrySdk`, so it is
now typed that way, and `resetForTest` loses a fallback arm that could
not run.
- **`CollaborationResource`:** the `heartbeat`, `tryLock`, `acquireLock`
and `restoreVersion` patterns bind names that their bodies never read,
so each becomes `_`.
- **Result table:** nothing reads the `#statsRow` template reference.
- **`search-results.component.spec.ts`:** the card-template host imports
`NgTemplateOutlet`, which its template never uses.
- **`TexeraWebApplication`:** drops a commented-out call to
`discardUncommittedChangesOfAllDatasets` and its TODO. That method no
longer exists.
- **`AddMetaInfLicenseFiles`:** drops `import
com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._`, which
nothing in the helper uses.

| Event | PR / Commit |
| --- | --- |
| Introduced by | `PresetService`: apache#1164 (2022-01-14);
`UserConfigService`: apache#1162 (2021-06-27); resource registry: apache#8299
(2026-08-31); `StorageConfig`: apache#3337 (2025-04-06); telemetry: apache#5375
(2026-10-25) and apache#5376 (2026-10-27); `CollaborationResource`: apache#1427
(2022-02-15); result table: apache#2931 (2024-10-14); search results spec:
apache#6565 (2026-07-20); `TexeraWebApplication`: apache#2391 (2024-02-20),
commented out by apache#2733 (2024-07-15); `AddMetaInfLicenseFiles`: apache#4367
(2026-04-17) |
| Usage removed by | `TexeraWebApplication`: apache#3314 (2025-03-12) deleted
`discardUncommittedChangesOfAllDatasets`. `AddMetaInfLicenseFiles`:
apache#4449 (2026-04-29) removed the last `Universal` reference. Everything
else: unused since introduction. |

As of 2026-11-25:
- No caller has read the `UserConfigService` return values in the more
than 5 years since they were added.
- The two `PresetService` helpers have had no caller outside their spec
for almost 5 years, and the `CollaborationResource` bindings have been
unused for as long.
- The `#statsRow` reference has been unread for over 2 years.
- The commented call has pointed at a deleted method, and the
`StorageConfig` constants have been unread, for over a year and a half
each.
- The Universal import has been unused for almost 7 months.
- The `setCover` hook has had no caller in the almost 3 months it has
existed, and the telemetry duplicates have done nothing in the month
since they were added.

### Any related issues, documentation, discussions?

Closes apache#9695.

### How was this PR tested?

Ran on this branch and on `main` at `d1a0c5e673` (Windows 11; Node 24
with Yarn 4.14.1; JDK 17):

```bash
cd frontend
npx ng test --watch=false --include='**/preset.service.spec.ts' --include='**/user-config.service.spec.ts' --include='**/preset-wrapper.component.spec.ts' --include='**/result-table-frame.component.spec.ts' --include='**/search-results.component.spec.ts' --include='**/resource-registry.service.spec.ts'
npx tsc --noEmit -p src/tsconfig.app.json
npx tsc --noEmit -p src/tsconfig.spec.json
yarn prettier-eslint --list-different $(git diff --name-only --relative origin/main -- src)
yarn eslint $(git diff --name-only --relative origin/main -- src)
cd ..
sbt Config/test Observability/test "WorkflowExecutionService/testOnly org.apache.texera.web.resource.CollaborationResourceSpec org.apache.texera.web.observability.WorkflowMetricsRecorderSpec"
sbt Config/scalafmtCheckAll Observability/scalafmtCheckAll WorkflowExecutionService/scalafmtCheckAll "Config/scalafixAll --check" "Observability/scalafixAll --check" "WorkflowExecutionService/scalafixAll --check"
```

- **Frontend:** the six specs run 199 tests on this branch and 206 on
`main`, all passing. The 7 extra on `main` are the deleted helpers' own
spec cases; every other test keeps its name and outcome. Both
typechecks, prettier-eslint and ESLint pass.
- **Scala:** the `Config` and `Observability` suites and the two Amber
specs run 212 tests, all passing on both sides with the same names and
outcomes. scalafmt and scalafix pass for all three projects.
- Every sbt run compiles the build definition, so
`AddMetaInfLicenseFiles.scala` compiled with and without the import.

To re-check, both commands return no hits on this branch:

```bash
git grep -nwE "getOperatorPreset|filterOperatorPresetProperties|ajvStrip|setCover" -- frontend/src
git grep -nE "ENV_(JDBC|ICEBERG|S3)_" -- common/config/src/main/scala/org/apache/texera/common/config/StorageConfig.scala
```

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants