Skip to content

Commit 1a37dbf

Browse files
committed
Add time-seq and _changes since=time docs
1 parent 6d70946 commit 1a37dbf

File tree

3 files changed

+139
-2
lines changed

3 files changed

+139
-2
lines changed

src/docs/src/api/database/changes.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@
9494
:query number limit: Limit number of result rows to the specified value
9595
(note that using ``0`` here has the same effect as ``1``).
9696
:query since: Start the results from the change immediately after the given
97-
update sequence. Can be valid update sequence or ``now`` value.
98-
Default is ``0``.
97+
update sequence. Default is ``0``. Other values can be:
98+
99+
- A valid update sequence, for example, from a ``_changes`` feed response.
100+
- ``now``
101+
- ``0``
102+
- A timestmap string matching the ``YYYY-MM-DDTHH:MM:SSZ``
103+
format. The results returned will depend on the time-sequence
104+
intervals recorded by the time-seq data structure. To inspect or reset
105+
it use the :ref:`_time_seq <api/db/time_seq>` endpoint.
99106
:query string style: Specifies how many revisions are returned in the
100107
changes array. The default, ``main_only``, will only return the current
101108
"winning" revision; ``all_docs`` will return all leaf revisions

src/docs/src/api/database/misc.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,114 @@ following behavior:
568568
{
569569
"ok": true
570570
}
571+
572+
.. _api/db/time_seq:
573+
574+
=====================
575+
``/{db}/_time_seq``
576+
=====================
577+
578+
.. http:get:: /{db}/_time_seq
579+
:synopsis: Get the time-seq data structure summaries
580+
581+
Time-seq is a data structure which keeps track of how db sequences map to
582+
rough time intervals. Each summary contains all the interval start times
583+
and the number of sequences in that time interval.
584+
585+
:param db: Database name
586+
:<header Accept: - :mimetype:`application/json`
587+
- :mimetype:`text/plain`
588+
:>header Content-Type: - :mimetype:`application/json`
589+
- :mimetype:`text/plain; charset=utf-8`
590+
:>json object time_seq: A time_seq summaries broken down by range and node.
591+
:code 200: Request completed successfully
592+
:code 400: Invalid database name
593+
:code 401: Read privilege required
594+
:code 403: Insufficient permissions / :ref:`Too many requests with invalid credentials<error/403>`
595+
:code 415: Bad :header:`Content-Type` value
596+
:code 500: Internal server error or timeout
597+
598+
**Request**:
599+
600+
.. code-block:: http
601+
602+
GET /db/_time_seq HTTP/1.1
603+
Accept: application/json
604+
Host: localhost:5984
605+
606+
**Response**:
607+
608+
.. code-block:: http
609+
610+
HTTP/1.1 200 OK
611+
Cache-Control: must-revalidate
612+
Content-Length: 400
613+
Content-Type: application/json
614+
615+
{
616+
"time_seq": {
617+
"00000000-7fffffff": {
618+
619+
["2025-07-27T06:00:00Z", 8],
620+
["2025-07-27T09:00:00Z", 13],
621+
["2025-07-27T12:00:00Z", 13],
622+
["2025-07-27T15:00:00Z", 7],
623+
["2025-07-27T18:00:00Z", 3]
624+
]
625+
},
626+
"80000000-ffffffff": {
627+
628+
["2025-07-27T03:00:00Z", 1],
629+
["2025-07-27T06:00:00Z", 10],
630+
["2025-07-27T09:00:00Z", 5],
631+
["2025-07-27T12:00:00Z", 5],
632+
["2025-07-27T15:00:00Z", 11],
633+
["2025-07-27T18:00:00Z", 2]
634+
]
635+
}
636+
}
637+
}
638+
639+
.. http:delete:: /{db}/_time_seq
640+
:synopsis: Reset time-seq data structures.
641+
642+
Time-seq is a data structure which keeps track of how db sequences map to
643+
rough time intervals. The ``DELETE`` method will reset time-seq data
644+
structure for all the shards in the database. Resetting the time-seq
645+
structure is always safe and doesn't alter the main b-trees, document
646+
revisions, or document bodies. It just resets the time to database
647+
sequences mappings. This should be rarely needed and is mainly to be used
648+
perhaps in the case when the OS time settings were misconfigured and the
649+
the time-seq data structures recorded invalid dates from a distant future.
650+
651+
:param db: Database name
652+
:<header Accept: - :mimetype:`application/json`
653+
- :mimetype:`text/plain`
654+
:<header Content-Type: :mimetype:`application/json`
655+
:>header Content-Type: - :mimetype:`application/json`
656+
- :mimetype:`text/plain; charset=utf-8`
657+
:>json boolean ok: Operation status
658+
:code 200: Request completed successfully
659+
:code 400: Invalid JSON data
660+
:code 401: Unauthorized request to a protected API
661+
:code 403: Insufficient permissions / :ref:`Too many requests with invalid credentials<error/403>`
662+
663+
**Request**:
664+
665+
.. code-block:: http
666+
667+
DELETE /db/_time_seq HTTP/1.1
668+
Content-Length: 0
669+
Host: localhost:15984
670+
671+
**Response**:
672+
673+
.. code-block:: http
674+
675+
HTTP/1.1 200 OK
676+
Content-Length: 12
677+
Content-Type: application/json
678+
679+
{
680+
"ok": true
681+
}

src/docs/src/config/couchdb.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,22 @@ Base CouchDB Options
257257

258258
[couchdb]
259259
js_engine = spidermonkey
260+
261+
.. config:option:: time_seq_min_time :: Minimum time-seq threshold
262+
263+
.. versionchanged:: 3.6
264+
265+
Time-seq is the data structure in the database files which keeps track
266+
of the mapping between rough time intervals and database sequence
267+
numbers. This setting is minimum time threshold below which updates to
268+
the time-seq data structure will be ignored. This may be useful, for
269+
example, in embedded systems which do not keep their own time when
270+
turned off, and instead only rely on NTP synchronization. Such systems
271+
after boot may briefly default to some time like 1970-01-01 until they
272+
synchronize. The default setting value is some recent time before the
273+
latest CouchDB release or before feature was developed. The value may
274+
be bumped on future release. The value is expected to be in Unix
275+
seconds (see ``wikipedia.org/wiki/inix_time`` for more details) ::
276+
277+
[couchdb]
278+
time_seq_min_time = 1754006400

0 commit comments

Comments
 (0)