-
Notifications
You must be signed in to change notification settings - Fork 4.1k
backup: support SHOW BACKUPS with backup ids #160137
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
backup: support SHOW BACKUPS with backup ids #160137
Conversation
|
Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
d050901 to
e7d8452
Compare
msbutler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nearly there!
| google.protobuf.Duration deadlock_timeout = 33 [(gogoproto.nullable) = false, | ||
| (gogoproto.stdduration) = true]; | ||
|
|
||
| // UseBackupsWithIDs, when true, enables the use of backup IDs in SHOW BACKUP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the commit could use a release note which explains how to use this new UX via the session var
pkg/backup/show.go
Outdated
| } else { | ||
| p.BufferClientNotice( | ||
| ctx, | ||
| pgnotice.Newf("no specific time range provided, defaulting to 24 hours"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to last 24 hours, yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, i was under the impression that if the user specifies just BEFORE X (i.e. no AFTER), we return all backups taken before X; and if they just specify AFTER Y, we return all backups after Y.... no 24 hour time window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the original impetus for having the default 24 hour window was in consideration of BEFORE. If the user wanted to see backups from before some disaster event at time t, I imagine t would be pretty recent. If they were to run SHOW BACKUPS IN <coll> BEFORE <t>, I didn't want them to get every backup in the collection before that time. So hence the 24 hour window.
And since I was already having a 24 hour window for BEFORE, it made sense to do the same with AFTER.
3f30822 to
f04686e
Compare
f04686e to
24a7600
Compare
msbutler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nearly there!
| "//pkg/util", | ||
| "//pkg/util/admission", | ||
| "//pkg/util/admission/admissionpb", | ||
| "//pkg/util/besteffort", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given how cursed negative intervals are, perhaps the example we give docs should be date times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah that's fair. I'm sad about it, it's so human-readable to just say "give me backups from 1 week ago".
pkg/backup/show_test.go
Outdated
| ) | ||
| }) | ||
|
|
||
| t.Run("AFTER", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a test that uses both BEFORE AND AFTER?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so the reason I didn't write one for both is because of the small window of time we have for backups. These backups are all taken within a second of each other and since doing a BEFORE/AFTER rounds to second-precision, the query is unable to really query for a subset of the backups. You'd end up either getting all backups, or just doing a repeat of the tests above, which I didn't find to be a very interesting test. One solution would be to take the backups with sleeps in between, but that'd increase the length of the test.
So for the BEFORE and AFTER test coverage, I figured the unit tests on ListRestorableBackups would get us the coverage we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, we can leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the test — after some more testing, you can sort of get some coverage if you just run the test enough times. So while most cases don't really give you interesting results, it still gives us coverage over time.
This commit updates the `SHOW BACKUP` time filtering syntax from `AFTER/BEFORE` to `NEWER/OLDER THAN`. Epic: CRDB-57536 Informs: cockroachdb#159647 Release note: None
24a7600 to
e349e1d
Compare
e349e1d to
c8ed42e
Compare
msbutler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job! i've come around to your approach. thanks for entertaining my push back.
| pendingEmit = nextEntry | ||
| return nil | ||
| } | ||
| if !nextEntry.end.After(pendingEmit.end) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I find "not after" a bit harder to reason about. To aid the reader, the comment could instead be written in a positive way:
"the pending emit has an end time less than or equal to the new entry. flush pending emit."
| ctx, store, newerThan, olderThan, | ||
| func(index parsedIndex) error { | ||
| if len(filteredIdxs) > 0 { | ||
| last := &filteredIdxs[len(filteredIdxs)-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i think it is more idiomatic and readable to dereference the array element, instead of using pointer shenanigans. i.e. instead just do:
lastIdx := len(filteredIdx)
if filteredIdx[lastIdx].end.Equal(index.end) ....
filteredIdxs[lastIdx] = index
| // in descending order with ties broken by ascending start time, keeping | ||
| // the last one ensures that we keep the non-compacted backup. | ||
| if last.end.Equal(index.end) && last.fullEnd.Equal(index.fullEnd) { | ||
| *last = index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we double check our invariant with a test only assertion? i.e. index.StartTime > last.StartTIme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it might be better to just have a unit test on listIndexesWithinRange. Probably something that needs to be added anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, thinking about it some more, there's already test cases that cover this in ListRestorableBackups. I'll just add the test-only assertion.
f2fd283 to
214f7bd
Compare
|
TFTR! bors r=msbutler |
160137: backup: support SHOW BACKUPS with backup ids r=msbutler a=kev-cao This commit teaches SHOW BACKUPS to display the new UX with backup IDs, along with BEFORE/AFTER filtering. Epic: [CRDB-57536](https://cockroachlabs.atlassian.net/browse/CRDB-57536) Resolves: #159647 Release note (sql change): Users can now set the `use_backups_with_ids` session setting to enable a new `SHOW BACKUPS IN` experience. When enabled, `SHOW BACKUPS IN <collection>` displays all backups in the collection. Results can be filtered by backup end time using `OLDER THAN <timestamp>` or `NEWER THAN <timestamp>` clauses. Example usage: SET use_backups_with_ids = true; SHOW BACKUPS IN '<collection>' OLDER THAN '-1w' NEWER THAN '-2w'; 160922: jobs: skip stale pts check for cancel requested jobs r=dt a=msbutler The stale pts check will load in job progress/payload, even if the job is already in a cancel requested state. If the cancel requested queue is backed up, we have seen a single job processed over a hundred times, which simply leads to more contention. This patch reduces this contention by quickly checking if the job is in a cancel requested state before payload/progress reading. Informs: #158979 Release note: none Co-authored-by: Kevin Cao <39608887+kev-cao@users.noreply.github.com> Co-authored-by: Michael Butler <butler@cockroachlabs.com>
|
Build failed (retrying...): |
160137: backup: support SHOW BACKUPS with backup ids r=msbutler a=kev-cao This commit teaches SHOW BACKUPS to display the new UX with backup IDs, along with BEFORE/AFTER filtering. Epic: [CRDB-57536](https://cockroachlabs.atlassian.net/browse/CRDB-57536) Resolves: #159647 Release note (sql change): Users can now set the `use_backups_with_ids` session setting to enable a new `SHOW BACKUPS IN` experience. When enabled, `SHOW BACKUPS IN <collection>` displays all backups in the collection. Results can be filtered by backup end time using `OLDER THAN <timestamp>` or `NEWER THAN <timestamp>` clauses. Example usage: SET use_backups_with_ids = true; SHOW BACKUPS IN '<collection>' OLDER THAN '-1w' NEWER THAN '-2w'; Co-authored-by: Kevin Cao <39608887+kev-cao@users.noreply.github.com>
|
Build failed: |
This commit teaches SHOW BACKUPS to display the new UX with backup IDs, along with BEFORE/AFTER filtering. Epic: CRDB-57536 Resolves: cockroachdb#159647 Release note (sql change): Users can now set the `use_backups_with_ids` session setting to enable a new `SHOW BACKUPS IN` experience. When enabled, `SHOW BACKUPS IN <collection>` displays all backups in the collection. Results can be filtered by backup end time using `OLDER THAN <timestamp>` or `NEWER THAN <timestamp>` clauses. Example usage: SET use_backups_with_ids = true; SHOW BACKUPS IN '<collection>' OLDER THAN '2026-01-09 12:13:14' NEWER THAN '2026-01-04 15:16:17';
214f7bd to
b81ac03
Compare
|
bors r=msbutler |


This commit teaches SHOW BACKUPS to display the new UX with backup IDs, along with BEFORE/AFTER filtering.
Epic: CRDB-57536
Resolves: #159647
Release note (sql change): Users can now set the
use_backups_with_idssession setting to enable a newSHOW BACKUPS INexperience. When enabled,SHOW BACKUPS IN <collection>displays all backups in the collection. Results can be filtered by backup end time usingOLDER THAN <timestamp>orNEWER THAN <timestamp>clauses.Example usage: