]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
prefetch wip
authorMarek Vavruša <marek.vavrusa@nic.cz>
Thu, 2 Jul 2015 20:09:22 +0000 (22:09 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 3 Jul 2015 22:25:52 +0000 (00:25 +0200)
daemon/ffimodule.c
modules/modules.mk
modules/prefetch/README.rst [new file with mode: 0644]
modules/prefetch/prefetch.lua [new file with mode: 0644]
modules/prefetch/prefetch.mk [new file with mode: 0644]

index 902991552768eefbffad78b7fc551cd29fea84e3..c6cc7788355121819aee9db3cc8c61379f55decb 100644 (file)
@@ -180,8 +180,8 @@ static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt)
 
 static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt)
 {
-       if (ctx->state & (KNOT_STATE_FAIL|KNOT_STATE_DONE)) {
-               return ctx->state; /* Already resolved/failed, skip */
+       if (ctx->state & (KNOT_STATE_FAIL)) {
+               return ctx->state; /* Already failed, skip */
        }
        LAYER_FFI_CALL(ctx, "produce");
        lua_pushlightuserdata(L, ctx->data);
index 1717714590fca54672094a6ee07cce5aae36e9a0..583e842f30b8cd3a25a7a17aac3e9f6c215bff82 100644 (file)
@@ -16,7 +16,8 @@ endif
 ifeq ($(HAS_lua),yes)
 modules_TARGETS += ketcd \
                    graphite \
-                   block
+                   block \
+                   prefetch
 endif
 
 # List of Golang modules
diff --git a/modules/prefetch/README.rst b/modules/prefetch/README.rst
new file mode 100644 (file)
index 0000000..fefb476
--- /dev/null
@@ -0,0 +1,4 @@
+.. _mod-prefetch:
+
+Prefetching
+-----------
diff --git a/modules/prefetch/prefetch.lua b/modules/prefetch/prefetch.lua
new file mode 100644 (file)
index 0000000..4035cad
--- /dev/null
@@ -0,0 +1,45 @@
+local prefetch = {
+       queue = {},
+       frequency = 2
+}
+
+-- @function Block layer implementation
+prefetch.layer = {
+       produce = function(state, req, pkt)
+               -- Schedule cached entries that are expiring soon
+               local qry = kres.query_current(req)
+               if not kres.query_has_flag(qry, kres.query.CACHED) then
+                       return state
+               end
+               local rr = pkt:get(kres.ANSWER, 0)
+               if rr and rr.ttl > 0 and rr.ttl < prefetch.frequency then
+                       local key = rr.owner..rr.type
+                       local val = prefetch.queue[key]
+                       if not val then
+                               prefetch.queue[key] = 1
+                       else
+                               prefetch.queue[key] = val + 1
+                       end
+               end
+               return state
+       end
+}
+
+function prefetch.batch(module)
+       for key, val in pairs(prefetch.queue) do
+               print('prefetching',key,val)
+       end
+       prefetch.queue = {}
+       -- @TODO: next batch interval
+       event.after(prefetch.frequency * sec, prefetch.batch)
+end
+
+function prefetch.init(module)
+       event.after(prefetch.frequency * sec, prefetch.batch)
+end
+
+function prefetch.deinit(module)
+       if prefetch.ev then event.cancel(prefetch.ev) end
+end
+
+return prefetch
diff --git a/modules/prefetch/prefetch.mk b/modules/prefetch/prefetch.mk
new file mode 100644 (file)
index 0000000..a486774
--- /dev/null
@@ -0,0 +1,2 @@
+prefetch_SOURCES := prefetch.lua
+$(call make_lua_module,prefetch)