Skip to content

Conversation

@harshitydv1
Copy link

This PR implements a new /{db}/_config API endpoint that provides a unified, extensible interface for database-specific configuration settings, as requested in issue #5685.

Overview

The implementation follows the pattern of the server-level /_config API and consolidates existing per-database configuration endpoints (_revs_limit, _purged_infos_limit, _auto_purge) into a cohesive structure while maintaining full backward compatibility.

Changes Made

Modified Files

  1. src/chttpd/src/chttpd_httpd_handlers.erl (1 line added)

    • Registered handler for _config endpoint
  2. src/chttpd/src/chttpd_db.erl (~220 lines added)

    • Added export for handle_db_config_req/2
    • Implemented main handler function with routing for GET, PUT, DELETE operations
    • Added comprehensive helper functions for configuration management

API Endpoints

GET /{db}/_config

Returns all configuration sections and their values.

Example Response:

{
  "revs": {"limit": 1000},
  "purges": {"limit": 1000},
  "auto_purge": {"deleted_document_ttl": null},
  "compaction": {"generations": 0}
}

GET /{db}/_config/{section}

Returns all keys in a specific section.

Example: GET /mydb/_config/revs

{"limit": 1000}

GET /{db}/_config/{section}/{key}

Returns a specific configuration value.

Example: GET /mydb/_config/revs/limit1000

PUT /{db}/_config/{section}/{key}

Updates a configuration value and returns the old value.

Example: PUT /mydb/_config/revs/limit with body 2000 → returns 1000

DELETE /{db}/_config/{section}/{key}

Resets a configuration value to its default and returns the old value.

Supported Configuration Sections

1. revs Section

  • Key: limit (integer, default: 1000)
  • Description: Maximum number of document revisions to track
  • Replaces: /{db}/_revs_limit (still supported for backward compatibility)

2. purges Section

  • Key: limit (positive integer, default: 1000)
  • Description: Maximum number of purge requests to store
  • Replaces: /{db}/_purged_infos_limit (still supported for backward compatibility)

3. auto_purge Section

  • Key: deleted_document_ttl (string, default: null)
  • Description: Time-to-live for deleted documents before auto-purge (e.g., "30d", "7d")
  • Replaces: /{db}/_auto_purge (still supported for backward compatibility)

4. compaction Section

  • Key: generations (integer, default: 0)
  • Description: Generational compaction setting (reserved for future use)
  • Status: Not yet implemented (returns error on PUT/DELETE)

Backward Compatibility

✅ All existing endpoints continue to work:

  • /{db}/_revs_limit
  • /{db}/_purged_infos_limit
  • /{db}/_auto_purge

The new _config API internally uses the same fabric layer functions, ensuring consistency.

Implementation Details

  • Follows existing CouchDB patterns and conventions
  • Comprehensive input validation for all config keys
  • Proper HTTP status codes and error messages
  • Extensible design for adding new configuration options

Fixes #5685<!-- Thank you for your contribution!

 Please file this form by replacing the Markdown comments
 with your text. If a section needs no action - remove it.

 Also remember, that CouchDB uses the Review-Then-Commit (RTC) model
 of code collaboration. Positive feedback is represented +1 from committers
 and negative is a -1. The -1 also means veto, and needs to be addressed
 to proceed. Once there are no objections, the PR can be merged by a
 CouchDB committer.

 See: http://couchdb.apache.org/bylaws.html#decisions for more info. -->

Overview

Testing recommendations

Related Issues or Pull Requests

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • Documentation changes were made in the src/docs folder
  • Documentation changes were backported (separated PR) to affected branches

Ken was not starting background indexation for approximately 10% of
databases after design document updates. The issue was in the
maybe_start_job function which returned 'resubmit' instead of 'ok'
when should_start_job returned false.

This caused databases to be unnecessarily flagged for resubmission,
creating a loop where they would never get indexed in the background.

The fix changes maybe_start_job to return 'ok' in both cases:
- When successfully triggering an update (for consistency)
- When should_start_job returns false (the actual fix)

This allows database processing to complete successfully without
unnecessary resubmissions, ensuring all databases eventually get
indexed in the background.

Fixes apache#5392
The handle_info(timeout, ...) function in ken_server.erl had two bugs:
1. Used delay instead of prune_interval for the prune check
2. Set timeout to prune_interval (60s) instead of 0

This caused databases to wait up to 60 seconds in the queue before
being processed for background indexation, resulting in ~10% of
databases being skipped.

Fixed by:
- Using prune_interval for the prune interval check
- Setting timeout to 0 for immediate queue processing

This ensures all databases are picked up promptly for background
indexation while preserving rate limiting and resource controls.

Fixes apache#5392
When all indexing channels are busy, maybe_start_job was returning 'ok'
even though the job wasn't started. This caused some databases (~10%)
to never get indexed in the background.

Changed maybe_start_job to return 'resubmit' instead of 'ok' when
should_start_job returns false. This triggers the existing resubmit
mechanism to retry the database later when channels become available.

The resubmit mechanism was already implemented and used by search and
nouveau indexes, but was never triggered for the channel-busy case.

Fixes apache#5392
…en a job cannot be started, enabling proper retry.
This commit implements a new /{db}/_config API endpoint that provides
a unified, extensible interface for database-specific configuration,
modeled after the server-level /_config API.

Changes:
- Added handler registration for _config endpoint in chttpd_httpd_handlers.erl
- Implemented handle_db_config_req/2 in chttpd_db.erl with support for:
  * GET /{db}/_config - returns all config sections
  * GET /{db}/_config/{section} - returns all keys in a section
  * GET /{db}/_config/{section}/{key} - returns specific value
  * PUT /{db}/_config/{section}/{key} - updates value
  * DELETE /{db}/_config/{section}/{key} - resets to default
- Added helper functions for config management
- Supports sections: revs, purges, auto_purge, compaction
- Maintains backward compatibility with existing endpoints:
  _revs_limit, _purged_infos_limit, _auto_purge

Fixes apache#5685
@harshitydv1 harshitydv1 closed this Dec 2, 2025
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 per-db _config API

1 participant