Skip to content

Commit a1c4da6

Browse files
committed
disable by default
1 parent f1801ff commit a1c4da6

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

flow/connectors/mongo/qrep.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/PeerDB-io/peerdb/flow/connectors/utils"
1515
"github.com/PeerDB-io/peerdb/flow/generated/protos"
16+
"github.com/PeerDB-io/peerdb/flow/internal"
1617
"github.com/PeerDB-io/peerdb/flow/model"
1718
"github.com/PeerDB-io/peerdb/flow/otel_metrics"
1819
"github.com/PeerDB-io/peerdb/flow/pkg/common"
@@ -35,6 +36,16 @@ func (c *MongoConnector) GetQRepPartitions(
3536
}
3637

3738
if config.WatermarkColumn != DefaultDocumentKeyColumnName {
39+
c.logger.Warn("unexpected watermark column, falling back to full table partition")
40+
return fullTablePartition, nil
41+
}
42+
43+
parallelSnapshotting, err := internal.PeerDBMongoDBParallelSnapshotting(ctx, config.Env)
44+
if err != nil {
45+
c.logger.Warn("failed to get parallel snapshotting config", slog.Any("error", err))
46+
}
47+
if !parallelSnapshotting {
48+
c.logger.Info("parallel snapshotting disabled, falling back to full table partition")
3849
return fullTablePartition, nil
3950
}
4051

flow/e2e/mongo_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (s MongoClickhouseSuite) Test_Simple_Flow_Partitioned() {
109109
flowConnConfig := s.generateFlowConnectionConfigsDefaultEnv(connectionGen)
110110
flowConnConfig.DoInitialSnapshot = true
111111
flowConnConfig.SnapshotNumRowsPerPartition = 10
112+
flowConnConfig.Env["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING"] = "true"
112113

113114
adminClient := s.Source().(*MongoSource).AdminClient()
114115
collection := adminClient.Database(srcDatabase).Collection(srcTable)
@@ -172,6 +173,7 @@ func (s MongoClickhouseSuite) Test_Snapshot_Partition_Capped_To_Timestamp_Range(
172173
// 1 row per partition would normally request 100 partitions for 100 docs,
173174
// but the 5-second timestamp range should cap it to 5 partitions.
174175
flowConnConfig.SnapshotNumRowsPerPartition = 1
176+
flowConnConfig.Env["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING"] = "true"
175177

176178
adminClient := s.Source().(*MongoSource).AdminClient()
177179
collection := adminClient.Database(srcDatabase).Collection(srcTable)
@@ -221,6 +223,7 @@ func (s MongoClickhouseSuite) Test_Snapshot_Empty_Collection() {
221223
flowConnConfig := s.generateFlowConnectionConfigsDefaultEnv(connectionGen)
222224
flowConnConfig.DoInitialSnapshot = true
223225
flowConnConfig.SnapshotNumRowsPerPartition = 1
226+
flowConnConfig.Env["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING"] = "true"
224227

225228
adminClient := s.Source().(*MongoSource).AdminClient()
226229
err := adminClient.Database(srcDatabase).CreateCollection(t.Context(), srcTable)
@@ -255,6 +258,7 @@ func (s MongoClickhouseSuite) Test_Snapshot_Non_ObjectID_Falls_Back_To_Single_Pa
255258
flowConnConfig := s.generateFlowConnectionConfigsDefaultEnv(connectionGen)
256259
flowConnConfig.DoInitialSnapshot = true
257260
flowConnConfig.SnapshotNumRowsPerPartition = 5
261+
flowConnConfig.Env["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING"] = "true"
258262

259263
adminClient := s.Source().(*MongoSource).AdminClient()
260264
collection := adminClient.Database(srcDatabase).Collection(srcTable)
@@ -300,6 +304,7 @@ func (s MongoClickhouseSuite) Test_Snapshot_Mixed_ObjectID_Falls_Back_To_Single_
300304
flowConnConfig := s.generateFlowConnectionConfigsDefaultEnv(connectionGen)
301305
flowConnConfig.DoInitialSnapshot = true
302306
flowConnConfig.SnapshotNumRowsPerPartition = 1
307+
flowConnConfig.Env["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING"] = "true"
303308

304309
adminClient := s.Source().(*MongoSource).AdminClient()
305310
collection := adminClient.Database(srcDatabase).Collection(srcTable)

flow/internal/dynamicconf.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ var DynamicSettings = [...]*protos.DynamicSetting{
435435
ApplyMode: protos.DynconfApplyMode_APPLY_MODE_AFTER_RESUME,
436436
TargetForSetting: protos.DynconfTarget_ALL,
437437
},
438+
{
439+
Name: "PEERDB_MONGODB_PARALLEL_SNAPSHOTTING",
440+
Description: "Use min/max ObjectID-based parallel partitioning for MongoDB initial snapshot",
441+
DefaultValue: "false",
442+
ValueType: protos.DynconfValueType_BOOL,
443+
ApplyMode: protos.DynconfApplyMode_APPLY_MODE_AFTER_RESUME,
444+
TargetForSetting: protos.DynconfTarget_ALL,
445+
},
438446
{
439447
Name: "PEERDB_MONGODB_DIRECT_BSON_CONVERTER",
440448
Description: "Use direct BSON-to-JSON converter for MongoDB (faster, no intermediate deserialization). " +
@@ -797,6 +805,10 @@ func PeerDBPostgresApplyCtidBlockPartitioning(ctx context.Context, env map[strin
797805
return dynamicConfBool(ctx, env, "PEERDB_POSTGRES_APPLY_CTID_BLOCK_PARTITIONING_OVERRIDE")
798806
}
799807

808+
func PeerDBMongoDBParallelSnapshotting(ctx context.Context, env map[string]string) (bool, error) {
809+
return dynamicConfBool(ctx, env, "PEERDB_MONGODB_PARALLEL_SNAPSHOTTING")
810+
}
811+
800812
func PeerDBMongoDBDirectBsonConverter(ctx context.Context, env map[string]string) (bool, error) {
801813
return dynamicConfBool(ctx, env, "PEERDB_MONGODB_DIRECT_BSON_CONVERTER")
802814
}

0 commit comments

Comments
 (0)