Skip to content

Commit

Permalink
feat: Add support for MongoDB databaseOptions keys minPoolSize, `…
Browse files Browse the repository at this point in the history
…connectTimeoutMS`, `socketTimeoutMS`, `autoSelectFamily`, `autoSelectFamilyAttemptTimeout` (#9577)
  • Loading branch information
pocketcolin authored Feb 7, 2025
1 parent 6114cd9 commit 20f2071
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/ParseConfigKey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ describe('Config Keys', () => {
maxTimeMS: 1000,
maxStalenessSeconds: 10,
maxPoolSize: 10,
minPoolSize: 5,
connectTimeoutMS: 5000,
socketTimeoutMS: 5000,
autoSelectFamily: true,
autoSelectFamilyAttemptTimeout: 3000
},
})).toBeResolved();
expect(loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], '')).not.toMatch(invalidKeyErrorMessage);
Expand Down
30 changes: 30 additions & 0 deletions src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,24 @@ module.exports.FileUploadOptions = {
},
};
module.exports.DatabaseOptions = {
autoSelectFamily: {
env: 'PARSE_SERVER_DATABASE_AUTO_SELECT_FAMILY',
help:
'The MongoDB driver option to set whether the socket attempts to connect to IPv6 and IPv4 addresses until a connection is established. If available, the driver will select the first IPv6 address.',
action: parsers.booleanParser,
},
autoSelectFamilyAttemptTimeout: {
env: 'PARSE_SERVER_DATABASE_AUTO_SELECT_FAMILY_ATTEMPT_TIMEOUT',
help:
'The MongoDB driver option to specify the amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the autoSelectFamily option. If set to a positive integer less than 10, the value 10 is used instead.',
action: parsers.numberParser('autoSelectFamilyAttemptTimeout'),
},
connectTimeoutMS: {
env: 'PARSE_SERVER_DATABASE_CONNECT_TIMEOUT_MS',
help:
'The MongoDB driver option to specify the amount of time, in milliseconds, to wait to establish a single TCP socket connection to the server before raising an error. Specifying 0 disables the connection timeout.',
action: parsers.numberParser('connectTimeoutMS'),
},
enableSchemaHooks: {
env: 'PARSE_SERVER_DATABASE_ENABLE_SCHEMA_HOOKS',
help:
Expand All @@ -1069,6 +1087,12 @@ module.exports.DatabaseOptions = {
'The MongoDB driver option to set a cumulative time limit in milliseconds for processing operations on a cursor.',
action: parsers.numberParser('maxTimeMS'),
},
minPoolSize: {
env: 'PARSE_SERVER_DATABASE_MIN_POOL_SIZE',
help:
'The MongoDB driver option to set the minimum number of opened, cached, ready-to-use database connections maintained by the driver.',
action: parsers.numberParser('minPoolSize'),
},
retryWrites: {
env: 'PARSE_SERVER_DATABASE_RETRY_WRITES',
help: 'The MongoDB driver option to set whether to retry failed writes.',
Expand All @@ -1080,6 +1104,12 @@ module.exports.DatabaseOptions = {
'The duration in seconds after which the schema cache expires and will be refetched from the database. Use this option if using multiple Parse Servers instances connected to the same database. A low duration will cause the schema cache to be updated too often, causing unnecessary database reads. A high duration will cause the schema to be updated too rarely, increasing the time required until schema changes propagate to all server instances. This feature can be used as an alternative or in conjunction with the option `enableSchemaHooks`. Default is infinite which means the schema cache never expires.',
action: parsers.numberParser('schemaCacheTtl'),
},
socketTimeoutMS: {
env: 'PARSE_SERVER_DATABASE_SOCKET_TIMEOUT_MS',
help:
'The MongoDB driver option to specify the amount of time, in milliseconds, spent attempting to send or receive on a socket before timing out. Specifying 0 means no timeout.',
action: parsers.numberParser('socketTimeoutMS'),
},
};
module.exports.AuthAdapter = {
enabled: {
Expand Down
5 changes: 5 additions & 0 deletions src/Options/docs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,18 @@ export interface DatabaseOptions {
maxTimeMS: ?number;
/* The MongoDB driver option to set the maximum replication lag for reads from secondary nodes.*/
maxStalenessSeconds: ?number;
/* The MongoDB driver option to set the minimum number of opened, cached, ready-to-use database connections maintained by the driver. */
minPoolSize: ?number;
/* The MongoDB driver option to set the maximum number of opened, cached, ready-to-use database connections maintained by the driver. */
maxPoolSize: ?number;
/* The MongoDB driver option to specify the amount of time, in milliseconds, to wait to establish a single TCP socket connection to the server before raising an error. Specifying 0 disables the connection timeout. */
connectTimeoutMS: ?number;
/* The MongoDB driver option to specify the amount of time, in milliseconds, spent attempting to send or receive on a socket before timing out. Specifying 0 means no timeout. */
socketTimeoutMS: ?number;
/* The MongoDB driver option to set whether the socket attempts to connect to IPv6 and IPv4 addresses until a connection is established. If available, the driver will select the first IPv6 address. */
autoSelectFamily: ?boolean;
/* The MongoDB driver option to specify the amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the autoSelectFamily option. If set to a positive integer less than 10, the value 10 is used instead. */
autoSelectFamilyAttemptTimeout: ?number;
}

export interface AuthAdapter {
Expand Down

0 comments on commit 20f2071

Please sign in to comment.