You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-4Lines changed: 34 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,40 @@ await db.doTn(tn => {
63
63
64
64
> **Note:** Running multiple operations in a single transaction is not necessarily faster than running them in separate transactions. Internally, operations on a single transaction would be serialized to ensure correctness. In the future, a more sophisticated locking might mitigate the need to serialize operations.
65
65
66
+
## Sparse sequences
67
+
68
+
It is recommended to enable _sparse sequences_ mode if possible.
69
+
70
+
Mutations in PouchDB databases are organized into sequences. By default, the adapter keeps these sequences strictly sequential (ie without gaps), just like LevelDB and other adapters. In a distributed database like FoundationDB, this would quickly become a bottleneck by making write concurrency impossible. Concurrent writes would conflict and need to be retried or canceled. Instead, the adapter can make use of FoundationDB commit versions. Versions are strictly monotonically increasing (like sequences) but not sequential. This should be, on its own, okay for most applications. The problem is that versions are big - 12 bytes each - so they don't fit into typical numeric data types. Instead, they are exposed as 24-character _hex strings_.
71
+
72
+
**Caveats:**
73
+
74
+
- Sparse sequences are not strictly sequential. This can cause issues when, for example, expecting `seq - 1` to exist for each reported `seq`.
75
+
- Sparse sequences are too large to fit into basic numeric data types. Instead, a 24-character hex strings are used. This can cause issues with PouchDB ecosystem and existing application code.
76
+
- Commit versions are, by definition, not finalized until the transaction is committed. When using multi-operation transactions, the sequences reported by the adapter are **non-final**. A transaction read version `+ 1` is used as a placeholder to ensure some level of robustness within the transaction. If the final sequences are needed outside the transaction, it's up to the userland code to replace the first 10 bytes (20 hex characters) with the actual commit version.
77
+
78
+
> **Changing the mode for an existing database is not supported.** But effort has been made to make it possible. If this is an important feature for you, please raise an issue.
79
+
80
+
Sparse sequences can be enabled by passing `sparseSeq: true` to PouchDB constructor:
81
+
82
+
```
83
+
const pouch = new PouchDB({
84
+
name: 'foo',
85
+
adapter: 'foundationdb',
86
+
db,
87
+
sparseSeq: true
88
+
});
89
+
90
+
db.changes({
91
+
since: 0n,
92
+
include_docs: true
93
+
})
94
+
```
95
+
96
+
> **Note:** It is generally safe to create multiple PouchDB instances with the same transaction, but make sure that all instances with the same `name` use the same version of this adapter.
97
+
98
+
> **Note:** Running multiple operations in a single transaction is not _necessarily_ faster than running them in separate transactions. Internally, operations on a single transaction would be serialized to ensure correctness. In the future, a more sophisticated locking might mitigate the need to serialize operations.
99
+
66
100
## Limitations
67
101
68
102
The adapter is subject to the fundamental [limitations](https://apple.github.io/foundationdb/known-limitations.html) of FoundationDB. In particular:
@@ -71,10 +105,6 @@ The adapter is subject to the fundamental [limitations](https://apple.github.io/
71
105
- Transactions can last at most 5 seconds from the first read.
72
106
- Write transactions have overall size limitations.
73
107
74
-
Also, there are non-FoundationDB-specific limitations:
75
-
76
-
- All write operations update "last update seq" and "doc count" keys, so concurrent write transactions are effectively guaranteed to conflict and wouldn't benefit from concurrency. This can also affect read operations, eg if they need to update views.
77
-
78
108
Some of these limitations are solvable. If these limitations are a significant problem for you, please create an issue.
0 commit comments