|
| 1 | +--- |
| 2 | +title: Durable LSNs |
| 3 | +keywords: durable, lsn |
| 4 | +sidebar: mydoc_sidebar |
| 5 | +permalink: durable_lsns.html |
| 6 | +--- |
| 7 | +# Durable LSNs |
| 8 | + |
| 9 | +## Coherency |
| 10 | + |
| 11 | +The leader-node in comdb2 commits a transaction locally and then blocks until |
| 12 | +that transaction has been applied to all of the cluster's replicants. This is |
| 13 | +known as "distributed commit". Replicants that cannot apply the transaction |
| 14 | +within a certain timeout are marked 'incoherent', and are not allowed to |
| 15 | +service new requests. |
| 16 | + |
| 17 | +A writing client is guaranteed to see the transaction it has just committed, |
| 18 | +because any node which hasn't applied the transaction will be marked |
| 19 | +incoherent, and will not handle new requests. This model preserves |
| 20 | +"reads-follows-writes" consistency. |
| 21 | + |
| 22 | +If a different client reads the database while a writing client is blocked in |
| 23 | +distributed commit, the reading-client will see the writer's transaction if |
| 24 | +that replicant has already applied it. Our coherency model does not guarantee |
| 25 | +visibility of the commit until the writing client regains control. While the |
| 26 | +writer is blocked, a reader might observe the effects of the transaction on |
| 27 | +replicant A, and then not see those effects on replicant B. |
| 28 | + |
| 29 | +## Durability |
| 30 | + |
| 31 | +A "durable" transaction cannot be unwound by a future leader. When the |
| 32 | +'elect\_highest\_committed\_gen' tunable is enabled, a transaction is |
| 33 | +considered durable once it has been applied to a quorum of the cluster's |
| 34 | +replicants. Because elections require a quorum of nodes to promote a new |
| 35 | +leader, this durability guarantee follows intuitively: once a transaction is |
| 36 | +replicated to a quorum, every future quorum will include at least one node |
| 37 | +which has applied it. The election process ensures that a node which has not |
| 38 | +applied the transaction cannot become the new leader. |
| 39 | + |
| 40 | +## Replicant Retry |
| 41 | + |
| 42 | +The 'replicant\_retry\_on\_not\_durable' tunable causes the replicant servicing |
| 43 | +the client request to retry any transaction that has not been replicated to a |
| 44 | +quorum. The retry is directed to the current cluster leader, which may change |
| 45 | +during course of the request. A non-durable transaction will be retried until |
| 46 | +it becomes durable, or until the retry count (controlled by |
| 47 | +'survive\_n\_master\_swings') is exhausted. |
| 48 | + |
| 49 | +If retries are exausted, and the 'hide\_non\_durable\_rcode' tunable is set to |
| 50 | +true, the client api will return the transaction's original rcode. If set to |
| 51 | +false, the client api will return a 402 error (CDB2ERR\_NOTDURABLE). |
| 52 | + |
| 53 | +## Metrics |
| 54 | + |
| 55 | +The leader keeps track of the total number of distributed commits as |
| 56 | +'distributed\_commits' in the comdb2\_metrics table. It also tracks the |
| 57 | +number of distributed commits that were not durable as 'not\_durable\_commits'. |
| 58 | +These metrics are collected regardless of whether durable-LSNs or the |
| 59 | +'replicant\_retry\_on\_not\_durable' tunable is enabled. |
| 60 | + |
0 commit comments