Worker Database Connection Configuration
Configure the worker component's database connection, including authentication modes (IAM, user/password), timeouts, and SSL settings. Reference for all
Overview
The worker component requires a persistent database connection to perform its tasks, which include running batch rollups and replay drains. This document describes the configuration properties, prefixed with s2r.db, that control how the worker connects to and authenticates with its database.
These settings allow you to define the database endpoint, credentials, authentication method, and network resilience parameters like timeouts and SSL mode. Proper configuration is essential for the worker's stability and ability to complete long-running background jobs.
How it Works
The worker's database connection is established at startup based on the provided s2r.db properties. The primary configuration choice is the authentication method, controlled by the s2r.db.authMode property.
Authentication Modes
The system supports two primary modes for database authentication:
-
IAM Authentication (
authMode: "iam"): This is the default mode. The worker uses Identity and Access Management (IAM) credentials to authenticate. This mode is often used with managed cloud database services.- When connecting to certain managed cloud databases that use a Java connector, the
s2r.db.instanceConnectionNameproperty should be set. This directs the driver to use a specific connection path. - The
s2r.db.iamTokenRefreshSecondsproperty controls the lifetime of the temporary IAM authentication token.
- When connecting to certain managed cloud databases that use a Java connector, the
-
Username/Password Authentication: By setting
authModeto a value other thaniam, you can configure the worker to use traditional database credentials.- In this mode,
s2r.db.userands2r.db.passwordmust be provided. - The connection is made directly to the endpoint specified by
s2r.db.hostands2r.db.port.
- In this mode,
The following diagram illustrates the authentication flow:
flowchart TD
subgraph "Worker Database Authentication"
A(Worker starts) --> B{Read s2r.db.authMode};
B -- "iam" --> C[IAM Authentication];
B -- "other" --> D[Username/Password Authentication];
C --> E["Connect using IAM credentials.<br/>If instanceConnectionName is set,<br/>uses a specific cloud database connector."];
D --> F[Connect using s2r.db.user and s2r.db.password];
E --> G([Database Connection]);
F --> G;
endTimeouts and Resilience
The worker is designed to handle long-running batch processes that can be significantly slower than typical API request queries. The timeout settings are configured to accommodate these workloads and improve resilience against network instability.
socketTimeoutSeconds: This timeout is set to a high value by default (120seconds) to prevent premature termination of slow batch statements, such as data rollups or replay drains. It must be configured to exceed the duration of the slowest expected database query.connectTimeoutSeconds: This timeout governs the initial connection attempt to the database. It is based on a default value from the platform's socket resilience library, designed to handle transient network outages during startup.
Configuration Reference
All properties are prefixed with s2r.db. For example, to set the host, the full property name would be s2r.db.host.
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
authMode | String | iam | No | The authentication mode to use. Set to iam for IAM-based authentication or another value for username/password authentication. |
host | String | — | Varies | The hostname or IP address of the database server. Required when not using instanceConnectionName. |
port | int | 5432 | No | The port number of the database server. |
name | String | soap_to_rest | No | The name of the database to connect to. |
user | String | — | Varies | The username for database authentication. Required when authMode is not iam. |
password | String | — | Varies | The password for database authentication. Required when authMode is not iam. |
iamTokenRefreshSeconds | int | 2700 | No | The frequency, in seconds, at which the IAM authentication token is refreshed. (2700 seconds = 45 minutes). |
sslMode | String | require | No | The SSL mode for the database connection. |
instanceConnectionName | String | — | Varies | The connection name for a managed cloud database instance, typically in the format <project>:<region>:<instance>. Used for the IAM authentication path with specific cloud connectors. |
ipType | String | PRIVATE | No | When using instanceConnectionName, specifies the IP address type to use for the connection. Valid values are PRIVATE, PUBLIC, and PSC. |
socketTimeoutSeconds | int | 120 | No | Socket-level read timeout in seconds. Set high to accommodate long-running worker batch jobs. This value must exceed the duration of the slowest batch statement. |
connectTimeoutSeconds | int | Varies | No | Socket-level connection timeout in seconds. The default is derived from the DbSocketResilience.DEFAULT_CONNECT_TIMEOUT_SECONDS constant to guard against connection failures during outages. The source does not specify the exact integer value of this constant. |
Troubleshooting
Long-Running Jobs Fail with Timeout
The worker executes potentially slow batch operations like data rollups and replays. If these jobs fail, check the logs for timeout errors.
Cause: The s2r.db.socketTimeoutSeconds value may be too low for the duration of the database queries being executed.
Solution: Profile your slowest batch queries and set s2r.db.socketTimeoutSeconds to a value greater than the longest expected query time. The default is 120 seconds.
