@@ -37,13 +37,13 @@ import (
3737 "github.com/cockroachdb/cockroach/pkg/sql/rowenc"
3838 "github.com/cockroachdb/cockroach/pkg/sql/rowexec"
3939 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
40+ "github.com/cockroachdb/cockroach/pkg/sql/sqlclustersettings"
4041 "github.com/cockroachdb/cockroach/pkg/sql/stats"
4142 "github.com/cockroachdb/cockroach/pkg/sql/types"
4243 "github.com/cockroachdb/cockroach/pkg/util/bulk"
4344 "github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
4445 "github.com/cockroachdb/cockroach/pkg/util/log"
4546 "github.com/cockroachdb/cockroach/pkg/util/log/logcrash"
46- "github.com/cockroachdb/cockroach/pkg/util/metamorphic"
4747 "github.com/cockroachdb/cockroach/pkg/util/protoutil"
4848 "github.com/cockroachdb/cockroach/pkg/util/span"
4949 "github.com/cockroachdb/cockroach/pkg/util/timeutil"
@@ -95,34 +95,6 @@ var maxChunkSize = settings.RegisterIntSetting(
9595 settings .NonNegativeInt ,
9696)
9797
98- type writerType string
99-
100- const (
101- // writerTypeSQL uses the SQL layer to write replicated rows.
102- writerTypeSQL writerType = "sql"
103- // writerTypeLegacyKV uses the legacy KV layer to write rows. The KV writer
104- // is deprecated because it does not support the full set of features of the
105- // SQL writer.
106- writerTypeLegacyKV writerType = "legacy-kv"
107-
108- // writerTypeCRUD is the shiny new sql writer that uses explicit reads,
109- // inserts, updates, and deletes instead of upserts.
110- writerTypeCRUD writerType = "crud"
111- )
112-
113- var immediateModeWriter = settings .RegisterStringSetting (
114- settings .ApplicationLevel ,
115- "logical_replication.consumer.immediate_mode_writer" ,
116- "the writer to use when in immediate mode" ,
117- metamorphic .ConstantWithTestChoice ("logical_replication.consumer.immediate_mode_writer" , string (writerTypeSQL ), string (writerTypeLegacyKV ), string (writerTypeCRUD )),
118- settings .WithValidateString (func (sv * settings.Values , val string ) error {
119- if val != string (writerTypeSQL ) && val != string (writerTypeLegacyKV ) && val != string (writerTypeCRUD ) {
120- return errors .Newf ("immediate mode writer must be either 'sql', 'legacy-kv', or 'crud', got '%s'" , val )
121- }
122- return nil
123- }),
124- )
125-
12698// logicalReplicationWriterProcessor consumes a cross-cluster replication stream
12799// by decoding kvs in it to logical changes and applying them by executing DMLs.
128100type logicalReplicationWriterProcessor struct {
@@ -719,7 +691,7 @@ func (lrw *logicalReplicationWriterProcessor) setupBatchHandlers(ctx context.Con
719691 b .Close (lrw .Ctx ())
720692 }
721693
722- writer := writerType (lrw .spec .WriterType )
694+ writer := sqlclustersettings . LDRWriterType (lrw .spec .WriterType )
723695 if writer == "" && ! lrw .FlowCtx .Cfg .Settings .Version .IsActive (ctx , clusterversion .V25_2 ) {
724696 var err error
725697 writer , err = getWriterType (
@@ -738,7 +710,7 @@ func (lrw *logicalReplicationWriterProcessor) setupBatchHandlers(ctx context.Con
738710 sd := sql .NewInternalSessionData (ctx , flowCtx .Cfg .Settings , "" /* opName */ )
739711
740712 switch writer {
741- case writerTypeSQL :
713+ case sqlclustersettings . LDRWriterTypeSQL :
742714 rp , err = makeSQLProcessor (
743715 ctx , flowCtx .Cfg .Settings , lrw .configByTable ,
744716 jobspb .JobID (lrw .spec .JobID ),
@@ -753,12 +725,12 @@ func (lrw *logicalReplicationWriterProcessor) setupBatchHandlers(ctx context.Con
753725 if err != nil {
754726 return err
755727 }
756- case writerTypeLegacyKV :
728+ case sqlclustersettings . LDRWriterTypeLegacyKV :
757729 rp , err = newKVRowProcessor (ctx , flowCtx .Cfg , flowCtx .EvalCtx , lrw .spec , lrw .configByTable )
758730 if err != nil {
759731 return err
760732 }
761- case writerTypeCRUD :
733+ case sqlclustersettings . LDRWriterTypeCRUD :
762734 rp , err = newCrudSqlWriter (ctx , flowCtx .Cfg , flowCtx .EvalCtx , sd , lrw .spec .Discard , lrw .configByTable , jobspb .JobID (lrw .spec .JobID ))
763735 if err != nil {
764736 return err
@@ -780,17 +752,17 @@ func (lrw *logicalReplicationWriterProcessor) setupBatchHandlers(ctx context.Con
780752
781753func getWriterType (
782754 ctx context.Context , mode jobspb.LogicalReplicationDetails_ApplyMode , settings * cluster.Settings ,
783- ) (writerType , error ) {
755+ ) (sqlclustersettings. LDRWriterType , error ) {
784756 switch mode {
785757 case jobspb .LogicalReplicationDetails_Immediate :
786758 // Require v25.2 to use the sql writer by default to ensure that the
787759 // KV origin timestamp validation is available on all nodes.
788760 if settings .Version .IsActive (ctx , clusterversion .V25_2 ) {
789- return writerType ( immediateModeWriter .Get (& settings .SV )), nil
761+ return sqlclustersettings . LDRWriterType ( sqlclustersettings . LDRImmediateModeWriter .Get (& settings .SV )), nil
790762 }
791- return writerTypeSQL , nil
763+ return sqlclustersettings . LDRWriterTypeSQL , nil
792764 case jobspb .LogicalReplicationDetails_Validated :
793- return writerTypeSQL , nil
765+ return sqlclustersettings . LDRWriterTypeSQL , nil
794766 default :
795767 return "" , errors .Newf ("unknown logical replication writer type: %s" , mode )
796768 }
0 commit comments