]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: remove unsupported prune() operation from API
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 26 Feb 2019 08:20:31 +0000 (09:20 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 6 Mar 2019 12:03:28 +0000 (13:03 +0100)
Cache cleaning needs to be done using separate mechanism
because cleaning it from worker process does not fit well into our
processing model. It is going to be a separate daemon.

daemon/bindings/cache.c
lib/cache/cdb_api.h
lib/cache/cdb_lmdb.c

index 5e780ecf683423da0a3e3035c0794c85f315f93a..2574a7cc099ee39565a19167cdcf1668b08ee103 100644 (file)
@@ -252,26 +252,6 @@ static int cache_prefixed(struct kr_cache *cache, const char *prefix, bool exact
 }
 #endif
 
-/** Prune expired/invalid records. */
-static int cache_prune(lua_State *L)
-{
-       struct kr_cache *cache = cache_assert_open(L);
-       /* Check parameters */
-       int prune_max = UINT16_MAX;
-       int n = lua_gettop(L);
-       if (n >= 1 && lua_isnumber(L, 1))
-               prune_max = lua_tointeger(L, 1);
-
-       /* Check if API supports pruning. */
-       int ret = kr_error(ENOSYS);
-       if (cache->api->prune)
-               ret = cache->api->prune(cache->db, prune_max);
-       /* Commit and format result. */
-       lua_error_maybe(L, ret);
-       lua_pushinteger(L, ret);
-       return 1;
-}
-
 /** Clear everything. */
 static int cache_clear_everything(lua_State *L)
 {
@@ -466,7 +446,6 @@ int kr_bindings_cache(lua_State *L)
                { "checkpoint", cache_checkpoint },
                { "open",   cache_open },
                { "close",  cache_close },
-               { "prune",  cache_prune },
                { "clear_everything", cache_clear_everything },
                { "get",     cache_get },
                { "max_ttl", cache_max_ttl },
index 814a5f5ddf738faa974b9e08f34138a83de73175..b9c91b09b4f62606017e0cbd4a3a315c10b1cf58 100644 (file)
@@ -58,8 +58,6 @@ struct kr_cdb_api {
        /** Find key-value pairs that are prefixed by the given key, limited by maxcount.
         * \return the number of pairs or negative error. */
        int (*match)(knot_db_t *db, knot_db_val_t *key, knot_db_val_t keyval[][2], int maxcount);
-       /** Not implemented ATM. */
-       int (*prune)(knot_db_t *db, int maxcount);
 
        /** Less-or-equal search (lexicographic ordering).
         * On successful return, key->data and val->data point to DB-owned data.
index 621d2e881c867eedae10bdbece0c4863ff7a8ca3..5b057b83c10e9b0b3be4fce61f5f282e16e47fd2 100644 (file)
@@ -613,60 +613,6 @@ static int cdb_match(knot_db_t *db, knot_db_val_t *key, knot_db_val_t keyval[][2
 }
 
 
-static int cdb_prune(knot_db_t *db, int limit)
-{
-       return -1;
-#if 0
-       /* Sync in-flight transactions */
-       cdb_sync(db);
-
-       /* Prune old records */
-       struct lmdb_env *env = db;
-       MDB_txn *txn = NULL;
-       int ret = txn_get(env, &txn, false);
-       if (ret != 0) {
-               return ret;
-       }
-
-       MDB_cursor *cur = NULL;
-       ret = mdb_cursor_open(txn, env->dbi, &cur);
-       if (ret != 0) {
-               return lmdb_error(ret);
-       }
-
-       MDB_val cur_key, cur_val;
-       ret = mdb_cursor_get(cur, &cur_key, &cur_val, MDB_FIRST);
-       if (ret != 0) {
-               mdb_cursor_close(cur);
-               return lmdb_error(ret);
-       }
-
-       int results = 0;
-       struct timeval now;
-       gettimeofday(&now, NULL);
-       while (ret == 0 && results < limit) {
-               /* Ignore special namespaces. */
-               if (cur_key.mv_size < 2 || ((const char *)cur_key.mv_data)[0] == 'V') {
-                       ret = mdb_cursor_get(cur, &cur_key, &cur_val, MDB_NEXT);
-                       continue;
-               }
-               /* Check entry age. */
-               struct kr_cache_entry *entry = cur_val.mv_data;
-               if (entry->timestamp > now.tv_sec ||
-                       (now.tv_sec - entry->timestamp) < entry->ttl) {
-                       ret = mdb_cursor_get(cur, &cur_key, &cur_val, MDB_NEXT);
-                       continue;
-               }
-               /* Remove entry */
-               mdb_cursor_del(cur, 0);
-               ++results;
-               ret = mdb_cursor_get(cur, &cur_key, &cur_val, MDB_NEXT);
-       }
-       mdb_cursor_close(cur);
-       return ret < 0 ? ret : results;
-#endif
-}
-
 static int cdb_read_leq(knot_db_t *env, knot_db_val_t *key, knot_db_val_t *val)
 {
        assert(env && key && key->data && val);
@@ -702,7 +648,7 @@ const struct kr_cdb_api *kr_cdb_lmdb(void)
                "lmdb",
                cdb_init, cdb_deinit, cdb_count, cdb_clear, cdb_sync,
                cdb_readv, cdb_writev, cdb_remove,
-               cdb_match, cdb_prune,
+               cdb_match,
                cdb_read_leq
        };