-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process PG->YDB replication PK Updates correctly
process pk updates in ydb sink correctly commit_hash:33e02c1e00b22df1f4f0a39b150a2ad2712d3c8c
- Loading branch information
1 parent
b2b38c6
commit 6dcb467
Showing
8 changed files
with
194 additions
and
21 deletions.
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
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,88 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
"github.com/doublecloud/transfer/internal/logger" | ||
"github.com/doublecloud/transfer/pkg/abstract" | ||
"github.com/doublecloud/transfer/pkg/abstract/model" | ||
pgcommon "github.com/doublecloud/transfer/pkg/providers/postgres" | ||
"github.com/doublecloud/transfer/pkg/providers/postgres/pgrecipe" | ||
"github.com/doublecloud/transfer/pkg/providers/ydb" | ||
"github.com/doublecloud/transfer/tests/helpers" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
databaseName = "public" | ||
TransferType = abstract.TransferTypeSnapshotAndIncrement | ||
tableName = "test" | ||
) | ||
|
||
func TestSnapshotAndIncrement(t *testing.T) { | ||
Source := pgrecipe.RecipeSource(pgrecipe.WithPrefix("")) | ||
Target := &ydb.YdbDestination{ | ||
Token: model.SecretString(os.Getenv("YDB_TOKEN")), | ||
Database: helpers.GetEnvOfFail(t, "YDB_DATABASE"), | ||
Instance: helpers.GetEnvOfFail(t, "YDB_ENDPOINT"), | ||
} | ||
|
||
_ = os.Setenv("YC", "1") // to not go to vanga | ||
helpers.InitSrcDst(helpers.TransferID, Source, Target, TransferType) // to WithDefaults() & FillDependentFields(): IsHomo, helpers.TransferID, IsUpdateable | ||
|
||
defer func() { | ||
sourcePort, err := helpers.GetPortFromStr(Target.Instance) | ||
require.NoError(t, err) | ||
require.NoError(t, helpers.CheckConnections( | ||
helpers.LabeledPort{Label: "PG source", Port: Source.Port}, | ||
helpers.LabeledPort{Label: "YDB target", Port: sourcePort}, | ||
)) | ||
}() | ||
|
||
connConfig, err := pgcommon.MakeConnConfigFromSrc(logger.Log, Source) | ||
require.NoError(t, err) | ||
conn, err := pgcommon.NewPgConnPool(connConfig, logger.Log) | ||
require.NoError(t, err) | ||
|
||
transfer := helpers.MakeTransfer(helpers.TransferID, Source, Target, TransferType) | ||
worker := helpers.Activate(t, transfer) | ||
defer worker.Close(t) | ||
|
||
time.Sleep(5 * time.Second) // for the worker to start | ||
|
||
_, err = conn.Exec(context.Background(), "INSERT INTO test (i1, t1, i2, t2, vc1) VALUES (3, '3', 3, 'c', '3'), (4, '4', 4, 'd', '4')") | ||
require.NoError(t, err) | ||
_, err = conn.Exec(context.Background(), "UPDATE test SET t2 = 'test_update' WHERE i1 = 1") | ||
require.NoError(t, err) | ||
_, err = conn.Exec(context.Background(), "DELETE FROM test WHERE i1 != 1") | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, helpers.WaitEqualRowsCount(t, databaseName, tableName, helpers.GetSampleableStorageByModel(t, Source), helpers.GetSampleableStorageByModel(t, Target), 60*time.Second)) | ||
require.NoError(t, helpers.WaitDestinationEqualRowsCount(databaseName, tableName, helpers.GetSampleableStorageByModel(t, Target), 60*time.Second, 1)) | ||
|
||
var large string | ||
var small string | ||
err = backoff.Retry(func() error { | ||
return conn.QueryRow(context.Background(), "SELECT t2, vc1 FROM public.test WHERE i1 = 1").Scan(&small, &large) | ||
}, backoff.NewConstantBackOff(time.Second)) | ||
require.NoError(t, err) | ||
|
||
dump := helpers.YDBPullDataFromTable(t, | ||
os.Getenv("YDB_TOKEN"), | ||
helpers.GetEnvOfFail(t, "YDB_DATABASE"), | ||
helpers.GetEnvOfFail(t, "YDB_ENDPOINT"), | ||
"public_test") | ||
require.Equal(t, 1, len(dump)) | ||
|
||
idx := dump[0].ColumnNameIndex("vc1") | ||
require.True(t, idx != -1) | ||
require.Equal(t, large, dump[0].ColumnValues[idx]) | ||
|
||
idx = dump[0].ColumnNameIndex("t2") | ||
require.True(t, idx != -1) | ||
require.Equal(t, small, dump[0].ColumnValues[idx]) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
tests/e2e/pg2ydb/snapshot_replication_pk_update/check_db_test.go
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,64 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/doublecloud/transfer/internal/logger" | ||
"github.com/doublecloud/transfer/pkg/abstract" | ||
"github.com/doublecloud/transfer/pkg/abstract/model" | ||
pgcommon "github.com/doublecloud/transfer/pkg/providers/postgres" | ||
"github.com/doublecloud/transfer/pkg/providers/postgres/pgrecipe" | ||
"github.com/doublecloud/transfer/pkg/providers/ydb" | ||
"github.com/doublecloud/transfer/tests/helpers" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
databaseName = "public" | ||
TransferType = abstract.TransferTypeSnapshotAndIncrement | ||
tableName = "people" | ||
primaryKey = "ID" | ||
) | ||
|
||
func TestSnapshotAndIncrement(t *testing.T) { | ||
Source := pgrecipe.RecipeSource(pgrecipe.WithPrefix("")) | ||
Target := &ydb.YdbDestination{ | ||
Token: model.SecretString(os.Getenv("YDB_TOKEN")), | ||
Database: helpers.GetEnvOfFail(t, "YDB_DATABASE"), | ||
Instance: helpers.GetEnvOfFail(t, "YDB_ENDPOINT"), | ||
} | ||
|
||
_ = os.Setenv("YC", "1") // to not go to vanga | ||
helpers.InitSrcDst(helpers.TransferID, Source, Target, TransferType) // to WithDefaults() & FillDependentFields(): IsHomo, helpers.TransferID, IsUpdateable | ||
|
||
defer func() { | ||
sourcePort, err := helpers.GetPortFromStr(Target.Instance) | ||
require.NoError(t, err) | ||
require.NoError(t, helpers.CheckConnections( | ||
helpers.LabeledPort{Label: "PG source", Port: Source.Port}, | ||
helpers.LabeledPort{Label: "YDB target", Port: sourcePort}, | ||
)) | ||
}() | ||
|
||
transfer := helpers.MakeTransfer( | ||
tableName, | ||
Source, | ||
Target, | ||
TransferType, | ||
) | ||
worker := helpers.Activate(t, transfer) | ||
defer worker.Close(t) | ||
|
||
conn, err := pgcommon.MakeConnPoolFromSrc(Source, logger.Log) | ||
require.NoError(t, err) | ||
_, err = conn.Exec(context.Background(), fmt.Sprintf(`insert into %s values(6, 'You')`, tableName)) | ||
require.NoError(t, err) | ||
_, err = conn.Exec(context.Background(), fmt.Sprintf(`update %s set %s = 7 where %s = 6`, tableName, primaryKey, primaryKey)) | ||
require.NoError(t, err) | ||
require.NoError(t, helpers.WaitEqualRowsCount(t, databaseName, tableName, helpers.GetSampleableStorageByModel(t, Source), helpers.GetSampleableStorageByModel(t, Target), 60*time.Second)) | ||
require.NoError(t, helpers.WaitDestinationEqualRowsCount(databaseName, tableName, helpers.GetSampleableStorageByModel(t, Target), 60*time.Second, 5)) | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/e2e/pg2ydb/snapshot_replication_pk_update/source/dump.sql
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,7 @@ | ||
CREATE TABLE People ( | ||
ID int NOT NULL, | ||
LastName varchar(255), | ||
PRIMARY KEY (ID) | ||
); | ||
|
||
INSERT INTO People VALUES (1, 'Masha'), (2, 'Maxim'), (3, 'Misha'), (4, 'Marina'); |