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

Implement new automatic snapshot feature #2403

Draft
wants to merge 5 commits into
base: b6.3
Choose a base branch
from

Conversation

ip1981
Copy link
Member

@ip1981 ip1981 commented Nov 26, 2020

Signed-off-by: Igor Pashev [email protected]


This change is Reviewable

@ip1981 ip1981 requested a review from a team November 26, 2020 13:27
@ip1981 ip1981 self-assigned this Nov 26, 2020
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch from 93fa574 to 3b789d1 Compare November 26, 2020 13:29
#[cfg_attr(feature = "graphql", derive(juniper::GraphQLObject))]
#[derive(serde::Deserialize, serde::Serialize, Eq, Clone, Debug)]
/// Automatic snapshot policy
pub struct SnapshotPolicy {
Copy link
Member Author

@ip1981 ip1981 Nov 26, 2020

Choose a reason for hiding this comment

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

FYI, currently weeks end on Sunday. I think it would be the best to make it part of the policy, even if not visible for users.

@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 3 times, most recently from 14e32b4 to 5d15364 Compare November 30, 2020 15:20
iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
svcs.insert(p, ah);
}

tokio::time::delay_for(tokio::time::Duration::from_secs(6)).await;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any significance to 6 seconds?

Copy link
Member Author

Choose a reason for hiding this comment

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

No :)

start: NaiveDateTime,
datetimes: &[NaiveDateTime],
) -> LinkedList<LinkedList<NaiveDateTime>> {
let mut v: Vec<i64> = datetimes
Copy link
Contributor

Choose a reason for hiding this comment

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

Any benefit to using a linked list? If we could use a Set we wouldn't need to worry about de-duping.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just that the size is not known in advance. And more importantly, the order is important.

iml-wire-types/src/snapshot.rs Outdated Show resolved Hide resolved
iml-wire-types/src/snapshot.rs Outdated Show resolved Hide resolved
iml-wire-types/src/warp_drive.rs Outdated Show resolved Hide resolved
iml-wire-types/src/warp_drive.rs Outdated Show resolved Hide resolved
@nixuser
Copy link

nixuser commented Dec 3, 2020

Web interface shows Failed to load resource: the server responded with a status of 502 () error, when I applied this build.
image

@nixuser
Copy link

nixuser commented Dec 3, 2020

why do we have policy and interval in help output? is it overlapping functionality or it is different?
SUBCOMMANDS:
create Create a snapshot
destroy Destroy the snapshot
help Prints this message or the help of the given subcommand(s)
interval Snapshot intervals operations
list List snapshots
mount Mount a snapshot
policy Automatic snapshot policies operations
retention Snapshot retention rules operations
unmount Unmount a snapshot

@ip1981
Copy link
Member Author

ip1981 commented Dec 4, 2020

why do we have policy and interval in help output? is it overlapping functionality or it is different?
SUBCOMMANDS:
create Create a snapshot
destroy Destroy the snapshot
help Prints this message or the help of the given subcommand(s)
interval Snapshot intervals operations
list List snapshots
mount Mount a snapshot
policy Automatic snapshot policies operations
retention Snapshot retention rules operations
unmount Unmount a snapshot

It's a previous effort which will be replaced by this new feature. You can ignore it for now.

@ip1981
Copy link
Member Author

ip1981 commented Dec 4, 2020

Web interface shows Failed to load resource: the server responded with a status of 502 () error, when I applied this build.
image

It's probably due to database migrations. I guess it needs to be built from scratch after I resolve conflicts in this PR.

@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 7 times, most recently from e3a0efd to 2cff950 Compare December 8, 2020 17:36
@jgrund jgrund force-pushed the ip1981/EX-1835-snapshot-v2-svc branch from 2cff950 to 17df2d3 Compare December 10, 2020 02:24
@jgrund
Copy link
Member

jgrund commented Dec 11, 2020

@ip1981 please rebase, this has conflicts on latest master.

iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
),
))]
/// Creates a new automatic snapshot policy.
async fn create_snapshot_policy(
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this (and any other snapshot related queries / mutations) into a new snapshot module so it's consistent with other areas.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible? Looks like we put everything into the implementation of pub(crate) struct QueryRoot.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, we are doing this in a few other areas already.

ref:

pub(crate) struct StratagemQuery;

sqlx::query!(
r#"
DELETE FROM snapshot_policy
WHERE (filesystem IS NOT DISTINCT FROM $1)
Copy link
Member

Choose a reason for hiding this comment

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

Why not !=

Copy link
Member Author

@ip1981 ip1981 Dec 11, 2020

Choose a reason for hiding this comment

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

Because $1 can be NULL.

Copy link
Member

Choose a reason for hiding this comment

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

Given we can only have one policy per fs, why do we need the id at all?

Why not just make filesystem the only required param as it's already a unique key?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was written first when I thought id would be used in general and fs only for convenience. I will update.

iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
r#"
DELETE FROM snapshot_policy
WHERE (filesystem IS NOT DISTINCT FROM $1)
OR (id IS NOT DISTINCT FROM $2)
Copy link
Member

Choose a reason for hiding this comment

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

Why not !=

Copy link
Member Author

Choose a reason for hiding this comment

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

Likewise, $2 can be NULL. I don't actually use id. So here it's just a PoC.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think we should eliminate the id and just make the fs field required.

Copy link
Member Author

Choose a reason for hiding this comment

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

... and it will be = ;-)

iml-api/src/graphql/mod.rs Outdated Show resolved Hide resolved
@ip1981 ip1981 marked this pull request as ready for review December 23, 2020 13:03
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 2 times, most recently from eac5624 to 3d4c89c Compare December 23, 2020 13:49
@ip1981
Copy link
Member Author

ip1981 commented Dec 23, 2020

Some more things to implement:

* Min snapshots are 2. Max snapshots are 32.

Done at the DB level and in GUI.

* We need to schedule the snapshot cleanup window per-policy
* Each interval scheduled must have the ability to specify when it will first run

Done. First create a new snapshot if possible, then cleanup.

There are a couple of things to improve, but in general it's ready.

I might be hitting a bug in Chrome when an input event is not triggered when selecting a date.
Was with 81, ok with 87.

@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch from 3d4c89c to c59d2bd Compare December 23, 2020 14:11
@ip1981 ip1981 marked this pull request as draft December 23, 2020 17:54
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 3 times, most recently from a128baa to ec17b4f Compare December 24, 2020 14:17
@ip1981 ip1981 marked this pull request as ready for review December 24, 2020 14:31
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch from ec17b4f to b4c5354 Compare December 24, 2020 19:59
@ip1981 ip1981 marked this pull request as draft February 15, 2021 16:03
@ip1981 ip1981 changed the base branch from master to b6.3 February 15, 2021 16:03
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch from b4c5354 to 4298bef Compare February 16, 2021 12:34
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 3 times, most recently from c6fd0fe to 036af3e Compare February 17, 2021 17:49
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 4 times, most recently from 4a1bbdc to 34c0016 Compare February 25, 2021 11:36
@ip1981
Copy link
Member Author

ip1981 commented Feb 25, 2021

I will need #2457 and #2458

@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch 2 times, most recently from 76c9662 to 002be2a Compare February 27, 2021 15:07
@ip1981 ip1981 force-pushed the ip1981/EX-1835-snapshot-v2-svc branch from 002be2a to d3d62fd Compare February 27, 2021 17:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants