# Archived Segcache TTL: requested lifetime and segment lifetime

A request's expiry argument does not by itself establish the read deadline in
the archived C Segcache implementation. A controlled-clock native experiment
observed a value at the requested deadline for a relative TTL of 8 seconds,
then a miss one second later. An older shared segment could instead expire
the same requested TTL early.

**Scope:** commit `0abdfeed3031b5cf441f07d35ad2aeb3d870789d`, an
[unmaintained C archive](https://github.com/Thesys-lab/Segcache/tree/0abdfeed3031b5cf441f07d35ad2aeb3d870789d).
These are deterministic native request-path observations, not network timing
or a claim about the later Rust implementation. Background reclamation was
stopped before clock injection. Prepared and replayed on 2026-11-19.

## Observed boundaries

All times in the table are integer process seconds. The test key is written
at second 100. A priming write creates the older segment where specified.

| Input | Segment age at write | Requested deadline | Segment deadline | Native read observation |
| --- | ---: | ---: | ---: | --- |
| Relative TTL 7 | 0 | 107 | 101 | Miss at 101 |
| Relative TTL 8 | 0 | 108 | 109 | Value at 108, miss at 109 |
| Relative TTL 9 | 0 | 109 | 109 | Miss at 109 |
| Relative TTL 15 | 0 | 115 | 109 | Miss at 109 |
| Relative TTL 8 | 1 | 108 | 108 | Miss at 108 |
| Relative TTL 8 | 4 | 108 | 105 | Miss at 105 |
| Absolute expiry 1700000108 | 0 | 108 | 109 | Value at 108, miss at 109 |
| Absolute expiry 1700000100 | 0 | 100 | 8355941 | Value at 100 and 101 |
| Client expiry argument 0 | 0 | INT32_MAX sentinel | 8355941 | Finite segment deadline |

The reference Unix start is 1700000000. Large times were reached by advancing
the injected clock, not by waiting for days. A further past-one-second case
is retained in the raw evidence; its result depends on the tested compiler's
signed right shift and is not a portable C guarantee.

## How the path produces the result

The native ASCII parser preserves the expiry argument. The time conversion
maps relative arguments to process time and large arguments to Unix-based
process time; client zero uses an INT32_MAX sentinel. Allocation subtracts
current process time and continues even for a nonpositive duration.

The bucket initializer uses an interval multiple plus one. A fresh segment
with input TTL 8 therefore receives a segment TTL of 9. Objects appended to
an older segment inherit its earlier creation time. An already-due absolute
expiry can produce internal duration zero, which selects the final bucket.
Internal zero is not the same input as client argument zero.

Read eligibility and physical reclamation are also separate. The ordinary
access predicate rejects at the segment deadline; the background predicate
requires a deadline strictly earlier than current time minus two seconds.
Background scheduling, flushes and references can further affect reclamation.
This experiment isolates the read path, not that reclamation schedule.

The [NSDI 2021 paper](https://www.usenix.org/system/files/nsdi21-yang.pdf),
sections 3.1 and 3.4, describes downward TTL approximation and shared expiration.
Those design statements do not establish every boundary in a later source
revision. Its [official erratum](https://www.usenix.org/system/files/nsdi21_errata_yang_juncheng-1.pdf)
corrects an LFU assertion, not TTL behavior.
The [reference memcached protocol](https://docs.memcached.org/protocols/basic/)
distinguishes zero, relative expiry up to 30 days, and larger Unix timestamps;
that protocol description alone does not prove archive conformance.

## Method and limits

The probe links unmodified upstream parsing, request processing, allocation,
hash lookup and response composition. Full ASCII requests enter
`segcache_process_read`, and composed ASCII replies are recorded. It uses
32 MiB of cache heap, disables capacity eviction, and stops and joins the
reclamation thread before writes. Each scenario runs in a fresh process.

There are 26 selected scenarios, two repetitions in each Debug/Release build:
104 native executions, not 104 independent production samples. GCC 13.3.0
on x86-64 Linux was used. A separate publishing-agent replay repeated those
104 executions and matched every scenario record in both build modes.
This is a repeatability check, not independent external scientific review.

Every original archive file is compared to the pinned tarball before and
after each capture. The 729-file manifest and generated configuration hash
are recorded. A separate unmodified loopback-server attempt failed at startup
with zero successful responses. There is no successful network confirmation.
No frequency, workload prevalence, performance, durability, legal compliance
or current-version exposure is estimated.

The practical lesson is to test requested expiry, read eligibility and memory
reclamation separately. A membership hit in a policy trace is not sufficient
evidence that a returned value meets an application's freshness contract.
These observations do not invalidate the paper's performance evaluation.

## Reproduce and inspect

Download [the complete package](https://hesela.dev/research/segcache-ttl/segcache-ttl.zip).
It contains this guide, the [source ledger](https://hesela.dev/research/segcache-ttl/SOURCES.md),
probe, replay script, validators and frozen evidence. It does not redistribute
the upstream source archive or paper.

Run from the extracted directory:

```sh
python3 -B verify.py
python3 -B -m unittest -v test_verify.py
python3 -B -O -m unittest -v test_verify.py
curl -fL https://codeload.github.com/Thesys-lab/Segcache/tar.gz/0abdfeed3031b5cf441f07d35ad2aeb3d870789d -o source.tar.gz
tar -xzf source.tar.gz
python3 -B replay.py --source Segcache-0abdfeed3031b5cf441f07d35ad2aeb3d870789d --archive source.tar.gz --output fresh-debug --build-type Debug
python3 -B replay.py --source Segcache-0abdfeed3031b5cf441f07d35ad2aeb3d870789d --archive source.tar.gz --output fresh-release --build-type Release
```

Native replay requires Linux, a C compiler, CMake, make, pthreads and the
usual C development headers. Do not run both builds concurrently: upstream
CMake writes a generated header into the source tree. The capture validator
checks the archive SHA-256 before compilation. Read the scripts before running
third-party build code. The frozen-evidence tests do not require a compiler.

[Return to the Segcache definition](https://hesela.dev/terms/segcache/).
