Skip to content

feat: add connection pool options to Oracle state store#4411

Merged
JoshVanL merged 5 commits into
dapr:mainfrom
nelson-parente:feat/oracle-state-connection-pool-options
Jun 23, 2026
Merged

feat: add connection pool options to Oracle state store#4411
JoshVanL merged 5 commits into
dapr:mainfrom
nelson-parente:feat/oracle-state-connection-pool-options

Conversation

@nelson-parente

@nelson-parente nelson-parente commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

The Oracle state store uses the Go go-ora driver via the standard database/sql abstraction. Connection pooling is therefore controlled by *sql.DB, not the driver/connection string. Today the Oracle state store exposes no way to tune the connection pool, so operators are stuck with Go's defaults regardless of their workload.

This PR adds four metadata options to configure the database/sql connection pool for the Oracle state store.

New metadata options

Metadata key database/sql setter Type Default (Go built-in)
maxOpenConns db.SetMaxOpenConns(int) number unlimited (0)
maxIdleConns db.SetMaxIdleConns(int) number 2
connMaxLifetime db.SetConnMaxLifetime(time.Duration) duration unlimited (0)
connMaxIdleTime db.SetConnMaxIdleTime(time.Duration) duration unlimited (0)

Each setter is called only when the user explicitly provides the option (non-zero value). Omitting a field leaves Go's built-in database/sql default unchanged, so this change is fully backwards-compatible.

Reference implementation

The pattern, field names, types, and "apply only if set" guard are intentionally mirrored from the existing MySQL bindings component (bindings/mysql/mysql.go), which already implements all four options identically.

Changes

  • state/oracledatabase/oracledatabaseaccess.go — added four fields to oracleDatabaseMetadata (with mapstructure tags) and four guarded db.Set* calls in Init after sql.Open.
  • state/oracledatabase/metadata.yaml — documented all four new fields (type, description, example, default).
  • state/oracledatabase/oracledatabaseaccess_test.go — added three new tests:
    • TestParseMetadataConnectionPool: table-driven test verifying metadata parsing for all four fields, including zero/omitted values and duration shorthand.
    • TestConnectionPoolApplied: verifies that non-zero pool settings are applied to *sql.DB (uses go-sqlmock, no live Oracle DB required).
    • TestConnectionPoolZeroValuesSkipped: verifies that zero values leave the Go default (MaxOpenConnections == 0).

Fixes #4276


📖 Documentation: dapr/docs#5221

Expose four database/sql connection-pool tunables as component metadata
so operators can tune the Oracle state store without forking the component:

  maxOpenConns    -> db.SetMaxOpenConns(int)
  maxIdleConns    -> db.SetMaxIdleConns(int)
  connMaxLifetime -> db.SetConnMaxLifetime(time.Duration)
  connMaxIdleTime -> db.SetConnMaxIdleTime(time.Duration)

Each setter is called only when the user provides the option (non-zero
value), preserving Go's built-in database/sql defaults when the field is
omitted. The pattern and field names mirror the MySQL bindings component
(bindings/mysql).

Fixes dapr#4276

Signed-off-by: Nelson Parente <nelson@diagrid.io>
@nelson-parente nelson-parente force-pushed the feat/oracle-state-connection-pool-options branch from bbcfba1 to 98b72d9 Compare June 17, 2026 14:32
@nelson-parente nelson-parente requested a review from Copilot June 18, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Not ready to approve

The documentation around maxIdleConns currently misstates the effective/default behavior (and Init still leaks a DB handle on ensureStateTable failure), which should be corrected before approval.

Pull request overview

This PR adds configurable database/sql connection pool tuning to the Oracle state store via new metadata fields, allowing operators to adjust pooling behavior (max open/idle connections, max lifetime/idle time) while preserving Go’s defaults when options are not provided.

Changes:

  • Extended oracleDatabaseMetadata with four connection-pool fields and applied them during Init via a dedicated applyConnectionPool helper.
  • Adjusted Init flow to ping before assigning o.db, and to close the DB on ping failure.
  • Added tests validating metadata decoding and basic application of pool settings; updated component metadata documentation.
File summaries
File Description
state/oracledatabase/oracledatabaseaccess.go Adds pool configuration fields + helper and applies pool settings during initialization.
state/oracledatabase/oracledatabaseaccess_test.go Adds tests for decoding pool metadata and applying MaxOpenConns via *sql.DB stats.
state/oracledatabase/metadata.yaml Documents the new pool-related metadata options.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread state/oracledatabase/oracledatabaseaccess.go Outdated
Comment thread state/oracledatabase/metadata.yaml Outdated
Comment thread state/oracledatabase/oracledatabaseaccess.go
…ns docs (Copilot review)

Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Ready to approve

The changes are low-risk, test-covered, and align with existing patterns, with only a minor comment/doc wording nit noted.

Note: this review does not count toward required approvals for merging.

Copilot's findings
  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.

Comment thread state/oracledatabase/oracledatabaseaccess.go Outdated
@nelson-parente nelson-parente marked this pull request as ready for review June 19, 2026 09:36
@nelson-parente nelson-parente requested review from a team as code owners June 19, 2026 09:36
@JoshVanL JoshVanL enabled auto-merge June 22, 2026 11:25
@JoshVanL JoshVanL added this pull request to the merge queue Jun 23, 2026
Merged via the queue into dapr:main with commit 41d62ba Jun 23, 2026
189 of 195 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add connection pool options to the Oracle state store component

3 participants