Skip to content

Commit 8e8ca28

Browse files
authored
PLM-207: Add operation timeout parameter (#136)
1 parent 3e7c5d5 commit 8e8ca28

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ bin/plm \
163163
--log-json
164164
```
165165

166+
## Environment Variables
167+
168+
- `PLM_SOURCE_URI`: MongoDB connection string for the source cluster.
169+
- `PLM_TARGET_URI`: MongoDB connection string for the target cluster.
170+
- `PLM_MONGODB_CLI_OPERATION_TIMEOUT`: Timeout for MongoDB client operations; accepts Go durations like `30s`, `2m`, `1h` (default: `5m`).
171+
166172
## Log JSON Fields
167173

168174
When using the `--log-json` option, the logs will be output in JSON format with the following fields:

config/const.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ const (
4444
DisconnectTimeout = 5 * time.Second
4545
// CloseCursorTimeout is the timeout duration for closing cursor.
4646
CloseCursorTimeout = 10 * time.Second
47-
// OperationTimeout is the timeout duration for MonngoDB client operations like
48-
// insert, update, delete, etc.
49-
OperationTimeout = 5 * time.Minute
47+
// DefaultMongoDBCliOperationTimeout is the default timeout duration for MongoDB client
48+
// operations like insert, update, delete, etc. It can be overridden via
49+
// environment variable (see config.OperationMongoDBCliTimeout()).
50+
DefaultMongoDBCliOperationTimeout = 5 * time.Minute
5051
)
5152

5253
// Change stream and replication settings.

config/values.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"strconv"
88
"strings"
9+
"time"
910

1011
"github.com/dustin/go-humanize"
1112
)
@@ -82,3 +83,17 @@ func UseTargetClientCompressors() []string {
8283

8384
return rv
8485
}
86+
87+
// OperationMongoDBCliTimeout returns the effective timeout for MongoDB client operations.
88+
// If the environment variable `PLM_MONGODB_CLI_OPERATION_TIMEOUT` is set, it must be a valid
89+
// time duration string (e.g., "30s", "2m", "1h"). Otherwise, the
90+
// DefaultMongoDBCliOperationTimeout is used.
91+
func OperationMongoDBCliTimeout() time.Duration {
92+
if v := strings.TrimSpace(os.Getenv("PLM_MONGODB_CLI_OPERATION_TIMEOUT")); v != "" {
93+
if d, err := time.ParseDuration(v); err == nil && d > 0 {
94+
return d
95+
}
96+
}
97+
98+
return DefaultMongoDBCliOperationTimeout
99+
}

topo/connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ConnectWithOptions(
5858
SetReadPreference(readpref.Primary()).
5959
SetReadConcern(readconcern.Majority()).
6060
SetWriteConcern(writeconcern.Majority()).
61-
SetTimeout(config.OperationTimeout)
61+
SetTimeout(config.OperationMongoDBCliTimeout())
6262

6363
if connOpts != nil && connOpts.Compressors != nil {
6464
opts.SetCompressors(connOpts.Compressors)

0 commit comments

Comments
 (0)