-
Notifications
You must be signed in to change notification settings - Fork 6
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
Initial version of MySQL frontend connector (based on Vitess) #1212
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module quesma/e2e-data-generator | ||
|
||
go 1.23.2 | ||
go 1.23.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module quesma.com/its | ||
|
||
go 1.23.2 | ||
go 1.23.5 | ||
|
||
require ( | ||
github.com/ClickHouse/clickhouse-go/v2 v2.20.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright Quesma, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
// Experimental alpha processor for MySQL protocol | ||
|
||
package frontend_connectors | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/mysql/replication" | ||
"vitess.io/vitess/go/sqltypes" | ||
"vitess.io/vitess/go/vt/proto/query" | ||
"vitess.io/vitess/go/vt/vtenv" | ||
|
||
"github.com/QuesmaOrg/quesma/quesma/logger" | ||
"github.com/QuesmaOrg/quesma/quesma/quesma/recovery" | ||
quesma_api "github.com/QuesmaOrg/quesma/quesma/v2/core" | ||
) | ||
|
||
type VitessMySqlConnector struct { | ||
processors []quesma_api.Processor | ||
listener *mysql.Listener | ||
endpoint string | ||
} | ||
|
||
func NewVitessMySqlConnector(endpoint string) (*VitessMySqlConnector, error) { | ||
connector := VitessMySqlConnector{ | ||
endpoint: endpoint, | ||
} | ||
|
||
// FIXME: the parameter values below should be tweaked, in particular (list not exhaustive): | ||
// - timeouts, delays are set to time.Second * 0 | ||
// - authServer is set to mysql.NewAuthServerNone(), meaning no authentication | ||
// - TLS is not set up | ||
listener, err := mysql.NewListener("tcp", endpoint, mysql.NewAuthServerNone(), &connector, time.Second*0, time.Second*0, false, false, time.Second*0, time.Second*0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
connector.listener = listener | ||
|
||
return &connector, nil | ||
} | ||
|
||
func (t *VitessMySqlConnector) Listen() error { | ||
go func() { | ||
defer recovery.LogPanic() | ||
t.listener.Accept() | ||
}() | ||
return nil | ||
} | ||
|
||
// Implementation of Vitess mysql.Handler interface: | ||
|
||
type ComQueryMessage struct { | ||
Query string | ||
} | ||
|
||
func (t *VitessMySqlConnector) NewConnection(c *mysql.Conn) { | ||
// TODO: should we do something here? | ||
} | ||
|
||
func (t *VitessMySqlConnector) ConnectionReady(c *mysql.Conn) { | ||
// TODO: should we do something here? | ||
} | ||
|
||
func (t *VitessMySqlConnector) ConnectionClosed(c *mysql.Conn) { | ||
// TODO: should we do something here? | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error { | ||
metadata := make(map[string]interface{}) | ||
var message any = ComQueryMessage{ | ||
Query: query, | ||
} | ||
|
||
dispatcher := quesma_api.Dispatcher{} | ||
_, result := dispatcher.Dispatch(t.processors, metadata, message) | ||
switch result := result.(type) { | ||
case *sqltypes.Result: | ||
err := callback(result) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
case error: | ||
return result | ||
default: | ||
logger.Error().Msgf("Unexpected ComQuery result type received from the processor: %T", result) | ||
return nil | ||
} | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComPrepare(c *mysql.Conn, query string, bindVars map[string]*query.BindVariable) ([]*query.Field, error) { | ||
// TODO implement ComPrepare | ||
logger.Error().Msg("ComPrepare not implemented") | ||
return nil, errors.New("ComPrepare not implemented") | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComStmtExecute(c *mysql.Conn, prepare *mysql.PrepareData, callback func(*sqltypes.Result) error) error { | ||
// TODO implement ComStmtExecute | ||
logger.Error().Msg("ComStmtExecute not implemented") | ||
return errors.New("ComStmtExecute not implemented") | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComRegisterReplica(c *mysql.Conn, replicaHost string, replicaPort uint16, replicaUser string, replicaPassword string) error { | ||
// TODO implement ComRegisterReplica | ||
logger.Error().Msg("ComRegisterReplica not implemented") | ||
return errors.New("ComRegisterReplica not implemented") | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComBinlogDump(c *mysql.Conn, logFile string, binlogPos uint32) error { | ||
// TODO implement ComBinlogDump | ||
logger.Error().Msg("ComBinlogDump not implemented") | ||
return errors.New("ComBinlogDump not implemented") | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComBinlogDumpGTID(c *mysql.Conn, logFile string, logPos uint64, gtidSet replication.GTIDSet) error { | ||
// TODO implement ComBinlogDumpGTID | ||
logger.Error().Msg("ComBinlogDumpGTID not implemented") | ||
return errors.New("ComBinlogDumpGTID not implemented") | ||
} | ||
|
||
func (t *VitessMySqlConnector) WarningCount(c *mysql.Conn) uint16 { | ||
return 0 | ||
} | ||
|
||
func (t *VitessMySqlConnector) ComResetConnection(c *mysql.Conn) { | ||
// TODO implement ComResetConnection | ||
logger.Error().Msg("ComResetConnection not implemented") | ||
} | ||
|
||
func (t *VitessMySqlConnector) Env() *vtenv.Environment { | ||
env, err := vtenv.New(vtenv.Options{ | ||
MySQLServerVersion: "", // will use Vitess's default version | ||
TruncateUILen: 512, | ||
TruncateErrLen: 512, | ||
}) | ||
if err != nil { | ||
logger.Error().Msgf("failed to create environment: %v", err) | ||
return nil | ||
} | ||
|
||
return env | ||
} | ||
|
||
func (t *VitessMySqlConnector) InstanceName() string { | ||
return "VitessMySqlConnector" | ||
} | ||
|
||
func (t *VitessMySqlConnector) GetEndpoint() string { | ||
return t.endpoint | ||
} | ||
|
||
func (t *VitessMySqlConnector) Stop(ctx context.Context) error { | ||
t.listener.Shutdown() | ||
return nil | ||
} | ||
|
||
func (t *VitessMySqlConnector) SetHandlers(processors []quesma_api.Processor) { | ||
t.processors = processors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vitess library requires go 1.23.5