The max TTL for an item is applied incorrectly if the max TTL exceeds 30 days.
Instead of the max TTL being applied as an offset from the current time, it is instead applied as an offset from when memcached started.
1. Start up Couchbase Server on a single node (this is time t start).
2. Create a bucket with max TTL of 2592001 (30 days + 1 second).
3. Create a document in the bucket with no expiry, e.g. from the UI (this is time t doc).
4. Check the expiry (via couch_dbdump, the UI etc).
Document has expiry of t doc + 2592001.
Document has expiry of t start + 2592001, every single document created in this bucket (with no explicit expiry set) has the exact same expiry, no matter what time they were created.
This happens because there is an issue in the method getExpiryParameters() (http://src.couchbase.org/source/xref/6.0.2/kv_engine/engines/ep/src/ep_engine.cc#2224):
Here, if the max ttl is greater than 30 days we have to convert it to an absolute time (based on Memcached's epoch), to do this we use ep_abs_time().
Below is the definition of mc_time_convert_to_abs_time() (http://src.couchbase.org/source/xref/6.0.2/kv_engine/daemon/mc_time.cc#181-183) which ep_abs_time() is mapped to:
This returns the memcached epoch (which is the time that memcached started) plus the relative time.
This means in the case above, we are setting the expiry to memcached start time plus the max ttl, instead of the current time.
The correct code for this case would instead be (to be consistent with other uses of ep_abs_time() within the codebase):