wesql / wescale

WeScale is a Modern MySQL proxy that supports read-write-split, read-after-write-consistency, load balancing and OnlineDDL.
Apache License 2.0
196 stars 8 forks source link

fix: fix bugs in schemaChanged #473

Closed newborn22 closed 3 months ago

newborn22 commented 3 months ago

Related Issue(s) & Descriptions

fix #468

The func (me *Engine) schemaChanged(tables map[string]*schema.Table, created, altered, dropped []string) assumes that tables in both the created and altered arrays exist in the tables map, leading to a null pointer error in the subsequent code.

for _, name := range append(created, altered...) {
        t := tables[name]
        if t.Type != schema.Message {
            continue
        }
                ...
}

However, in reality, if tables in the created and altered arrays are not explicitly defined with primary keys, they will not exist in the tables map (as determined in the func (se *Engine) populatePrimaryKeys(ctx context.Context, conn *connpool.DBConn, tables map[string]*Table) error).

Therefore, we should add an additional check to verify whether the tables exist in the tables map.

Checklist