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

sql: delete db zone config after GC TTL #30666

Merged
merged 1 commit into from Oct 11, 2018

Conversation

Projects
None yet
6 participants
@eriktrinh
Contributor

eriktrinh commented Sep 26, 2018

Previously the database's zone config would be deleted immediately when
a DROP DATABASE is initiated, including if there are tables that the
drop cascades down to. This causes dropped tables waiting for the GC
period without a table zone config to have values from the default
config to be applied (which can cause unnecessary data movement).

This change removes the database's zone config once all the cascaded
table data is completely removed, using the dropped table status in the
job details.

Fixes #24179.

@eriktrinh eriktrinh requested review from dt and vivekmenezes Sep 26, 2018

@eriktrinh eriktrinh requested review from cockroachdb/sql-async-prs as code owners Sep 26, 2018

@cockroach-teamcity

This comment has been minimized.

Show comment
Hide comment
@cockroach-teamcity

cockroach-teamcity Sep 26, 2018

Member

This change is Reviewable

Member

cockroach-teamcity commented Sep 26, 2018

This change is Reviewable

@benesch

🎉 🙇 this is huge!

@eriktrinh eriktrinh requested a review from BramGruneir Oct 9, 2018

@BramGruneir

Reviewed 5 of 5 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/jobs/jobspb/jobs.proto, line 139 at r1 (raw file):

  repeated DroppedTableDetails dropped_tables = 3 [(gogoproto.nullable) = false];
  // The descriptor ID of the dropped database which created this job.
  uint32 drop_database_id = 4 [

please call this dropped_database_id instead of drop_database_id to match the dropped_tables.


pkg/sql/drop_database.go, line 175 at r1 (raw file):

			return err
		}
		details := job.Details().(jobspb.SchemaChangeDetails)

Why do you need to set the details after creating the job? Why not do it within createDropTableJob()?


pkg/sql/drop_database.go, line 180 at r1 (raw file):

			return errors.Wrapf(err, "failed to set drop database ID %d for job", n.dbDesc.ID)
		}
	} else {

Why would the jobID be 0? Could you add a comment about it?

Also, do you test this code path?


pkg/sql/drop_test.go, line 214 at r1 (raw file):

		t.Fatal(err)
	}
	// Database zone config is removed once all table data and zone configs are removed.

Can you add a check to make sure that after the job is created, but before it is finished that the zone config still exists?

@eriktrinh

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/jobs/jobspb/jobs.proto, line 139 at r1 (raw file):

Previously, BramGruneir (Bram Gruneir) wrote…

please call this dropped_database_id instead of drop_database_id to match the dropped_tables.

Done.


pkg/sql/drop_database.go, line 175 at r1 (raw file):

Previously, BramGruneir (Bram Gruneir) wrote…

Why do you need to set the details after creating the job? Why not do it within createDropTableJob()?

Done.


pkg/sql/drop_database.go, line 180 at r1 (raw file):

Previously, BramGruneir (Bram Gruneir) wrote…

Why would the jobID be 0? Could you add a comment about it?

Also, do you test this code path?

Done. Also added a test that goes down this code path when the database is empty


pkg/sql/drop_test.go, line 214 at r1 (raw file):

Previously, BramGruneir (Bram Gruneir) wrote…

Can you add a check to make sure that after the job is created, but before it is finished that the zone config still exists?

TestDropDatabaseDeleteData should already be testing this.

@BramGruneir

:lgtm:

Reviewed 8 of 8 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/sql/drop_database.go, line 133 at r2 (raw file):

	}

	jobID, err := p.createDropTablesJob(ctx, tableDescs, droppedTableDetails, tree.AsStringWithFlags(n.n,

nit: for readability, please you put the tree.AsStringWithFlags(..) all on one line


pkg/sql/drop_test.go, line 242 at r2 (raw file):

}

func TestDropDatabaseEmpty(t *testing.T) {

Please add a comment as to what this test is doing. It helps others that are not familiar with the code. For the other one as well.


pkg/sql/truncate.go, line 89 at r2 (raw file):

	}

	dropJobID, err := p.createDropTablesJob(ctx, stmtTableDescs, droppedTableDetails, tree.AsStringWithFlags(n,

nit: Please keep the asstringwithflags() call all on one line

@BramGruneir

This comment has been minimized.

Show comment
Hide comment
@BramGruneir

BramGruneir Oct 10, 2018

Member

with some small nits

Member

BramGruneir commented Oct 10, 2018

with some small nits

@vivekmenezes

This comment has been minimized.

Show comment
Hide comment
@vivekmenezes

vivekmenezes Oct 10, 2018

Contributor

I'll just take a quick look at this. Hold on

Contributor

vivekmenezes commented Oct 10, 2018

I'll just take a quick look at this. Hold on

@BramGruneir

Reviewed 3 of 3 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@vivekmenezes

Nice work!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/sql/drop_test.go, line 388 at r3 (raw file):

	if _, err := addDefaultZoneConfig(sqlDB, dbDesc.ID); err != nil {
		t.Fatal(err)
	}

perhaps add the zone config before dropping the database above.


pkg/sql/drop_test.go, line 402 at r3 (raw file):

	tests.CheckKeyCount(t, kvDB, table2Span, 6)

	// Database zone config is removed once all table data and zone configs are removed.

this comment is more appropriate for the check done at the end.

sql: delete db zone config after GC TTL
Previously the database's zone config would be deleted immediately when
a DROP DATABASE is initiated, including if there are tables that the
drop cascades down to. This causes dropped tables waiting for the GC
period without a table zone config to have values from the default
config to be applied (which can cause unnecessary data movement).

This change removes the database's zone config once all the cascaded
table data is completely removed, using the dropped table status in the
job details.

Release note: None
@eriktrinh

Thanks for the review!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/sql/drop_test.go, line 242 at r2 (raw file):

Previously, BramGruneir (Bram Gruneir) wrote…

Please add a comment as to what this test is doing. It helps others that are not familiar with the code. For the other one as well.

Done.


pkg/sql/drop_test.go, line 388 at r3 (raw file):

Previously, vivekmenezes wrote…

perhaps add the zone config before dropping the database above.

Done.


pkg/sql/drop_test.go, line 402 at r3 (raw file):

Previously, vivekmenezes wrote…

this comment is more appropriate for the check done at the end.

Done.

@eriktrinh

This comment has been minimized.

Show comment
Hide comment
@eriktrinh

eriktrinh Oct 11, 2018

Contributor

bors r+

Contributor

eriktrinh commented Oct 11, 2018

bors r+

craig bot pushed a commit that referenced this pull request Oct 11, 2018

Merge #30666
30666: sql: delete db zone config after GC TTL r=eriktrinh a=eriktrinh

Previously the database's zone config would be deleted immediately when
a DROP DATABASE is initiated, including if there are tables that the
drop cascades down to. This causes dropped tables waiting for the GC
period without a table zone config to have values from the default
config to be applied (which can cause unnecessary data movement).

This change removes the database's zone config once all the cascaded
table data is completely removed, using the dropped table status in the
job details.

Fixes #24179.

Co-authored-by: Erik Trinh <erik@cockroachlabs.com>
@craig

This comment has been minimized.

Show comment
Hide comment
@craig

craig bot commented Oct 11, 2018

Build succeeded

@craig craig bot merged commit 79dd9f6 into cockroachdb:master Oct 11, 2018

2 of 3 checks passed

GitHub CI (Cockroach) TeamCity build started
Details
bors Build succeeded
Details
license/cla Contributor License Agreement is signed.
Details
@knz

This comment has been minimized.

Show comment
Hide comment
@knz

knz Oct 12, 2018

Member

This needs a backport. @benesch @BramGruneir please assist Erik if this is his first, our window for backporting is only 2 days from today.

Member

knz commented Oct 12, 2018

This needs a backport. @benesch @BramGruneir please assist Erik if this is his first, our window for backporting is only 2 days from today.

@vivekmenezes

This comment has been minimized.

Show comment
Hide comment
@vivekmenezes

vivekmenezes Oct 12, 2018

Contributor
Contributor

vivekmenezes commented Oct 12, 2018

@eriktrinh eriktrinh deleted the eriktrinh:drop-db-cfg branch Oct 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment