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

add support for atomic saves #72

Merged
merged 1 commit into from
Jan 22, 2024
Merged

Conversation

loreanvictor
Copy link
Contributor

Previously, diagram saves (for example, during realtime collaboration) would follow these steps:

  1. The server would receive a change from a client
  2. The server would load the diagram
  3. The server would apply the changes
  4. The server would save the diagram and broadcast the changes

Since updating diagrams was not atomic, there was a potential for clashes while updating a diagram: for example an update could be initiated by another client while the server is between steps 2 and 4, resulting in corrupted stored data.

This PR changes the process to enable atomic updates, resolving this issue:

  1. The server will receive a change from a client
  2. The server atomically updates the diagram
  3. The server broadcasts the change

The DiagramStorageService interface is updated with two additional methods:

export interface DiagramStorageService {
  saveDiagram(diagramDTO: DiagramDTO, token: string): Promise<string>;
  getDiagramByLink(token: string): Promise<DiagramDTO | undefined>;

  // 👇 these methods are added via this PR
  patchDiagram(token: string, patch: Operation[]): Promise<void>;
  diagramExists(token: string): Promise<boolean>;
}

DiagramFileStorageService provides implementations for both of these methods. It will rate limit calls to saveDiagram() and calls to patchDiagram() in a single queue, as the purpose of the rate limiting is to avoid frequently modifying the diagram files on the filesystem regardless of the nature of the change (i.e. a patch will be overwritten by a following save and vice-versa, so they should be debounced w.r.t. each other).

@matthiaslehnertum matthiaslehnertum merged commit 4b58523 into main Jan 22, 2024
1 check passed
@matthiaslehnertum matthiaslehnertum deleted the feature/atomic-saves branch January 22, 2024 10:04
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.

2 participants