Skip to content

Initial Workflow Collaboration Implementation - #758

Closed
kerryqliu wants to merge 13 commits into
masterfrom
workflow-collab
Closed

kerryqliu wants to merge 13 commits into
masterfrom
workflow-collab

Conversation

@kerryqliu

Copy link
Copy Markdown
Contributor

collab

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.java

Located 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.ts

Earlier, 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):

const commandMessage1: CommandMessage = {'action': 'deleteOperator', 'parameters': ['123'], 'type': 'execute'};
// Message gets received on different client
this[commandMessage1.action].apply(this, commandMessage1.parameters);

workflow-collab.service.ts

This 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

  • Current implementation relies on different clients starting at the same state and then the two keeping up with each new action. Need ways for clients to be able to "catch up"
  • Related to the above concern, how to recover if connection gets dropped
  • How to deal with multiple clients making edits concurrently

@kerryqliu
kerryqliu requested a review from zuozhiw May 31, 2020 01:00
@Yicong-Huang

Copy link
Copy Markdown
Contributor

@kerryqliu I am very curious about this topic. Can we discuss offline?

@Yicong-Huang
Yicong-Huang marked this pull request as draft April 23, 2021 21:40
@zuozhiw

zuozhiw commented Jun 27, 2021

Copy link
Copy Markdown
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.

@zuozhiw zuozhiw closed this Jun 27, 2021
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:

![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]>
@aglinxinyuan
aglinxinyuan deleted the workflow-collab branch May 25, 2023 20:58
@aglinxinyuan
aglinxinyuan restored the workflow-collab branch May 25, 2023 20:59
@aglinxinyuan
aglinxinyuan deleted the workflow-collab branch May 25, 2023 20:59
@aglinxinyuan
aglinxinyuan restored the workflow-collab branch May 25, 2023 20:59
@aglinxinyuan
aglinxinyuan deleted the workflow-collab branch May 25, 2023 21:00
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]>
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.

3 participants