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

Add UseRdonly option to the airbyte connector #112

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/airbyte-source/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"description": "Comma separated list of shards you'd like to sync, by default all shards are synced.",
"title": "Shards",
"type": "string",
"order": 5
"order": 6
},
"database": {
"description": "The PlanetScale database name.",
Expand Down Expand Up @@ -52,12 +52,19 @@
"default": false,
"order": 4
},
"use_rdonly": {
"description": "Use an rdonly replica to pull data from",
Anders-PlanetScale marked this conversation as resolved.
Show resolved Hide resolved
"title": "Use rdonly?",
"type": "boolean",
"default": false,
"order": 5
},
"starting_gtids": {
"type": "string",
"title": "Starting GTIDs",
"default": "",
"description": "A JSON string containing start GTIDs for every { keyspace: { shard: starting_gtid } }",
"order": 6
"order": 7
},
"options": {
"type": "object",
Expand Down
5 changes: 4 additions & 1 deletion cmd/internal/planetscale_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type PlanetScaleSource struct {
Password string `json:"password"`
Shards string `json:"shards"`
UseReplica bool `json:"use_replica"`
UseRdonly bool `json:"use_rdonly"`
StartingGtids string `json:"starting_gtids"`
Options CustomSourceOptions `json:"options"`
}
Expand All @@ -36,7 +37,9 @@ func (psc PlanetScaleSource) DSN() string {
config.Passwd = psc.Password

tt := psdbconnect.TabletType_primary
if psc.UseReplica {
if psc.UseRdonly {
tt = psdbconnect.TabletType_batch
} else if psc.UseReplica {
tt = psdbconnect.TabletType_replica
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/internal/planetscale_edge_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func (p PlanetScaleEdgeDatabase) Read(ctx context.Context, w io.Writer, ps Plane
)

tabletType := psdbconnect.TabletType_primary
if ps.UseReplica {
if ps.UseRdonly {
tabletType = psdbconnect.TabletType_batch
Copy link
Contributor

Choose a reason for hiding this comment

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

Confirmed that this will be mapped to topodatapb.TabletType_RDONLY by our edge gateway.

} else if ps.UseReplica {
tabletType = psdbconnect.TabletType_replica
}

Expand Down
49 changes: 49 additions & 0 deletions cmd/internal/planetscale_edge_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,55 @@ func TestRead_CanPickReplicaForShardedKeyspaces(t *testing.T) {
assert.False(t, tma.GetVitessTabletsFnInvoked)
}

func TestRead_CanPickRdonlyForShardedKeyspaces(t *testing.T) {
tma := getTestMysqlAccess()
b := bytes.NewBufferString("")
ped := PlanetScaleEdgeDatabase{
Logger: NewLogger(b),
Mysql: tma,
}
tc := &psdbconnect.TableCursor{
Shard: "40-80",
Position: "THIS_IS_A_SHARD_GTID",
Keyspace: "connect-test",
}

syncClient := &connectSyncClientMock{
syncResponses: []*psdbconnect.SyncResponse{
{Cursor: tc},
},
}

cc := clientConnectionMock{
syncFn: func(ctx context.Context, in *psdbconnect.SyncRequest, opts ...grpc.CallOption) (psdbconnect.Connect_SyncClient, error) {
assert.Equal(t, psdbconnect.TabletType_batch, in.TabletType)
assert.Contains(t, in.Cells, "planetscale_operator_default")
return syncClient, nil
},
}
ped.clientFn = func(ctx context.Context, ps PlanetScaleSource) (psdbconnect.ConnectClient, error) {
return &cc, nil
}
ps := PlanetScaleSource{
Database: "connect-test",
UseRdonly: true,
}
cs := ConfiguredStream{
Stream: Stream{
Name: "customers",
Namespace: "connect-test",
},
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
assert.False(t, tma.PingContextFnInvoked)
assert.False(t, tma.GetVitessTabletsFnInvoked)
}

func TestDiscover_CanPickRightAirbyteType(t *testing.T) {
var tests = []struct {
MysqlType string
Expand Down
Loading