Commit e50f3ac
committed
Time-based since parameter for _changes
Use the new time-seq feature to stream changes from before a point in time.
This can be used for backups or any case when then it helps to associate a
range of sequence updates to a time interval. The time-seq exponential decaying
interval rules apply: the further back in time, the less accurate the time
intervals will be.
The API change consists in making `since` accept a standard time value and
streaming the changes started right before that time value based on the known
time-seq intervals. The time format of the since parameter is
YYYY-MM-DDTHH:MM:SSZ. It's valid as either an ISO 8601 or an RFC 3339 format.
From API design point of view this feature can be regarded as an extension to
the other `since` values like `now` or `0`.
Implementation-wise the change is treated similarly how we treat the `now`
special value: before the changes request starts, we translate the time value
to a proper `since` sequence. After that, we continue on with that regular
sequence as if nothing special happened. Consequently, the shape of the emitted
result is exactly the same as any previous change sequences. This is an extra
"plus" for consistency and compatibility.
To get a feel for the feature, I created a small db and updated it every few
hours during the day:
`http get $DB/db/_time_seq`
```
{
"00000000-ffffffff": {
"[email protected]": [
["2025-07-21T01:00:00Z", 15],
["2025-07-21T05:00:00Z", 2]
["2025-07-21T19:00:00Z", 9],
["2025-07-21T20:00:00Z", 5],
["2025-07-21T21:00:00Z", 70]
["2025-07-21T22:00:00Z", 10]
]
}
}
```
Change feed with `since=2025-07-21T22:00:00Z` will return documents changed
since that last hour only:
```
% http get $DB/db/_changes'?since=2025-07-21T22:00:00Z' | jq -r '.results[].id'
101
102
103
104
105
106
107
108
109
110
```
Even the somewhat obscure `since_seq` replication parameter should work, so we
can replicate from a particular point in time:
```
% http post 'http://adm:pass@localhost:15984/_replicate' \
source:='"http://adm:pass@localhost:15984/db"' \
target:='"http://adm:pass@localhost:15984/tgt"' \
since_seq:='"2025-07-21T22:00:00Z"'
{
"history": [
{
"bulk_get_attempts": 10,
"bulk_get_docs": 10,
"doc_write_failures": 0,
"docs_read": 10,
"docs_written": 10,
"end_last_seq": "111-g1AAAABLeJzLYWBgYMxgTmHgz8tPSTV0MDQy1zMAQsMcoARTIkMeC8N_IMjKYE7MzwUKsacaG6UYGSVhasgCALN1Ews",
"end_time": "Mon, 21 Jul 2025 22:11:59 GMT",
"missing_checked": 10,
"missing_found": 10,
"recorded_seq": "111-g1AAAABLeJzLYWBgYMxgTmHgz8tPSTV0MDQy1zMAQsMcoARTIkMeC8N_IMjKYE7MzwUKsacaG6UYGSVhasgCALN1Ews",
"session_id": "19252b97e34088aeaaa6cde6694a419f",
"start_last_seq": "2025-07-21T22:00:00Z",
"start_time": "Mon, 21 Jul 2025 22:11:55 GMT"
}
],
"ok": true,
"replication_id_version": 4,
"session_id": "19252b97e34088aeaaa6cde6694a419f",
"source_last_seq": "111-g1AAAABLeJzLYWBgYMxgTmHgz8tPSTV0MDQy1zMAQsMcoARTIkMeC8N_IMjKYE7MzwUKsacaG6UYGSVhasgCALN1Ews"
}
```
The target db now has only documents written in that last hour:
```
% http $DB/tgt/_all_docs | jq -r '.rows[].id'
101
102
103
104
105
106
107
108
109
110
```1 parent a74b514 commit e50f3ac
File tree
3 files changed
+115
-14
lines changed- src
- chttpd
- src
- test/eunit
- fabric/src
3 files changed
+115
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
875 | | - | |
876 | | - | |
| 875 | + | |
| 876 | + | |
877 | 877 | | |
878 | 878 | | |
879 | 879 | | |
880 | | - | |
881 | | - | |
| 880 | + | |
882 | 881 | | |
883 | 882 | | |
884 | | - | |
| 883 | + | |
885 | 884 | | |
886 | | - | |
| 885 | + | |
887 | 886 | | |
888 | 887 | | |
889 | 888 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | | - | |
| 113 | + | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| |||
493 | 495 | | |
494 | 496 | | |
495 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
496 | 589 | | |
497 | 590 | | |
498 | 591 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | | - | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
372 | 379 | | |
373 | 380 | | |
374 | 381 | | |
| |||
728 | 735 | | |
729 | 736 | | |
730 | 737 | | |
731 | | - | |
| 738 | + | |
732 | 739 | | |
733 | | - | |
| 740 | + | |
734 | 741 | | |
735 | | - | |
| 742 | + | |
736 | 743 | | |
737 | 744 | | |
738 | 745 | | |
| |||
741 | 748 | | |
742 | 749 | | |
743 | 750 | | |
744 | | - | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
745 | 754 | | |
746 | 755 | | |
747 | 756 | | |
| |||
0 commit comments