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

sql: introduce MutableTableDescriptor struct #31794

Merged
merged 1 commit into from
Oct 26, 2018

Conversation

eriktrinh
Copy link

Replace the type alias which made MutableTableDescriptor and
TableDescriptor equivalent types with a struct that embeds
TableDescriptor. This forces any write of a table descriptor for schema
changes to use this struct.

Release note: None

@eriktrinh eriktrinh requested review from vivekmenezes and a team October 24, 2018 17:02
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@eriktrinh eriktrinh changed the title sql: introduce MutableTableDesciptor struct sql: introduce MutableTableDescriptor struct Oct 24, 2018
Copy link
Contributor

@vivekmenezes vivekmenezes left a comment

Choose a reason for hiding this comment

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

I'm very impressed with the work you've put together here by introducing this new type. It's going to help the system get more robust. I think that the second commit is not relevant to this PR and should be removed from the PR. You can send it to me as a separate PR.

Thanks!

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


pkg/sql/create_view.go, line 161 at r1 (raw file):

		if backRefMutable == nil {
			backRefMutable = &sqlbase.MutableTableDescriptor{TableDescriptor: updated.desc}
		}

Why do you need to lookup the uncommitted tables and then create a new MutableTableDescriptor here?


pkg/sql/descriptor.go, line 132 at r1 (raw file):

	} else {
		mutDesc, ok = descriptor.(*sqlbase.MutableTableDescriptor)
	}

The above code seems odd


pkg/sql/physical_schema_accessors.go, line 146 at r1 (raw file):

	}
	return nil, nil, nil
}

Why is the change made here required for this PR?


pkg/sql/resolver.go, line 112 at r1 (raw file):

	}
	return desc.(*MutableTableDescriptor), nil
}

great! Love it!


pkg/sql/resolver.go, line 155 at r1 (raw file):

		return &MutableTableDescriptor{
			TableDescriptor: descI.(*TableDescriptor),
		}, nil

You probably want to add a TODO here to remove this in a subsequent PR.
I actually feel more comfortable using a function NewMutableTableDescriptor() so we can easily track where new mutable table descriptors are created.


pkg/sql/schema_accessors.go, line 51 at r1 (raw file):

	// interface definitions below more intuitive.
	ObjectDescriptor = sqlbase.TableDescriptor
	// MutableTableDescriptor is provided for convenience and to make the

excellent!


pkg/sql/schema_accessors.go, line 84 at r1 (raw file):

	// IsSequence returns true if the descriptor actually describes a
	// Sequence resource rather than a Table.
	IsSequence() bool

It does appear that these ought to be methods on TableDescriptor. So users would do obj.TableDesc().IsTable()

@eriktrinh eriktrinh force-pushed the mut-tbl-desc branch 3 times, most recently from 4b28c64 to 21fbc1e Compare October 25, 2018 21:38
Copy link
Author

@eriktrinh eriktrinh 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


pkg/sql/create_view.go, line 161 at r1 (raw file):

Previously, vivekmenezes wrote…

Why do you need to lookup the uncommitted tables and then create a new MutableTableDescriptor here?

We look up the uncommitted tables because the referenced table descriptors are updated and written, which should happen on the MutableTableDescriptor as well.


pkg/sql/descriptor.go, line 132 at r1 (raw file):

Previously, vivekmenezes wrote…

The above code seems odd

Done. Hopefully this is more readable.


pkg/sql/physical_schema_accessors.go, line 146 at r1 (raw file):

Previously, vivekmenezes wrote…

Why is the change made here required for this PR?

We don't want to assign nil to desc in the old code and return it because the returned ObjectDescriptor will be a non-nil interface value with an underlying nil pointer.


pkg/sql/resolver.go, line 112 at r1 (raw file):

Previously, vivekmenezes wrote…

great! Love it!

Ack.


pkg/sql/resolver.go, line 155 at r1 (raw file):

Previously, vivekmenezes wrote…

You probably want to add a TODO here to remove this in a subsequent PR.
I actually feel more comfortable using a function NewMutableTableDescriptor() so we can easily track where new mutable table descriptors are created.

I think it would be worth it to add a second commit to this PR which does so.


pkg/sql/schema_accessors.go, line 51 at r1 (raw file):

Previously, vivekmenezes wrote…

excellent!

Ack.


pkg/sql/schema_accessors.go, line 84 at r1 (raw file):

Previously, vivekmenezes wrote…

It does appear that these ought to be methods on TableDescriptor. So users would do obj.TableDesc().IsTable()

Done.

Copy link
Contributor

@vivekmenezes vivekmenezes 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


pkg/sql/descriptor.go, line 129 at r2 (raw file):

	var mutDesc *sqlbase.MutableTableDescriptor
	switch d := descriptor.(type) {
	case *sqlbase.MutableTableDescriptor:

how can a descriptor.(type) ever be a MutableTableDescriptor?


pkg/sql/resolver.go, line 155 at r1 (raw file):

Previously, eriktrinh (Erik Trinh) wrote…

I think it would be worth it to add a second commit to this PR which does so.

this looks fine for now

Copy link
Contributor

@vivekmenezes vivekmenezes left a comment

Choose a reason for hiding this comment

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

This looks good. Feel free to incorporate the feedback and merge. Thanks for making it happen!

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

Copy link
Contributor

@vivekmenezes vivekmenezes left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

Replace the type alias which made MutableTableDescriptor and
TableDescriptor equivalent types with a struct that embeds
TableDescriptor. This forces any write of a table descriptor for schema
changes to use this struct.

Release note: None
Copy link
Author

@eriktrinh eriktrinh 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 (and 1 stale)


pkg/sql/descriptor.go, line 129 at r2 (raw file):

Previously, vivekmenezes wrote…

how can a descriptor.(type) ever be a MutableTableDescriptor?

this is called in create_table and create_view where it uses created MutableTableDescriptors which implements DescriptorProto

@eriktrinh
Copy link
Author

bors r+

craig bot pushed a commit that referenced this pull request Oct 26, 2018
31794: sql: introduce MutableTableDescriptor struct r=eriktrinh a=eriktrinh

Replace the type alias which made MutableTableDescriptor and
TableDescriptor equivalent types with a struct that embeds
TableDescriptor. This forces any write of a table descriptor for schema
changes to use this struct.

Release note: None

Co-authored-by: Erik Trinh <[email protected]>
@craig
Copy link
Contributor

craig bot commented Oct 26, 2018

Build succeeded

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.

3 participants