Skip to content

Commit eeea9c8

Browse files
DOC-11859 maxTTL improvements
1 parent 307c960 commit eeea9c8

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

modules/concept-docs/pages/data-durability-acid-transactions.adoc

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
= Data Modelling, Durability, and Consistency
2-
// :page-aliases:
32
// :page-aliases: durability-replication-failure-considerations.adoc
43
:description: Performance, availability, consistency -- balance your priorities, and model your data to achieve these goals.
54
: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)]
96

107
// Note to editors
118
//
@@ -61,7 +58,7 @@ Couchbase stores data in _documents_, and this is the atomic....
6158
////
6259

6360
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.
6562
Here we hope to keep it _relatively_ simple, with a look at which Couchbase features give you which guarantees,
6663
when you may prefer to use them, and -- perhaps equally important, though sometimes overlooked --
6764
what is the performance cost of these choices.
@@ -215,7 +212,7 @@ xref:concept-docs:transactions.adoc[multi-document ACID transactions].
215212

216213
== Concurrent Document Mutations
217214

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.
219216
It helps avoid and control potential race conditions in which some mutations may be inadvertently lost or overridden by mutations made by other clients.
220217

221218
=== Performance considerations
@@ -248,27 +245,42 @@ xref:howtos:concurrent-document-mutations.adoc#pessimistic-locking[Pessimistic L
248245

249246

250247

251-
////
248+
252249
== Expiration
253250

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.
256255

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.
257259

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.
258263

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.
259268

269+
// TODO check they all use MAX32INT -- 2147483648 seconds
260270

271+
=== Collection No-Expiry Option
261272

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].
264275

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`.
269283

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-
////
272284

273285

274286

0 commit comments

Comments
 (0)