Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

snapshots #113

Merged
merged 30 commits into from
Apr 1, 2021
Merged

snapshots #113

merged 30 commits into from
Apr 1, 2021

Conversation

MarinPostma
Copy link
Contributor

@MarinPostma MarinPostma commented Mar 20, 2021

This pr adds support for snapshoting.

The snapshoting process for an index requires that no other update is processing at the same time. A mutex lock has been added to prevent a snapshot from occuring at the same time as an update, while still premitting updates to be pushed.

The list of the indexes to snapshot is first retrieved from the UuidResolver which also performs its snapshot.

This list is passed to the update store, which attempts to acquire a lock on the update store while it snaphots itself and it's associated index store.

This means that a snapshot can only be completed once all indexes have finished their ongoing update.

This pr also adds refactoring of the code to allow unit testing and mocking, and unit test the snapshot creation.

@MarinPostma MarinPostma marked this pull request as ready for review March 24, 2021 11:43
irevoire
irevoire previously approved these changes Mar 24, 2021
Comment on lines +62 to +96
async fn get_all_updates_status(&self, uuid: Uuid) -> Result<Vec<UpdateStatus>> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::ListUpdates { uuid, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}

async fn update_status(&self, uuid: Uuid, id: u64) -> Result<UpdateStatus> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::GetUpdate { uuid, id, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}

async fn delete(&self, uuid: Uuid) -> Result<()> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::Delete { uuid, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}

async fn create(&self, uuid: Uuid) -> Result<()> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::Create { uuid, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}

async fn snapshot(&self, uuid: Uuid, path: PathBuf) -> Result<()> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::Snapshot { uuid, path, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be interesting to write a macro that generates all these functions? (for another PR though, this one is already complex enough 😂 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I thought about that a bit, it's not straightforward, but could be a fun little project :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@irevoire lol I tried to do so and it looks pretty strange and I'm not sure it became any better 😄
3e875b0

It works, however!

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

I tried cargo run --release --schedule-snapshot=true

and I get in the logs: Snashot scheduled every 86400s

But the snapshot was not created. It should be created when launching:

Capture d’écran 2021-03-24 à 20 09 45


pub async fn run(self) {
info!(
"Snashot scheduled every {}s.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Snashot scheduled every {}s.",
"Snapshot scheduled every {}s.",

@curquiza
Copy link
Member

curquiza commented Mar 24, 2021

Also, I tried: cargo run --release -- --schedule-snapshot=true --snapshot-interval-sec 10 and after 10sec I got:

Capture d’écran 2021-03-24 à 20 11 52

By default, a snapshot should be created in the snapshots directory

Then I created the expected snapshots folder and I re-launched and I got:

Capture d’écran 2021-03-24 à 20 14 24

I re-tried by using: cargo run --release -- --schedule-snapshot=true --snapshot-interval-sec 10 --snapshot-dir snapshots/ but still the second error Is a directory

And I've never got any snapshot in the snapshots folder, but I get .tmp files:
Capture d’écran 2021-03-24 à 20 18 47

@MarinPostma
Copy link
Contributor Author

Interesting, thanks I'll look into this !

curquiza
curquiza previously approved these changes Mar 28, 2021
@MarinPostma
Copy link
Contributor Author

bors merge

bors bot added a commit that referenced this pull request Mar 29, 2021
113: snapshots r=MarinPostma a=MarinPostma

 This pr adds support for snapshoting.

The snapshoting process for an index requires that no other update is processing at the same time. A mutex lock has been added to prevent a snapshot from occuring at the same time as an update, while still premitting updates to be pushed.

The list of the indexes to snapshot is first retrieved from the `UuidResolver` which also performs its snapshot.

This list is passed to the update store, which attempts to acquire a lock on the update store while it snaphots itself and it's associated index store.

 This means that a snapshot can only be completed once all indexes have finished their ongoing update.

This pr also adds refactoring of the code to allow unit testing and mocking, and unit test the snapshot creation.

Co-authored-by: mpostma <postma.marin@protonmail.com>
Co-authored-by: tamo <irevoire@protonmail.ch>
Co-authored-by: marin <postma.marin@protonmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 29, 2021

Build failed:

@curquiza
Copy link
Member

😭 Bors hates us

@MarinPostma
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Mar 29, 2021
@bors
Copy link
Contributor

bors bot commented Mar 29, 2021

try

Build succeeded:

@MarinPostma
Copy link
Contributor Author

bors merge

bors bot added a commit that referenced this pull request Mar 30, 2021
113: snapshots r=MarinPostma a=MarinPostma

 This pr adds support for snapshoting.

The snapshoting process for an index requires that no other update is processing at the same time. A mutex lock has been added to prevent a snapshot from occuring at the same time as an update, while still premitting updates to be pushed.

The list of the indexes to snapshot is first retrieved from the `UuidResolver` which also performs its snapshot.

This list is passed to the update store, which attempts to acquire a lock on the update store while it snaphots itself and it's associated index store.

 This means that a snapshot can only be completed once all indexes have finished their ongoing update.

This pr also adds refactoring of the code to allow unit testing and mocking, and unit test the snapshot creation.

Co-authored-by: mpostma <postma.marin@protonmail.com>
Co-authored-by: tamo <irevoire@protonmail.ch>
Co-authored-by: marin <postma.marin@protonmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 30, 2021

Build failed:

@curquiza
Copy link
Member

@MarinPostma can we remove the failing test since you created https://github.com/meilisearch/transplant/issues/130?

@MarinPostma
Copy link
Contributor Author

Yes this is on my to-do, you want to make a release?

@curquiza
Copy link
Member

I would to do an alpha release before the end of the week if possible 🙂

curquiza
curquiza previously approved these changes Mar 31, 2021
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

perfecto !!

@MarinPostma
Copy link
Contributor Author

bors merge

bors bot added a commit that referenced this pull request Mar 31, 2021
113: snapshots r=MarinPostma a=MarinPostma

 This pr adds support for snapshoting.

The snapshoting process for an index requires that no other update is processing at the same time. A mutex lock has been added to prevent a snapshot from occuring at the same time as an update, while still premitting updates to be pushed.

The list of the indexes to snapshot is first retrieved from the `UuidResolver` which also performs its snapshot.

This list is passed to the update store, which attempts to acquire a lock on the update store while it snaphots itself and it's associated index store.

 This means that a snapshot can only be completed once all indexes have finished their ongoing update.

This pr also adds refactoring of the code to allow unit testing and mocking, and unit test the snapshot creation.

Co-authored-by: mpostma <postma.marin@protonmail.com>
Co-authored-by: tamo <irevoire@protonmail.ch>
Co-authored-by: marin <postma.marin@protonmail.com>
Co-authored-by: Marin Postma <postma.marin@protonmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 31, 2021

This PR was included in a batch that successfully built, but then failed to merge into main (it was a non-fast-forward update). It will be automatically retried.

@bors
Copy link
Contributor

bors bot commented Mar 31, 2021

Merge conflict.

@MarinPostma
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 1, 2021

Build succeeded:

@bors bors bot merged commit 89e05fc into main Apr 1, 2021
@bors bors bot deleted the snapshots branch April 1, 2021 13:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants