Skip to content

Conversation

@kev-cao
Copy link
Contributor

@kev-cao kev-cao commented Dec 24, 2025

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_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';

@kev-cao kev-cao requested review from a team as code owners December 24, 2025 21:58
@kev-cao kev-cao requested review from asg0451, msbutler, nameisbhaskar, shailendra-patel and xinhaoz and removed request for a team December 24, 2025 21:58
@blathers-crl
Copy link

blathers-crl bot commented Dec 24, 2025

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.

@kev-cao kev-cao requested review from a team, DrewKimball, andyyang890 and mw5h and removed request for a team, DrewKimball, andyyang890, asg0451, mw5h, nameisbhaskar, shailendra-patel and xinhaoz December 24, 2025 21:58
@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch 3 times, most recently from d050901 to e7d8452 Compare January 8, 2026 18:03
Copy link
Collaborator

@msbutler msbutler left a 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
Copy link
Collaborator

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

} else {
p.BufferClientNotice(
ctx,
pgnotice.Newf("no specific time range provided, defaulting to 24 hours"),
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

@kev-cao kev-cao Jan 8, 2026

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.

@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch 3 times, most recently from 3f30822 to f04686e Compare January 9, 2026 19:55
@kev-cao
Copy link
Contributor Author

kev-cao commented Jan 9, 2026

Screenshot:
image

@kev-cao kev-cao requested a review from msbutler January 9, 2026 20:01
@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch from f04686e to 24a7600 Compare January 9, 2026 21:43
Copy link
Collaborator

@msbutler msbutler left a 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",
Copy link
Collaborator

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?

Copy link
Contributor Author

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".

)
})

t.Run("AFTER", func(t *testing.T) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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
@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch from 24a7600 to e349e1d Compare January 12, 2026 16:13
@kev-cao
Copy link
Contributor Author

kev-cao commented Jan 12, 2026

New PGNotice:
image

@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch from e349e1d to c8ed42e Compare January 12, 2026 16:34
Copy link
Collaborator

@msbutler msbutler left a 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) {
Copy link
Collaborator

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]
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch 3 times, most recently from f2fd283 to 214f7bd Compare January 13, 2026 18:58
@kev-cao
Copy link
Contributor Author

kev-cao commented Jan 13, 2026

TFTR!

bors r=msbutler

craig bot pushed a commit that referenced this pull request Jan 13, 2026
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>
@craig
Copy link
Contributor

craig bot commented Jan 13, 2026

Build failed (retrying...):

craig bot pushed a commit that referenced this pull request Jan 13, 2026
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>
@craig
Copy link
Contributor

craig bot commented Jan 13, 2026

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';
@kev-cao kev-cao force-pushed the backup/show-backups-with-index branch from 214f7bd to b81ac03 Compare January 14, 2026 03:27
@kev-cao
Copy link
Contributor Author

kev-cao commented Jan 14, 2026

bors r=msbutler

@craig
Copy link
Contributor

craig bot commented Jan 14, 2026

@craig craig bot merged commit 2eeff2e into cockroachdb:master Jan 14, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-AI-Review-Not-Helpful AI reviewer produced result which was incorrect or unhelpful O-No-AI-Review Prevents AI Review from running target-release-26.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backup: add new SHOW BACKUPS index behavior

3 participants