|
1 | 1 | = Data Modelling, Durability, and Consistency
|
2 |
| -// :page-aliases: |
3 | 2 | // :page-aliases: durability-replication-failure-considerations.adoc
|
4 | 3 | :description: Performance, availability, consistency -- balance your priorities, and model your data to achieve these goals.
|
5 | 4 | :page-toclevels: 2
|
6 |
| -// :anyreplica-api: pass:q[https://docs.couchbase.com/sdk-api/couchbase-scala-client/com/couchbase/client/scala/Collection.html#getAnyReplica(id:String,options:com.couchbase.client.scala.kv.GetAnyReplicaOptions):scala.util.Try[com.couchbase.client.scala.kv.GetReplicaResult] |
7 |
| -// :anyreplica-api: https://docs.couchbase.com/sdk-api/couchbase-scala-client/com/couchbase/client/scala/Collection.html |
8 |
| - |
| 5 | +:anyreplica-api: pass:q[https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/AsyncCollection.html#getAnyReplica(java.lang.String,com.couchbase.client.java.kv.GetAnyReplicaOptions)] |
9 | 6 |
|
10 | 7 | // Note to editors
|
11 | 8 | //
|
@@ -61,7 +58,7 @@ Couchbase stores data in _documents_, and this is the atomic....
|
61 | 58 | ////
|
62 | 59 |
|
63 | 60 | Designing an application to offer guarantees of durability or consistency in a networked environment is hard.
|
64 |
| -The newcomer to the area has to wrestle with concepts like https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/[CAP Theorum] and the https://en.wikipedia.org/wiki/Isolation_(database_systems)[many possible interpretations] of ACID transactions. |
| 61 | +The newcomer to the area has to wrestle with concepts like https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/[CAP Theorum^] and the https://en.wikipedia.org/wiki/Isolation_(database_systems)[many possible interpretations^] of ACID transactions. |
65 | 62 | Here we hope to keep it _relatively_ simple, with a look at which Couchbase features give you which guarantees,
|
66 | 63 | when you may prefer to use them, and -- perhaps equally important, though sometimes overlooked --
|
67 | 64 | what is the performance cost of these choices.
|
@@ -215,7 +212,7 @@ xref:concept-docs:transactions.adoc[multi-document ACID transactions].
|
215 | 212 |
|
216 | 213 | == Concurrent Document Mutations
|
217 | 214 |
|
218 |
| -You can use the CAS value to control how concurrent document modifications are handled. |
| 215 | +You can use the CAS (Compare and Swap) value to control how concurrent document modifications are handled. |
219 | 216 | It helps avoid and control potential race conditions in which some mutations may be inadvertently lost or overridden by mutations made by other clients.
|
220 | 217 |
|
221 | 218 | === Performance considerations
|
@@ -248,27 +245,42 @@ xref:howtos:concurrent-document-mutations.adoc#pessimistic-locking[Pessimistic L
|
248 | 245 |
|
249 | 246 |
|
250 | 247 |
|
251 |
| -//// |
| 248 | + |
252 | 249 | == Expiration
|
253 | 250 |
|
254 |
| -*TODO* MaxTTL |
255 |
| -//// |
| 251 | +The expiration setting for a document determines if and when it expires. |
| 252 | +When a document expires, Couchbase Server removes it. |
| 253 | +You can set a maximum time to live (`maxTTL`) value on buckets and collections that imposes a default expiration on their documents. |
| 254 | +It also imposes an upper limit on explicitly-set expiration times. |
256 | 255 |
|
| 256 | +You can set an expiration value on an individual document either when you create it or when you mutate it. |
| 257 | +Set the expiration to the number of seconds the document should exist before Couchbase Server automatically removes it. |
| 258 | +You can change this value later in case you want extend the life of the document. |
257 | 259 |
|
| 260 | +As there could be cost implications for storing ephemeral data past its usable life -- |
| 261 | +or even legal implications about keeping data under GDPR and other privacy legislation -- |
| 262 | +you should be clear about the interactions between setting `maxTTL` at different levels can have. |
258 | 263 |
|
| 264 | +For example, setting a collection's `maxTTL` to `0` (the default) means it will inherit the bucket's `maxTTL` value; |
| 265 | +setting a bucket's `maxTTL` to `0` (the default) means it will never expire. |
| 266 | +The table in the xref:{version-server}@server:learn:data/expiration.adoc#expiration-setting-priorities[expiration documentation] |
| 267 | +covers the interaction between a document’s expiration setting and the `maxTTL` settings of the collection and bucket that contain it. |
259 | 268 |
|
| 269 | +// TODO check they all use MAX32INT -- 2147483648 seconds |
260 | 270 |
|
| 271 | +=== Collection No-Expiry Option |
261 | 272 |
|
262 |
| -//// |
263 |
| -TTL |
| 273 | +From Java SDK 3.5.3 with Capella (and self-managed Server from 7.6.0), setting a `maxTTL` of `-1` on a collection will prevent it from expiring, even when its containing bucket has reached expiry time. |
| 274 | +Again, see the table in the xref:{version-server}@server:learn:data/expiration.adoc#expiration-setting-priorities[expiration documentation]. |
264 | 275 |
|
265 |
| -DOC-11679 |
266 |
| - |
267 |
| -Re: Information on maxTTL for collections is not accurate |
268 |
| -The summary of "Document do not expire" is actually incorrect. After I did some testing, it turns out that documents *can* expire within collections and buckets that have maxTTL=0 if you set the document's expiration to a positive value. |
| 276 | +=== Changing a Document, but Not the Expiry |
| 277 | + |
| 278 | +By default, changing a document also changes its expiry. |
| 279 | +If you do not pass a value for expiry, the document does not expire, even if the document previously had an expiry. If this is not what you want, you must tell Couchbase to keep the document’s expiry. |
| 280 | + |
| 281 | +With the mutation operation on a document (say a `replace` or an `upsert`), use `preserveExpiry = true` -- |
| 282 | +and consider using optimistic locking if two threads could be changing the same document and one is not necessarily passing in `preserveExpiry = true`. |
269 | 283 |
|
270 |
| -Instead of talking about maxTTL in terms of documents expiring or not expiring, I believe we should discuss maxTTL's effect on a document's expiration setting: a non-zero value as sets a default expiration value for all documents contained in the bucket/collection (actually, I believe this is all newly-created documents . Setting maxTTL on a bucket or collection does not automatically change the expiration of existing documents, from what I have seen). It also sets the upper bound on a the expiration value you can set in a document directly. The actual expiration time is set by the document's expiration setting. |
271 |
| -//// |
272 | 284 |
|
273 | 285 |
|
274 | 286 |
|
|
0 commit comments