[master] a03e139 Add batch records as a cursor option to the VSM cursor

Martin Blix Grydeland martin at varnish-cache.org
Wed Oct 9 16:03:04 CEST 2013


commit a03e139afc50f782681e2c6485814316ba3f2c78
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Oct 9 13:46:26 2013 +0200

    Add batch records as a cursor option to the VSM cursor
    
    If the option isn't set, batch records are never returned from the cursor.
    
    If the option is set, batch records are reported, and the next call to
    the cursor will return the first record after the batch. Calling
    application will then need to know how to use VSL_NEXT pointer macros
    to extract the records in the batch.

diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h
index 5f30c0c..03d6e6c 100644
--- a/include/vapi/vsl.h
+++ b/include/vapi/vsl.h
@@ -202,6 +202,7 @@ void VSL_ResetError(struct VSL_data *vsl);
 	 */
 
 #define VSL_COPT_TAIL	(1 << 0)
+#define VSL_COPT_BATCH	(1 << 1)
 struct VSL_cursor *VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm,
     unsigned options);
        /*
@@ -210,6 +211,7 @@ struct VSL_cursor *VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm,
 	*
 	* Options:
 	*   VSL_COPT_TAIL	Start cursor at log tail
+	*   VSL_COPT_BATCH	Return batch records
 	*
 	* Return values:
 	* non-NULL: Pointer to cursor
diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index e030776..14634fe 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -172,6 +172,15 @@ vslc_vsm_next(struct VSL_cursor *cursor)
 
 		c->cursor.rec = c->next;
 		c->next.ptr = VSL_NEXT(c->next.ptr);
+		if (VSL_TAG(c->cursor.rec.ptr) == SLT__Batch) {
+			if (!(c->options & VSL_COPT_BATCH))
+				/* Skip the batch record */
+				continue;
+			/* Next call will point to the first record past
+			   the batch */
+			c->next.ptr +=
+			    VSL_WORDS(VSL_BATCHLEN(c->cursor.rec.ptr));
+		}
 		return (1);
 	}
 }
diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c
index 6912943..5038a89 100644
--- a/lib/libvarnishapi/vsl_dispatch.c
+++ b/lib/libvarnishapi/vsl_dispatch.c
@@ -1116,6 +1116,7 @@ vslq_raw(struct VSLQ *vslq, VSLQ_dispatch_f *func, void *priv)
 		vslq->raw.c.cursor.rec.ptr = NULL;
 		vslq->raw.trans.vxid = VSL_ID(vslq->raw.c.ptr);
 		vslq->raw.offset += VSL_NEXT(vslq->raw.c.ptr) - vslq->raw.c.ptr;
+		assert(VSL_TAG(vslq->raw.c.ptr) != SLT__Batch);
 	} while (VSL_TAG(vslq->raw.c.ptr) == SLT__Batch);
 
 	if (func == NULL)
@@ -1181,6 +1182,7 @@ vslq_next(struct VSLQ *vslq)
 		return (i);
 
 	tag = VSL_TAG(c->rec.ptr);
+	assert(tag != SLT__Batch);
 	if (tag == SLT__Batch) {
 		batch = 1;
 		vxid = VSL_BATCHID(c->rec.ptr);



More information about the varnish-commit mailing list