Commit cb5e711
authored
Make subscribe durable (#3894)
# Description of Changes
With the addition of module-defined views, subscriptions are no longer
read-only as they may invoke view materialization.
The way this works is that a subscription starts off as a mutable
transaction, materializes views if necessary, and then downgrades to a
read-only transaction to evaluate the subscription.
Before this patch, we were calling `commit_downgrade` directly on the
`MutTxId` in order to downgrade the transaction. This would update the
in-memory `CommittedState`, but it wouldn't make the transaction
durable.
This would result in us incrementing the transaction offset of the
in-memory `CommittedState` without writing anything to the commitlog.
This in turn would invalidate snapshots as they would be pointing
further ahead into the commitlog than they should, and so when replaying
from a snapshot we would potentially skip over commits that were not
included in the snapshot.
This patch changes those call sites to use
`RelationalDB::commit_tx_downgrade` which both updates the in-memory
state **and** makes the transaction durable.
**NOTE:** The fact that views are materialized is purely an
implementation detail at this point in time. And technically view tables
are ephemeral meaning they are not persisted to the commitlog. So the
real bug here was that we were updating the tx offset of the in-memory
committed state at all. This is technically fixed by
#3884 and so after
#3884 lands this change
becomes a no-op. However, we still shouldn't be calling `commit` and
`commit_downgrade` directly on a `MutTxId` since in most cases it is
wrong to bypass the durability layer. And without this change, the bug
would still be present were view tables not ephemeral, which they may
not be at some point in the future.
# API and ABI breaking changes
None
# Expected complexity level and risk
1. The change itself is trivial, the bug is not.
# Testing
Adding an automated test for this is not so straightforward. First it's
view related which means we don't have many options apart from a smoke
test, but I don't believe the smoke tests have a mechanism for replaying
the commitlog.
If transaction offsets are supposed to be linear, without any gaps, then
it would be useful to assert that on each append, in which case we could
write a smoke test that would fail as soon as the offsets diverged.1 parent a7c605c commit cb5e711
6 files changed
Lines changed: 28 additions & 32 deletions
File tree
- crates
- core/src
- db
- sql
- subscription
- datastore/src/locking_tx_datastore
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
827 | 827 | | |
828 | 828 | | |
829 | 829 | | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
| 830 | + | |
835 | 831 | | |
836 | 832 | | |
837 | | - | |
838 | | - | |
839 | | - | |
| 833 | + | |
840 | 834 | | |
841 | 835 | | |
842 | 836 | | |
| |||
845 | 839 | | |
846 | 840 | | |
847 | 841 | | |
848 | | - | |
| 842 | + | |
849 | 843 | | |
850 | 844 | | |
851 | 845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
215 | 214 | | |
216 | 215 | | |
217 | 216 | | |
218 | | - | |
| 217 | + | |
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
222 | 221 | | |
223 | 222 | | |
224 | 223 | | |
225 | 224 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 225 | + | |
232 | 226 | | |
233 | 227 | | |
234 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1027 | 1027 | | |
1028 | 1028 | | |
1029 | 1029 | | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
| 1030 | + | |
1033 | 1031 | | |
1034 | 1032 | | |
1035 | 1033 | | |
| |||
1102 | 1100 | | |
1103 | 1101 | | |
1104 | 1102 | | |
1105 | | - | |
| 1103 | + | |
1106 | 1104 | | |
1107 | 1105 | | |
1108 | 1106 | | |
| |||
1136 | 1134 | | |
1137 | 1135 | | |
1138 | 1136 | | |
1139 | | - | |
| 1137 | + | |
1140 | 1138 | | |
1141 | 1139 | | |
1142 | 1140 | | |
| |||
1229 | 1227 | | |
1230 | 1228 | | |
1231 | 1229 | | |
1232 | | - | |
| 1230 | + | |
1233 | 1231 | | |
1234 | 1232 | | |
1235 | | - | |
| 1233 | + | |
1236 | 1234 | | |
1237 | 1235 | | |
1238 | 1236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1087 | 1087 | | |
1088 | 1088 | | |
1089 | 1089 | | |
1090 | | - | |
| 1090 | + | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
950 | 950 | | |
951 | 951 | | |
952 | 952 | | |
| 953 | + | |
| 954 | + | |
953 | 955 | | |
954 | 956 | | |
955 | 957 | | |
| |||
960 | 962 | | |
961 | 963 | | |
962 | 964 | | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
969 | 969 | | |
970 | 970 | | |
971 | 971 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1902 | 1902 | | |
1903 | 1903 | | |
1904 | 1904 | | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
1905 | 1910 | | |
1906 | 1911 | | |
1907 | 1912 | | |
| |||
1947 | 1952 | | |
1948 | 1953 | | |
1949 | 1954 | | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
1950 | 1960 | | |
1951 | 1961 | | |
1952 | 1962 | | |
1953 | 1963 | | |
1954 | | - | |
| 1964 | + | |
1955 | 1965 | | |
1956 | 1966 | | |
1957 | 1967 | | |
| |||
0 commit comments