Repository navigation
Conversation
Contributor
|
@kerryqliu I am very curious about this topic. Can we discuss offline? |
Yicong-Huang
marked this pull request as draft
April 23, 2021 21:40
Contributor
|
PR closed for now, we'll resume implementing collabrative features in the future. Thanks for the work and the knowledge we gained from this proof of concept implementation is valueable. |
Xiao-zhen-Liu
added a commit
that referenced
this pull request
Feb 15, 2022
## 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). <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:  - 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]>
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:  - 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]>
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.
This pull request includes an initial implementation for being able to send commands between multiple clients. This is currently an experimental version that only allows communication between different clients on one machine. The gif above gives a brief demonstration behind how it looks, with each individual command being sent as soon as it's performed. Sending commands ensures that the information sent between clients after each action remains the same despite how cluttered the workflow gets, but it does introduce some concerns that need to be addressed in the future.
For now, here's a brief explanation for the main files involved with this feature.
CollaborationResource.javaLocated at web/src/main/java/edu/uci/ics/texera/web/resource/CollaborationResource.java. This is the websocket used to communicate between the different clients, with a command being sent to all other clients currently connected to the websocket.
workflow-action.service.tsEarlier, we had added the Command interface for undo/redo. Unfortunately, that interface kept track of each action as a set of functions, which we can't send between clients. We instead implemented the new CommandMessage interface which keeps track of an action's name, the parameters for that action, and the type for that action(e.g. normal action, undo, or redo). All of these things are able to be communicated between clients. Now, in addition to just performing the action on that client, we'll construct a command message after performing each action that we can send. An example looks like the following(this refers to WorkflowActionService):
workflow-collab.service.tsThis service is where the websocket connection gets established with the resource described above. It'll listen to the websocket and push new messages into a stream, notifying other services to perform the actions.
Minor changes were made in a handful of other files to make sure they interacted properly with the new features. Additionally, I added a parameter to currently disable the feature since it's experimental, but it can be toggled on manually.
New packages installed
Automerge
Yjs
I installed and experimented with these packages during earlier attempts on implementing collaboration. Both of these are implementations of CRDTs, a data structure that eventually leads states on different devices to converge. I did some experimentation with them and while I don't think they're necessary for this current implementation, the ideas behind them could be useful later and worth looking into deeper.
Some Concerns