]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: rename kr_cache_sync -> kr_cache_commit
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 26 Feb 2019 10:57:59 +0000 (11:57 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 6 Mar 2019 12:03:28 +0000 (13:03 +0100)
Function originally called kr_cache_sync() was in fact responsible
for calling mdb_txn_commit() and not mdb_env_sync() which was confusing.

daemon/lua/kres-gen.lua
daemon/lua/kres-gen.sh
daemon/lua/kres.lua
lib/cache/api.c
lib/cache/api.h
lib/cache/cdb_api.h
lib/cache/cdb_lmdb.c
lib/resolve.c
lib/zonecut.c
tests/test_cache.c

index 62dba709869b99303de202d17b36834945cabdb9..994dd200259dbf90324a099a188c613cb7082f00 100644 (file)
@@ -333,7 +333,7 @@ int kr_cache_closest_apex(struct kr_cache *, const knot_dname_t *, _Bool, knot_d
 int kr_cache_insert_rr(struct kr_cache *, const knot_rrset_t *, const knot_rrset_t *, uint8_t, uint32_t);
 int kr_cache_remove(struct kr_cache *, const knot_dname_t *, uint16_t);
 int kr_cache_remove_subtree(struct kr_cache *, const knot_dname_t *, _Bool, int);
-int kr_cache_sync(struct kr_cache *);
+int kr_cache_commit(struct kr_cache *);
 typedef struct {
        uint8_t bitmap[32];
        uint8_t length;
index ea0f7af636b581272d3287e8bfdcd2f036fe2cd8..2f8206db4d8d58175e37bf8c3b4a7277a101a754 100755 (executable)
@@ -190,7 +190,7 @@ EOF
        kr_cache_insert_rr
        kr_cache_remove
        kr_cache_remove_subtree
-       kr_cache_sync
+       kr_cache_commit
 EOF
 
 
index 952f9e96a8581d87d993107679ca9f52eb9110ef..448624c1e346d0cdb8cc8f7155b624111d73059f 100644 (file)
@@ -842,7 +842,7 @@ ffi.metatype( kr_cache_t, {
                end,
                sync = function (self)
                        assert(ffi.istype(kr_cache_t, self))
-                       local ret = C.kr_cache_sync(self)
+                       local ret = C.kr_cache_commit(self)
                        if ret ~= 0 then return nil, knot_error_t(ret) end
                        return true
                end,
index c0591d653ed4853af9123129c74cbf1a6dc5d533..fd0360ae3057c84383d28c643644458974e67bab 100644 (file)
@@ -107,7 +107,7 @@ static int assert_right_version(struct kr_cache *cache)
                        ret = cache_op(cache, write, &key, &val, 1);
                }
        }
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
        return ret;
 }
 
@@ -157,13 +157,13 @@ void kr_cache_close(struct kr_cache *cache)
        kr_cache_emergency_file_to_remove = NULL;
 }
 
-int kr_cache_sync(struct kr_cache *cache)
+int kr_cache_commit(struct kr_cache *cache)
 {
        if (!cache_isvalid(cache)) {
                return kr_error(EINVAL);
        }
-       if (cache->api->sync) {
-               return cache_op(cache, sync);
+       if (cache->api->commit) {
+               return cache_op(cache, commit);
        }
        return kr_ok();
 }
@@ -336,7 +336,7 @@ int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
        }
 
        int ret = peek_nosync(ctx, pkt);
-       kr_cache_sync(&req->ctx->cache);
+       kr_cache_commit(&req->ctx->cache);
        return ret;
 }
 
@@ -414,7 +414,7 @@ finally:
        if (unauth_cnt) {
                VERBOSE_MSG(qry, "=> stashed also %d nonauth RRsets\n", unauth_cnt);
        };
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
        return ctx->state; /* we ignore cache-stashing errors */
 }
 
@@ -550,7 +550,7 @@ static ssize_t stash_rrset(struct kr_cache *cache, const struct kr_query *qry,
 
        #if 0 /* Occasionally useful when debugging some kinds of changes. */
        {
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
        knot_db_val_t val = { NULL, 0 };
        ret = cache_op(cache, read, &key, &val, 1);
        if (ret != kr_error(ENOENT)) { // ENOENT might happen in some edge case, I guess
@@ -879,7 +879,7 @@ int kr_cache_remove_subtree(struct kr_cache *cache, const knot_dname_t *name,
        }
        ret = cache->api->remove(cache->db, keys, count);
 cleanup:
-       kr_cache_sync(cache); /* Sync even after just kr_cache_match(). */
+       kr_cache_commit(cache); /* Sync even after just kr_cache_match(). */
        /* Free keys */
        while (--i >= 0) {
                free(keys[i].data);
index 61bf796a94d8467140f1bc99a9ecd0bf4481a11b..1fe3d081acad0e3bc75e9ecf7b2deb1a62d6ab4b 100644 (file)
@@ -81,7 +81,7 @@ void kr_cache_close(struct kr_cache *cache);
 
 /** Run after a row of operations to release transaction/lock if needed. */
 KR_EXPORT
-int kr_cache_sync(struct kr_cache *cache);
+int kr_cache_commit(struct kr_cache *cache);
 
 /**
  * Return true if cache is open and enabled.
index b9c91b09b4f62606017e0cbd4a3a315c10b1cf58..943256152163932d89fc0713d4652a006211f3a6 100644 (file)
@@ -39,7 +39,7 @@ struct kr_cdb_api {
        int (*clear)(knot_db_t *db);
 
        /** Run after a row of operations to release transaction/lock if needed. */
-       int (*sync)(knot_db_t *db);
+       int (*commit)(knot_db_t *db);
 
        /* Data access */
 
index 5b057b83c10e9b0b3be4fce61f5f282e16e47fd2..96a1fc1a6bd6432518aee14898a4708178ce2372 100644 (file)
@@ -148,7 +148,7 @@ static int txn_get(struct lmdb_env *env, MDB_txn **txn, bool rdonly)
        assert(env && txn);
        if (env->txn.rw) {
                /* Reuse the *open* RW txn even if only reading is requested.
-                * We leave the management of this to the cdb_sync command.
+                * We leave the management of this to the cdb_commit command.
                 * The user may e.g. want to do some reads between the writes. */
                *txn = env->txn.rw;
                return kr_ok();
@@ -185,7 +185,7 @@ static int txn_get(struct lmdb_env *env, MDB_txn **txn, bool rdonly)
        return kr_ok();
 }
 
-static int cdb_sync(knot_db_t *db)
+static int cdb_commit(knot_db_t *db)
 {
        struct lmdb_env *env = db;
        int ret = kr_ok();
@@ -209,7 +209,7 @@ static int txn_curs_get(struct lmdb_env *env, MDB_cursor **curs)
        }
        /* Only in a read-only txn; TODO: it's a bit messy/coupled */
        if (env->txn.rw) {
-               int ret = cdb_sync(env);
+               int ret = cdb_commit(env);
                if (ret) return ret;
        }
        MDB_txn *txn = NULL;
@@ -249,7 +249,7 @@ static void cdb_close_env(struct lmdb_env *env)
        assert(env && env->env);
 
        /* Get rid of any transactions. */
-       cdb_sync(env);
+       cdb_commit(env);
        free_txn_ro(env);
 
        mdb_env_sync(env->env, 1);
@@ -394,7 +394,7 @@ static int cdb_clear(knot_db_t *db)
                if (ret == kr_ok()) {
                        ret = lmdb_error(mdb_drop(txn, env->dbi, 0));
                        if (ret == kr_ok()) {
-                               ret = cdb_sync(db);
+                               ret = cdb_commit(db);
                        }
                        if (ret == kr_ok()) {
                                return ret;
@@ -404,7 +404,7 @@ static int cdb_clear(knot_db_t *db)
        }
 
        /* We are about to switch to a different file, so end all txns, to be sure. */
-       (void) cdb_sync(db);
+       (void) cdb_commit(db);
        free_txn_ro(db);
 
        /* Since there is no guarantee that there will be free
@@ -506,7 +506,7 @@ static int cdb_write(struct lmdb_env *env, MDB_txn **txn, const knot_db_val_t *k
 
        /* Try to recover from doing too much writing in a single transaction. */
        if (ret == MDB_TXN_FULL) {
-               ret = cdb_sync(env);
+               ret = cdb_commit(env);
                if (ret) {
                        ret = txn_get(env, txn, false);
                }
@@ -646,7 +646,7 @@ const struct kr_cdb_api *kr_cdb_lmdb(void)
 {
        static const struct kr_cdb_api api = {
                "lmdb",
-               cdb_init, cdb_deinit, cdb_count, cdb_clear, cdb_sync,
+               cdb_init, cdb_deinit, cdb_count, cdb_clear, cdb_commit,
                cdb_readv, cdb_writev, cdb_remove,
                cdb_match,
                cdb_read_leq
index 97dbb8328cf53a6dec57015a465b1c6988223043..ce21edf9941261d9c4f488bd1e992ebed6894254 100644 (file)
@@ -203,7 +203,7 @@ static void check_empty_nonterms(struct kr_query *qry, knot_pkt_t *pkt, struct k
                assert(target[0]);
                target = knot_wire_next_label(target, NULL);
        }
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 #endif
 }
 
index 5e54d9760073ecc4004f901651884c175ac5025e..248a4c5cea8b312ab6362ef07bb55cb8bd054964 100644 (file)
@@ -591,7 +591,7 @@ int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut,
                }
        }
 
-       kr_cache_sync(&ctx->cache);
+       kr_cache_commit(&ctx->cache);
        mm_free(cut->pool, qname);
        return ret;
 }
index 56e0305a85a8ca4a5594c7e08b833d5b3cfbe59c..7cfdb81cedb875c1d359a0b45c8dbb5f6a5d208b 100644 (file)
@@ -166,7 +166,7 @@ static void test_fake_invalid (void **state)
        ret = kr_cache_peek(cache, KR_CACHE_USER, dname, KNOT_RRTYPE_TSIG, &entry, 0);
        cache->api = api_saved;
        assert_int_not_equal(ret, 0);
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 static void test_fake_insert(void **state)
@@ -185,7 +185,7 @@ static void test_fake_insert(void **state)
                KNOT_RRTYPE_TSIG, &global_fake_ce, global_namedb_data);
        assert_int_equal(ret_cache_ins_ok, 0);
        assert_int_equal(ret_cache_ins_inval, KNOT_EINVAL);
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 /* Test invalid parameters and some api failures. */
@@ -219,7 +219,7 @@ static void test_invalid(void **state)
        assert_int_not_equal(kr_cache_remove(cache, KR_CACHE_RR, NULL, 0), 0);
        assert_int_not_equal(kr_cache_remove(NULL, 0, NULL, 0), 0);
        assert_int_not_equal(kr_cache_clear(NULL), 0);
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 /* Test cache write */
@@ -229,7 +229,7 @@ static void test_insert_rr(void **state)
        struct kr_cache *cache = (*state);
        int ret = kr_cache_insert_rr(cache, &global_rr, 0, 0, CACHE_TIME);
        assert_int_equal(ret, 0);
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 static void test_materialize(void **state)
@@ -281,7 +281,7 @@ static void test_query(void **state)
                assert_int_equal(query_ret, 0);
                assert_true(rr_equal);
        }
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 /* Test cache read (simulate aged entry) */
@@ -296,7 +296,7 @@ static void test_query_aged(void **state)
        struct kr_cache *cache = (*state);
        int ret = kr_cache_peek_rr(cache, &cache_rr, &rank, &flags, &timestamp);
        assert_int_equal(ret, kr_error(ESTALE));
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 /* Test cache removal */
@@ -313,7 +313,7 @@ static void test_remove(void **state)
        assert_int_equal(ret, 0);
        ret = kr_cache_peek_rr(cache, &cache_rr, &rank, &flags, &timestamp);
        assert_int_equal(ret, KNOT_ENOENT);
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 /* Test cache fill */
@@ -330,7 +330,7 @@ static void test_fill(void **state)
                if (ret != 0) {
                        break;
                }
-               ret = kr_cache_sync(cache);
+               ret = kr_cache_commit(cache);
                if (ret != 0) {
                        break;
                }
@@ -338,7 +338,7 @@ static void test_fill(void **state)
 
        /* Expect we run out of space */
        assert_int_equal(ret, kr_error(ENOSPC));
-       kr_cache_sync(cache);
+       kr_cache_commit(cache);
 }
 
 /* Test cache clear */