shithub: neoventi

Download patch

ref: 09b5471a8feeda723b1fe2f951921a4302a312f0
parent: 368ded133c040ad7f2f9548e06457e3753662dee
author: Noam Preil <noam@pixelhero.dev>
date: Wed Sep 17 23:27:02 EDT 2025

reclaim space at the tail of the live arena, if corrupted by old-venti

--- a/arena.c
+++ b/arena.c
@@ -27,11 +27,13 @@
 vtarenasync(VtArena *arena)
 {
 	// First, check if the directory and the data log are in sync
-	usize n, m;
+	usize n, m, corruptchain;
 	char *buf, *ci;
 	u32int block, perblock, off;
 	u64int addr, goodaddr;
+	int good;
 	n = arena->arenastats.clumps;
+	corruptchain = 0;
 	fprint(2, "clumps: %d, %d\n", n, arena->indexstats.clumps);
 	if(n == arena->indexstats.clumps)
 		return 1;
@@ -54,18 +56,34 @@
 		}
 		off += ClumpInfoSize;
 		ci = &buf[off];
-		if(!arenarepair(arena, (u8int*)ci, addr)){
+		good = arenarepair(arena, (u8int*)ci, addr);
+		addr += (((u64int)(U16GET(ci + 1))) + 38);
+		if(!good){
 			fprint(2, "clump %d is broken, at address %llud: %r\n", m, addr);
+			corruptchain += 1;
 			// Skip. old venti creates corruption in some easy-to-repro cases
 			// (e.g. write, kill venti within a few seconds) and I don't need people
 			// complaining about it.
+		} else {
+			corruptchain = 0;
+			goodaddr = addr;
 		}
-		addr += (((u64int)(U16GET(ci + 1))) + 38);
 	}
+	if(addr != goodaddr){
+		assert(corruptchain > 0);
+		fprint(2, "corruption detected: the last %d clumps are corrupt. Dropping them.\n"
+				  "\taddr dropped from %llud to %llud\n",
+		corruptchain, addr, goodaddr);
+		addr = goodaddr;
+		arena->arenastats.clumps -= corruptchain;
+	}
 	if(arena->arenastats.used != addr){
 		fprint(2, "corrupt: found addr %d, expected %d", addr, arena->arenastats.used);
 		arena->arenastats.used = addr;
 	}
+	// TODO: we haven't updated indexstats->clumps, so this is safe, but we _do_
+	// need to be indexing these clumps.
+	vtarenawb(arena);
 	return 1;
 }
 
--- a/notebook
+++ b/notebook
@@ -3433,3 +3433,19 @@
 	- Queue the clump for indexing
 	- Advance to the next one
 - Index all queued clumps at once (possibly in parallel if it makes sense to do so)
+
+and, that's better:
+
+corruption detected: the last 211 clumps are corrupt. Dropping them, restoring indexed state.
+	addr dropped from 1571851 to 49190
+
+That's, what, 1.5MiB of disk space not permanently wasted because of this?
+
+And, after relaunching:
+
+Initializing neoventi build 5... Resuming: used 49190, block 6, blocksize 8192, offset 38
+clumps: 1, 0
+blockbase 00794624
+initialized, launching server...overridding tcp address for simultaneous testing! tcp!*!14011...
+
+The issue is completely gone. Can we rewrite that data now using neoventi, and access with venti?
--