Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions pkg/crosscluster/logical/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ go_test(
"//pkg/ccl/changefeedccl/changefeedbase",
"//pkg/ccl/storageccl",
"//pkg/clusterversion",
"//pkg/crosscluster",
"//pkg/crosscluster/replicationtestutils",
"//pkg/crosscluster/streamclient",
"//pkg/crosscluster/streamclient/randclient",
Expand Down
10 changes: 7 additions & 3 deletions pkg/crosscluster/logical/logical_replication_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/cdcevent"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/crosscluster"
"github.com/cockroachdb/cockroach/pkg/crosscluster/replicationtestutils"
"github.com/cockroachdb/cockroach/pkg/crosscluster/streamclient"
_ "github.com/cockroachdb/cockroach/pkg/crosscluster/streamclient/randclient"
Expand Down Expand Up @@ -895,9 +896,6 @@ func TestRandomTables(t *testing.T) {
tc, s, runnerA, runnerB := setupLogicalTestServer(t, ctx, testClusterBaseClusterArgs, 1)
defer tc.Stopper().Stop(ctx)

// TODO(#148303): Remove this once the crud writer supports tables with array primary keys.
runnerA.Exec(t, "SET CLUSTER SETTING logical_replication.consumer.immediate_mode_writer = 'legacy-kv'")

sqlA := s.SQLConn(t, serverutils.DBName("a"))

var tableName, streamStartStmt string
Expand Down Expand Up @@ -2897,8 +2895,14 @@ func TestGetWriterType(t *testing.T) {

t.Run("validated-mode", func(t *testing.T) {
st := cluster.MakeTestingClusterSettings()

wt, err := getWriterType(ctx, jobspb.LogicalReplicationDetails_Validated, st)
require.NoError(t, err)
require.Equal(t, sqlclustersettings.LDRWriterTypeCRUD, wt)

crosscluster.LogicalReplicationUDFWriterEnabled.Override(ctx, &st.SV, true)
wt, err = getWriterType(ctx, jobspb.LogicalReplicationDetails_Validated, st)
require.NoError(t, err)
require.Equal(t, sqlclustersettings.LDRWriterTypeSQL, wt)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,17 @@ func (lrw *logicalReplicationWriterProcessor) setupBatchHandlers(ctx context.Con
func getWriterType(
ctx context.Context, mode jobspb.LogicalReplicationDetails_ApplyMode, settings *cluster.Settings,
) (sqlclustersettings.LDRWriterType, error) {
// TODO(jeffswenson): delete the kv and legacy sql ldr writers
switch mode {
case jobspb.LogicalReplicationDetails_Immediate:
return sqlclustersettings.LDRWriterType(sqlclustersettings.LDRImmediateModeWriter.Get(&settings.SV)), nil
case jobspb.LogicalReplicationDetails_Validated:
return sqlclustersettings.LDRWriterTypeSQL, nil
if crosscluster.LogicalReplicationUDFWriterEnabled.Get(&settings.SV) {
// If the UDF writer is enabled, fall back to the legacy SQL writer for
// validated mode.
return sqlclustersettings.LDRWriterTypeSQL, nil
}
return sqlclustersettings.LDRWriterTypeCRUD, nil
default:
return "", errors.Newf("unknown logical replication writer type: %s", mode)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/sql/sqlclustersettings/clustersettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ var LDRImmediateModeWriter = settings.RegisterStringSetting(
settings.ApplicationLevel,
"logical_replication.consumer.immediate_mode_writer",
"the writer to use when in immediate mode",
// TODO(jeffswenson): make the crud writer the default
metamorphic.ConstantWithTestChoice("logical_replication.consumer.immediate_mode_writer", string(LDRWriterTypeLegacyKV), string(LDRWriterTypeCRUD), string(LDRWriterTypeSQL)),
metamorphic.ConstantWithTestChoice("logical_replication.consumer.immediate_mode_writer", string(LDRWriterTypeCRUD), string(LDRWriterTypeLegacyKV), string(LDRWriterTypeSQL)),
settings.WithValidateString(func(sv *settings.Values, val string) error {
if val != string(LDRWriterTypeSQL) && val != string(LDRWriterTypeLegacyKV) && val != string(LDRWriterTypeCRUD) {
return errors.Newf("immediate mode writer must be either 'sql', 'legacy-kv', or 'crud', got '%s'", val)
Expand Down