openark / orchestrator

MySQL replication topology management and HA
Apache License 2.0
5.61k stars 926 forks source link

SQL syntax Error #965

Open junli0411 opened 5 years ago

junli0411 commented 5 years ago

Hi, I got the following error in orchestrator.log 2019-08-21 08:22:33 ERROR Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and cluster_name='xxxxxx:3306'' at line 6

the function ReplaceClusterName in file instancedao.go , there's a sql error : , err := db.ExecOrchestrator(` update database_instance set cluster_name=? where and cluster_name=? `, newClusterName, oldClusterName, )

shlomi-noach commented 5 years ago

This was fixed in latest release.

shlomi-noach commented 5 years ago

Or... actually I haven’t released since the fix has been merged! So it’s fixed in master branch. Release to follow.

junli0411 commented 5 years ago

I'm not sure why , but I still get the same error sql in the master branch.

shlomi-noach commented 5 years ago

Please check https://github.com/github/orchestrator/releases/tag/v3.1.2

junli0411 commented 5 years ago

double checked the v3.1.2 , it's still there. ^_^

func ReplaceClusterName(oldClusterName string, newClusterName string) error {
    if oldClusterName == "" {
        return log.Errorf("replaceClusterName: skipping empty oldClusterName")
    }
    if newClusterName == "" {
        return log.Errorf("replaceClusterName: skipping empty newClusterName")
    }
    writeFunc := func() error {
        _, err := db.ExecOrchestrator(\`
            update
                database_instance
            set
                cluster_name=?
            where
                **and** cluster_name=?
                \`, newClusterName, oldClusterName,
        )
        if err != nil {
            return log.Errore(err)
        }
        AuditOperation("replace-cluster-name", nil, fmt.Sprintf("replaxced %s with %s", oldClusterName, newClusterName))
        return nil
    }
    return ExecDBWriteFunc(writeFunc)
} 
junli0411 commented 5 years ago

Maybe it missed some columns before the 'and' or we need to remove the 'and'.

shlomi-noach commented 5 years ago

@junli0411 -- oh, the code is still there -- but no one is using it. Do you still see the error in your log?

BTW, pro tip: use markdown. Use three backtics to format your code. See how I've edited your previous comment.

junli0411 commented 5 years ago

the log is only there when it's doing failover , I will check it when there's a failover next time. I will use markdown next time