Skip to content

Commit 2a0e34c

Browse files
committed
PCSM-219: Undoing using the validator
1 parent 2b30ea2 commit 2a0e34c

File tree

8 files changed

+14
-265
lines changed

8 files changed

+14
-265
lines changed

config/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/spf13/viper"
1111

1212
"github.com/percona/percona-clustersync-mongodb/errors"
13-
"github.com/percona/percona-clustersync-mongodb/validate"
1413
)
1514

1615
// Load initializes Viper and returns a validated Config.
@@ -35,11 +34,6 @@ func Load(cmd *cobra.Command) (*Config, error) {
3534
return nil, errors.Wrap(err, "unmarshal config")
3635
}
3736

38-
err = validate.Struct(&cfg)
39-
if err != nil {
40-
return nil, errors.Wrap(err, "validate config")
41-
}
42-
4337
return &cfg, nil
4438
}
4539

config/schema.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// Config holds all PCSM configuration.
1111
type Config struct {
1212
// Connection
13-
Port int `mapstructure:"port" validate:"omitempty,gte=1024,lte=65535"`
13+
Port int `mapstructure:"port"`
1414
Source string `mapstructure:"source"`
1515
Target string `mapstructure:"target"`
1616

@@ -34,14 +34,14 @@ type Config struct {
3434

3535
// LogConfig holds logging configuration.
3636
type LogConfig struct {
37-
Level string `mapstructure:"log-level" validate:"omitempty,oneof=trace debug info warn error fatal panic"`
37+
Level string `mapstructure:"log-level"`
3838
JSON bool `mapstructure:"log-json"`
3939
NoColor bool `mapstructure:"no-color"`
4040
}
4141

4242
// MongoDBConfig holds MongoDB client configuration.
4343
type MongoDBConfig struct {
44-
OperationTimeout string `mapstructure:"mongodb-cli-operation-timeout" validate:"omitempty,duration"`
44+
OperationTimeout string `mapstructure:"mongodb-cli-operation-timeout"`
4545
}
4646

4747
// OperationTimeoutDuration returns the parsed timeout or default.
@@ -58,11 +58,11 @@ func (m *MongoDBConfig) OperationTimeoutDuration() time.Duration {
5858

5959
// CloneConfig holds clone tuning configuration.
6060
type CloneConfig struct {
61-
NumParallelCollections int `mapstructure:"clone-num-parallel-collections" validate:"omitempty,gte=0,lte=100"`
62-
NumReadWorkers int `mapstructure:"clone-num-read-workers" validate:"omitempty,gte=0,lte=1000"`
63-
NumInsertWorkers int `mapstructure:"clone-num-insert-workers" validate:"omitempty,gte=0,lte=1000"`
64-
SegmentSize string `mapstructure:"clone-segment-size" validate:"omitempty,bytesize"`
65-
ReadBatchSize string `mapstructure:"clone-read-batch-size" validate:"omitempty,bytesize"`
61+
NumParallelCollections int `mapstructure:"clone-num-parallel-collections"`
62+
NumReadWorkers int `mapstructure:"clone-num-read-workers"`
63+
NumInsertWorkers int `mapstructure:"clone-num-insert-workers"`
64+
SegmentSize string `mapstructure:"clone-segment-size"`
65+
ReadBatchSize string `mapstructure:"clone-read-batch-size"`
6666
}
6767

6868
// SegmentSizeBytes parses and returns the segment size in bytes.

go.mod

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ go 1.25.0
44

55
require (
66
github.com/dustin/go-humanize v1.0.1
7-
github.com/go-playground/validator/v10 v10.30.0
87
github.com/prometheus/client_golang v1.22.0
98
github.com/rs/zerolog v1.34.0
109
github.com/spf13/cobra v1.9.1
11-
github.com/spf13/pflag v1.0.10
1210
github.com/spf13/viper v1.21.0
1311
github.com/stretchr/testify v1.11.1
1412
go.mongodb.org/mongo-driver/v2 v2.2.1
@@ -20,14 +18,10 @@ require (
2018
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2119
github.com/davecgh/go-spew v1.1.1 // indirect
2220
github.com/fsnotify/fsnotify v1.9.0 // indirect
23-
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
24-
github.com/go-playground/locales v0.14.1 // indirect
25-
github.com/go-playground/universal-translator v0.18.1 // indirect
2621
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
2722
github.com/golang/snappy v1.0.0 // indirect
2823
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2924
github.com/klauspost/compress v1.18.0 // indirect
30-
github.com/leodido/go-urn v1.4.0 // indirect
3125
github.com/mattn/go-colorable v0.1.13 // indirect
3226
github.com/mattn/go-isatty v0.0.19 // indirect
3327
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -40,6 +34,7 @@ require (
4034
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
4135
github.com/spf13/afero v1.15.0 // indirect
4236
github.com/spf13/cast v1.10.0 // indirect
37+
github.com/spf13/pflag v1.0.10 // indirect
4338
github.com/subosito/gotenv v1.6.0 // indirect
4439
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
4540
github.com/xdg-go/scram v1.1.2 // indirect

go.sum

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
1212
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1313
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
1414
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
15-
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
16-
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
17-
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
18-
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
19-
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
20-
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
21-
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
22-
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
23-
github.com/go-playground/validator/v10 v10.30.0 h1:5YBPNs273uzsZJD1I8uiB4Aqg9sN6sMDVX3s6LxmhWU=
24-
github.com/go-playground/validator/v10 v10.30.0/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
2515
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
2616
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
2717
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -39,8 +29,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
3929
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4030
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
4131
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
42-
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
43-
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
4432
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
4533
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
4634
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=

main.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/percona/percona-clustersync-mongodb/pcsm"
3131
"github.com/percona/percona-clustersync-mongodb/topo"
3232
"github.com/percona/percona-clustersync-mongodb/util"
33-
"github.com/percona/percona-clustersync-mongodb/validate"
3433
)
3534

3635
// Constants for server configuration.
@@ -851,13 +850,6 @@ func (s *server) handleStart(w http.ResponseWriter, r *http.Request) {
851850
}
852851
}
853852

854-
// Validate request
855-
if err := params.Validate(); err != nil {
856-
writeResponse(w, startResponse{Err: err.Error()})
857-
858-
return
859-
}
860-
861853
options, err := resolveStartOptions(s.cfg, params)
862854
if err != nil {
863855
writeResponse(w, startResponse{Err: err.Error()})
@@ -1046,24 +1038,19 @@ type startRequest struct {
10461038

10471039
// Clone tuning options (pointer types to distinguish "not set" from zero value)
10481040
// CloneNumParallelCollections is the number of collections to clone in parallel.
1049-
CloneNumParallelCollections *int `json:"cloneNumParallelCollections,omitempty" validate:"omitempty,gte=0,lte=100"`
1041+
CloneNumParallelCollections *int `json:"cloneNumParallelCollections,omitempty"`
10501042
// CloneNumReadWorkers is the number of read workers during clone.
1051-
CloneNumReadWorkers *int `json:"cloneNumReadWorkers,omitempty" validate:"omitempty,gte=0,lte=1000"`
1043+
CloneNumReadWorkers *int `json:"cloneNumReadWorkers,omitempty"`
10521044
// CloneNumInsertWorkers is the number of insert workers during clone.
1053-
CloneNumInsertWorkers *int `json:"cloneNumInsertWorkers,omitempty" validate:"omitempty,gte=0,lte=1000"`
1045+
CloneNumInsertWorkers *int `json:"cloneNumInsertWorkers,omitempty"`
10541046
// CloneSegmentSize is the segment size for clone operations (e.g., "100MB", "1GiB").
1055-
CloneSegmentSize *string `json:"cloneSegmentSize,omitempty" validate:"omitempty,bytesize"`
1047+
CloneSegmentSize *string `json:"cloneSegmentSize,omitempty"`
10561048
// CloneReadBatchSize is the read batch size during clone (e.g., "16MiB").
1057-
CloneReadBatchSize *string `json:"cloneReadBatchSize,omitempty" validate:"omitempty,bytesize"`
1049+
CloneReadBatchSize *string `json:"cloneReadBatchSize,omitempty"`
10581050

10591051
// NOTE: UseCollectionBulkWrite intentionally NOT exposed via HTTP (internal only)
10601052
}
10611053

1062-
// Validate validates the startRequest.
1063-
func (r *startRequest) Validate() error {
1064-
return validate.Struct(r)
1065-
}
1066-
10671054
// startResponse represents the response body for the /start endpoint.
10681055
type startResponse struct {
10691056
// Ok indicates if the operation was successful.

validate/bytesize.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

validate/errors.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

validate/validate.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)