Skip to content

Conversation

jycor
Copy link
Contributor

@jycor jycor commented May 11, 2022

Mostly renaming variables and files to better reflect what they are now.
Added flatbuffer files for MySQL DB.

@jycor jycor changed the title Refactor grant_tables to mysql_db [WIP] Refactor grant_tables to mysql_db May 11, 2022
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

Approach seems fine, model for flatbuffer messages looks reasonable to me. Daylon should take a look.

@jycor jycor mentioned this pull request May 17, 2022
@jycor jycor changed the title [WIP] Refactor grant_tables to mysql_db Refactor grant_tables to mysql_db May 17, 2022
Copy link
Contributor

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

Looks good overall! A few things to cleanup and I think it's good to go.

func (g *GrantTables) LoadData(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error {
g.Enabled = true
func (t *MySQLDb) LoadPrivilegeData(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error {
// TODO: this is bad do something else
Copy link
Contributor

Choose a reason for hiding this comment

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

Random comment? Looks like some leftovers, I'd remove if it's no longer relevant.

g.persistFunc = persistFunc
// loadPrivilegeTypes is a helper method that loads privilege types given the length and loading function
// and returns them as a set
func loadPrivilegeTypes(n int, f func(j int) int32) map[sql.PrivilegeType]struct{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

These load... functions should be in their own file.

// persisted.
type PersistCallback func(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error
type PrivilegePersistCallback func(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error
type DataPersistCallback func(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I see what you were trying to get at here. If an integrator only has privileges (such as a database before this change), then they should still call DataPersistCallback, and they'll just pass nils to the other parameters. Having two callbacks that are functionally equivalent will complicate things.

This also extends to the LoadMySQLData call, we should only have this one and not the other one for privileges as well.


table PrivilegeSet {
global_static:[int];
//TODO: global_dynamic:[string];
Copy link
Contributor

Choose a reason for hiding this comment

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

global_dynamic is fine as a string array. They'll all be unique entries so it'll be fine.

password:string;
password_last_changed:int64; // time.Time?
locked:bool;
//attributes:string; // *string?
Copy link
Contributor

Choose a reason for hiding this comment

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

So since FlatBuffers don't support *string directly, you can mimic it with a struct. See https://stackoverflow.com/questions/53803880/flatbuffers-and-null-value

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, password_last_changed is fine as an int64.

Copy link
Contributor

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

Looking at dolthub/dolt#3411 (review), we should make a few changes detailed in that review.

@jycor jycor requested a review from Hydrocharged May 19, 2022 21:19
Copy link
Contributor

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

Looks good! A few small comments and we're good to merge

)

// PersistCallback represents the callback that will be called when the Grant Tables have been updated and need to be
// PrivilegePersistCallback represents the callback that will be called when the Grant Tables have been updated and need to be
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong comment name

// TODO: fill in other tables when they exist
return nil
}

// SetPersistCallback sets the callback to be used when the Grant Tables have been updated and need to be persisted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't update the comment here, still says Grant Tables

persistFunc := g.persistFunc
if persistFunc == nil {
func (t *MySQLDb) Persist(ctx *sql.Context) error {
// TODO: future databases will no longer persist to privilege file, only to mysql.db; should document this
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a Dolt comment, shouldn't be in GMS

return serial.PrivilegeSetEnd(b)
}

func serializeAttributes(b *flatbuffers.Builder, attributes *string) flatbuffers.UOffsetT {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably leave a comment explaining why the zero offset is necessary, and also that this should always be called as a result

@jycor jycor merged commit 54179a8 into main May 24, 2022
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