-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
cli: fix dump to gracefully handle temp tables, views and sequences #51185
Conversation
pkg/cli/dump.go
Outdated
if !ok { | ||
return basicMetadata{}, fmt.Errorf("unexpected value: %T", schemaNameI) | ||
} | ||
if strings.Contains(schemaName, sessiondata.PgTempSchemaName) { |
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.
not contains, but Prefix
@@ -858,3 +860,171 @@ INSERT INTO foo (id) VALUES | |||
}) | |||
} | |||
} | |||
|
|||
func TestDumpTempTables(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.
use the datadriven dump tests instead -- take a look at pkg/cli/testdata/dump/
This PR should be backported to 20.1 |
I guess if this is accepted #51173 becomes moot. |
One thing that nags at me
shows 25 items Are they not supposed to be removed from here? |
b84834e
to
da96896
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @miretskiy and @rohany)
pkg/cli/dump.go, line 550 at r1 (raw file):
Previously, rohany (Rohan Yadav) wrote…
not contains, but
Prefix
good catch, done.
pkg/cli/dump_test.go, line 864 at r1 (raw file):
Previously, rohany (Rohan Yadav) wrote…
use the datadriven dump tests instead -- take a look at
pkg/cli/testdata/dump/
as discussed offline, temp tables do not persist across RunWithCaptureArgs()
invocations. Therefore, using the datadriven infrastructure does not allow us to test our handling of temp object since they get deleted between sql
and dump
runs anyways.
They are cleaned up periodically by a background process, not immediately as the session exits. |
@@ -858,3 +860,171 @@ INSERT INTO foo (id) VALUES | |||
}) | |||
} | |||
} | |||
|
|||
func TestDumpTempTables(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.
I would just comment here why you didn't use the datadriven tests so that we remember
da96896
to
967b818
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @miretskiy and @rohany)
pkg/cli/dump_test.go, line 864 at r2 (raw file):
Previously, rohany (Rohan Yadav) wrote…
I would just comment here why you didn't use the datadriven tests so that we remember
Done.
967b818
to
7b92f4f
Compare
Can't reproduce the CI stress fail locally or on gceworker. I suspect it could be because the PGURL name was a constant rather than the convention which is |
7b92f4f
to
1854c08
Compare
Pushed to get a CI run in. Testing whether the time statement in main_test.go is the cause of stressrace failure on CI. The test is now passing on gceworker. |
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @miretskiy and @rohany)
pkg/cli/main_test.go, line 36 at r3 (raw file):
@RaduBerinde keeping this line is causing the newly added TestDumpTempTables
to fail under make stress
with - https://teamcity.cockroachdb.com/repository/download/Cockroach_UnitTests/2078378:id/testrace/logTestDumpTempTables_dump_db_only_temp068989627/clitest-stderr.4ab17fe2fbed.roach.2020-07-09T20_12_24Z.018111.log
It also causes the other older unit tests to fail when I run them on a gceworker, with the same error as linked above. I tried moving the time statement into init
based on a thread I saw on Slack, but that doesn't work either. Any recommendations on how to remedy this?
@@ -31,10 +30,6 @@ func TestMain(m *testing.M) { | |||
// a version injected. Pretend to be a very up-to-date version. | |||
defer build.TestingOverrideTag("v999.0.0")() | |||
|
|||
// The times for Example_statement_diag are reported in the local timezone. |
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.
Why did you change this?
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 didn't plan to check-in the deletion, I just wanted to see if that was the cause of themake stress
failures for the dump unit tests on CI. I have asked Radu for his input on the same in the comment above - #51185 (review)
1854c08
to
8e97ca2
Compare
Previously, in the case of cli tests we overrode Local to be equal to UTC time so that the output is always the same. This assignment however resulted in data race conditions in several CLI unit tests. Egs: https://teamcity.cockroachdb.com/repository/download/Cockroach_UnitTests/ 2078378:id/testrace/logTestDumpTempTables_dump_db_only_temp068989627/ clitest-stderr.4ab17fe2fbed.roach.2020-07-09T20_12_24Z.018111.log This change ensures all statement diag times are always show in UTC, thereby eliminating the need to override Local. Release note (cli change): statement-diag command will now show all times in UTC.
pg_dump ignores temporary tables, views and sequences. This change makes `cockroach dump` follow the same behavior by skipping descriptors with schema name having `pg_temp` as its prefix, when aggregating the metadata for the tables to be dumped. When no table names are specified in the `cockroach dump` command, we silently ignore all temp objects. If the user explicitly asks for a temp object to be dumped, we error out with an informative message. Fixes:cockroachdb#50899 Release note (bug fix): `cockroach dump` no longer errors out when dumping temporary tables, view or sequences. It either ignores them or throws an informative error if the temp object is explicitly requested to be dumped via the CLI.
8e97ca2
to
d8c41da
Compare
@RaduBerinde as discussed offline I changed Local() to UTC() in the statement_diag. I have separated the change out into its own commit. |
Statement diag commit LGTM, thanks! |
@adityamaru do you know why this was segfaulting though with the |
Looks like it was racing with Go's timer code which sends |
TFTRs! bors r+ |
Build succeeded |
should we backport this to v20.1? |
it's a bug fix without backward-incompatibility so yes |
pg_dump ignores temporary tables, views and sequences. This change
makes
cockroach dump
follow the same behavior by skipping descriptorswith schema name having
pg_temp
as its prefix, when aggregating themetadata for the tables to be dumped.
When no table names are specified in the
cockroach dump
command, wesilently ignore all temp objects. If the user explicitly asks for a
temp object to be dumped, we error out with an informative message.
Fixes:#50899
Fixes:#51166
Release note (bug fix):
cockroach dump
no longer errors out whendumping temporary tables, view or sequences. It either ignores them or
throws an informative error if the temp object is explicitly requested
to be dumped via the CLI.