Skip to content
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

Merged
merged 2 commits into from
Jul 14, 2020

Conversation

adityamaru
Copy link
Contributor

@adityamaru adityamaru commented Jul 9, 2020

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:#50899
Fixes:#51166

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.

@adityamaru adityamaru requested review from rohany, miretskiy and a team July 9, 2020 02:16
@adityamaru adityamaru requested a review from a team as a code owner July 9, 2020 02:16
@cockroach-teamcity
Copy link
Member

This change is Reviewable

pkg/cli/dump.go Outdated
if !ok {
return basicMetadata{}, fmt.Errorf("unexpected value: %T", schemaNameI)
}
if strings.Contains(schemaName, sessiondata.PgTempSchemaName) {
Copy link
Contributor

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) {
Copy link
Contributor

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/

@rohany
Copy link
Contributor

rohany commented Jul 9, 2020

This PR should be backported to 20.1

@donbowman
Copy link

I guess if this is accepted #51173 becomes moot.

@donbowman
Copy link

One thing that nags at me
#42425
suggests that the temp tables/sequences/... are deleted when no longer in use (session gone).
but that does not seem to be the case:

select distinct schema_name from crdb_internal.create_statements;

shows 25 items
show sessions reports 1 (the session i have open doing the show sessions)

Are they not supposed to be removed from here?

@adityamaru adityamaru force-pushed the temp-table-dump branch 2 times, most recently from b84834e to da96896 Compare July 9, 2020 14:22
Copy link
Contributor Author

@adityamaru adityamaru left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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.

@adityamaru adityamaru requested a review from rohany July 9, 2020 14:25
@rohany
Copy link
Contributor

rohany commented Jul 9, 2020

suggests that the temp tables/sequences/... are deleted when no longer in use (session gone).

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) {
Copy link
Contributor

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

Copy link
Contributor Author

@adityamaru adityamaru left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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.

@adityamaru
Copy link
Contributor Author

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 t.Name.

@adityamaru
Copy link
Contributor Author

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.

Copy link
Contributor Author

@adityamaru adityamaru left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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)

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.
@adityamaru
Copy link
Contributor Author

@RaduBerinde as discussed offline I changed Local() to UTC() in the statement_diag. I have separated the change out into its own commit.

@RaduBerinde
Copy link
Member

Statement diag commit LGTM, thanks!

@rohany
Copy link
Contributor

rohany commented Jul 13, 2020

@adityamaru do you know why this was segfaulting though with the Local though?

@RaduBerinde
Copy link
Member

Looks like it was racing with Go's timer code which sends Now() through some channel. It's enough for any other package to have set up a timer in an init(). Modifying Local is a pretty broken "API".

@adityamaru
Copy link
Contributor Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 14, 2020

Build succeeded

@craig craig bot merged commit 161d68e into cockroachdb:master Jul 14, 2020
@otan
Copy link
Contributor

otan commented Jul 15, 2020

should we backport this to v20.1?

@knz
Copy link
Contributor

knz commented Jul 15, 2020

it's a bug fix without backward-incompatibility so yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants