[PATCH 07/10] Mark new segments as new, and don't write them to the persisted segment table until they are closed.

Martin Blix Grydeland martin at varnish-software.com
Wed Oct 10 16:27:20 CEST 2012


---
 bin/varnishd/storage/storage_persistent.c      |    6 ++++--
 bin/varnishd/storage/storage_persistent.h      |    1 +
 bin/varnishd/storage/storage_persistent_silo.c |    2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 429cd45..021c5e2 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -368,8 +368,8 @@ smp_save_segs(struct smp_sc *sc)
 	VTAILQ_FOREACH_SAFE(sg, &sc->segments, list, sg2) {
 		if (sg->nobj > 0)
 			break;
-		if (sg == sc->cur_seg)
-			continue;
+		if (sg->flags & SMP_SEG_NEW)
+			break;
 		VTAILQ_REMOVE(&sc->segments, sg, list);
 		LRU_Free(sg->lru);
 		FREE_OBJ(sg);
@@ -386,6 +386,8 @@ smp_save_segs(struct smp_sc *sc)
 	VTAILQ_FOREACH(sg, &sc->segments, list) {
 		assert(sg->p.offset < sc->mediasize);
 		assert(sg->p.offset + sg->p.length <= sc->mediasize);
+		if (sg->flags & SMP_SEG_NEW)
+			break;
 		*ss = sg->p;
 		ss++;
 		length += sizeof *ss;
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index e716c51..cb2fc82 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -87,6 +87,7 @@ struct smp_seg {
 	unsigned		flags;
 #define SMP_SEG_MUSTLOAD	(1 << 0)
 #define SMP_SEG_LOADED		(1 << 1)
+#define SMP_SEG_NEW		(1 << 2)
 
 	uint32_t		nobj;		/* Number of objects */
 	uint32_t		nalloc;		/* Allocations */
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 9dd827e..981d1c6 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -176,6 +176,7 @@ smp_new_seg(struct smp_sc *sc)
 		return;
 	*sg = tmpsg;
 	sg->lru = LRU_Alloc();
+	sg->flags |= SMP_SEG_NEW;
 	CHECK_OBJ_NOTNULL(sg->lru, LRU_MAGIC);
 
 	sg->p.offset = IRNUP(sc, sg->p.offset);
@@ -266,6 +267,7 @@ smp_close_seg(struct smp_sc *sc, struct smp_seg *sg)
 	smp_sync_sign(sg->ctx);
 
 	/* Request sync of segment list */
+	sg->flags &= ~SMP_SEG_NEW;
 	smp_sync_segs(sc);
 	sc->free_offset = smp_segend(sg);
 }
-- 
1.7.9.5




More information about the varnish-dev mailing list