I did what I suggested earlier and measured it instead of arguing about it. 
Method: I picked one store (us1, s0) on one of my nodes and took 150 of its 3037 non-TTL log files, spread evenly by log id (= roughly evenly over time). That’s 161 GB in total. A small read-only script walks the 64-byte record footers of each log backwards, the same way fsck does. It then checks every record against the hashtbl: still referenced → alive (trash counts as alive), not referenced → dead. The created field of each record gives the piece age.
Dead share by piece age:
| piece age |
all logs |
“upload” logs |
“mixed” logs |
| 0–30 days |
15.5 % |
15.1 % |
(too little data) |
| 30–90 days |
18.7 % |
21.6 % |
5.8 % |
| 90–180 days |
14.8 % |
19.0 % |
11.1 % |
| 180–365 days |
12.9 % |
20.1 % |
11.4 % |
| 1–2 years |
13.2 % |
(too little data) |
13.6 % |
“Upload” = 80 % of the pieces in the log are within 14 days of each other (filled by direct uploads), 68 logs, 18.5 % dead overall. “Mixed” = everything else (migration/compaction output), 82 logs, 12.2 % dead overall.
So young pieces die somewhat more often, but not by much. The mixed logs full of 1–2 year old pieces still carry ~13 % dead data. Moving fresh uploads into separate gen1 logs would not clean that up. If anything, the old buckets are underestimated, because dead old pieces had more time to get compacted away already.
Where the dead bytes are, per log:
| dead share of the log |
logs |
share of all dead bytes |
| 0–10 % |
56 |
8 % |
| 10–20 % |
41 |
28 % |
| 20–30 % |
36 |
38 % |
| 30–40 % |
16 |
24 % |
| ≥ 40 % |
1 |
2 % |
90 % of the dead bytes sit in logs that are still 60–90 % alive. With the default alive-fraction: 0.25 and probability-power: 2, the chance of such a log being picked per compaction run is ((0.25/0.75) * (1-alive)/alive)^2, i.e. between 0.7 % and 5 %. These logs are effectively never rewritten. Across all my nodes DataReclaimable adds up to about 15 % of the log size, so it’s not a small amount.
My takeaway: the problem is less that ages are mixed and more where the selection threshold sits. Separating log classes would not change much here. I have just started a test with hashstore.compaction.alive-fraction: 0.5 on two nodes (two other nodes as control). That raises the per-run probability for 60–90 % alive logs to roughly 6–44 %. The price is more rewrite IO, about 3 GB written per 1 GB reclaimed. I’ll report back in a week or two with how fast DataReclaimable goes down and what it does to disk utilization and success rates.
Caveat: one store on one node. Happy to see numbers from other nodes, the script is below. It is read-only and runs at idle IO priority (nice -n19 ionice -c3 python3 logage.py <store dir> 150 out.csv), about 15 s per log on my HDDs.
logage.py
#!/usr/bin/env python3
# Read-only analysis of a hashstore store: for a sample of log files, walk the record footers
# backwards and classify each record as alive / trash / dead by comparing with the hashtbl.
# usage: logage.py <store dir (…/<sat>/s0)> <nsample> <out.csv>
import os, sys, glob, struct, time, collections
store, nsample, out = sys.argv[1], int(sys.argv[2]), sys.argv[3]
REC = 64
def parse(b):
return dict(
offset=int.from_bytes(b[32:38], "little"),
log=int.from_bytes(b[38:46], "little"),
length=int.from_bytes(b[46:50], "little"),
created=int.from_bytes(b[50:53], "little") & 0x7FFFFF,
expires=int.from_bytes(b[53:56], "little"),
)
logs = {}
for p in glob.glob(os.path.join(store, "??", "log-*")):
_, lid, ttl = os.path.basename(p).split("-")
if int(ttl, 16) == 0:
logs[int(lid, 16)] = p
ids = sorted(logs)
sample = set(ids[::max(1, len(ids) // nsample)][:nsample])
tbl = sorted(glob.glob(os.path.join(store, "meta", "hashtbl-*")))[-1]
table = collections.defaultdict(dict)
with open(tbl, "rb") as fh:
fh.seek(4096)
while chunk := fh.read(64 << 20):
chunk = chunk[: len(chunk) // REC * REC]
for i, (lid,) in enumerate(struct.iter_unpack("<38xQ18x", chunk)):
if lid in sample:
r = parse(chunk[i * REC:(i + 1) * REC])
if r["length"]:
table[lid][r["offset"]] = r["expires"]
with open(out, "w") as w:
w.write("log,log_bytes,state,created,length\n")
for lid in sorted(sample):
try:
fd = os.open(logs[lid], os.O_RDONLY)
except FileNotFoundError:
continue
size = os.fstat(fd).st_size
alive = table.get(lid, {})
pos, bad = size - REC, 0
while pos >= 0 and bad <= (1 << 20):
r = parse(os.pread(fd, REC, pos))
if r["log"] != lid or r["offset"] + r["length"] != pos:
pos, bad = pos - 1, bad + 1
continue
exp = alive.get(r["offset"])
state = "dead" if exp is None else ("trash" if exp & 1 else "alive")
w.write(f"{lid},{size},{state},{r['created']},{r['length']}\n")
pos = r["offset"] - REC
os.close(fd)