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

Manage sync threads failures #49

Merged
merged 3 commits into from
Aug 20, 2022
Merged

Conversation

trueleo
Copy link
Contributor

@trueleo trueleo commented Aug 19, 2022

Fixes #43

Description

This PR makes bunch of changes to ways how local sync and s3 sync threads are managed inside parseable. The goal is to make parseable main thread be aware of unwanted failure inside either of these dedicated sync thread. Additionally we want to have control over life cycle of these threads and have them stop on command, This can be later explored in future if we want to have graceful shutdown an also to guarantee more data consistency in case of failure.

This solution works something like this :-

Sync threads are spawned with pair of one shot channels (named with suffix inbox and outbox) for communication with main thread.

  • inbox is sender type which can be used to stop the respective thread by breaking its scheduler loop.
  • outbox is receiver type which is polled inside the main thread's looped select. So that whenever we receive a message from thread we stop.

scheduler is ran inside loop which runs pending tasks and polls the channel for any message from main thread ( if any then stop the thread )

All of this is wrapped by a catch unwind. So in case of an unwinding because of panic there is a chance to let main thread know and handle accordingly. This is added as a safeguard for now but later we need to verify that local_sync and s3_sync don't have anything that can panic.


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

@nitisht nitisht requested review from de-sh and nitisht August 19, 2022 15:41
server/src/main.rs Outdated Show resolved Hide resolved
@trueleo trueleo marked this pull request as ready for review August 20, 2022 13:42
});

loop {
thread::sleep(Duration::from_millis(50));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay to thread sleep here for small amount of time ?

Copy link
Member

Choose a reason for hiding this comment

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

Why is sleep needed here?

@nitisht nitisht merged commit 44c55e6 into parseablehq:main Aug 20, 2022
@trueleo trueleo deleted the sync_handler branch August 21, 2022 04:51
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.

Mechanism to ensure local data sync thread is always running
2 participants