Commit 2d8f9207 authored by Marek Vavruša's avatar Marek Vavruša

cache: implemented as namedb/lmdb backend

- removed excess copies in query, cache time tracking
- simple insert/replace semantics
- zero-copy query if TTL recalculation is not needed
- doc
parent 1093ce48
This diff is collapsed.
......@@ -16,22 +16,80 @@ limitations under the License.
#pragma once
#include <libknot/rrset.h>
#include <libknot/internal/namedb/namedb.h>
enum kr_cache_flag {
KR_CACHE_NOFLAG = 0,
KR_CACHE_RDONLY = 1 << 0
/*!
* \brief Serialized form of the RRSet with inception timestamp.
*/
struct kr_cache_rrset
{
uint32_t timestamp;
uint16_t count;
uint8_t data[];
};
struct kr_cache;
struct kr_txn;
/*!
* \brief Open/create persistent cache in given path.
* \param handle Path to existing directory where the DB should be created.
* \param mm Memory context.
* \return database instance or NULL
*/
namedb_t *kr_cache_open(const char *handle, mm_ctx_t *mm);
struct kr_cache *kr_cache_open(const char *handle, unsigned flags, mm_ctx_t *mm);
void kr_cache_close(struct kr_cache *cache);
/*!
* \brief Close persistent cache.
* \note This doesn't clear the data, just closes the connection to the database.
* \param cache database instance
*/
void kr_cache_close(namedb_t *cache);
struct kr_txn *kr_cache_txn_begin(struct kr_cache *cache, struct kr_txn *parent, unsigned flags, mm_ctx_t *mm);
int kr_cache_txn_commit(struct kr_txn *txn);
void kr_cache_txn_abort(struct kr_txn *txn);
/*!
* \brief Begin cache transaction (read-only or write).
*
* \param cache database instance
* \param txn transaction instance to be initialized (output)
* \param flags transaction flags (see namedb.h in libknot)
* \return KNOT_E*
*/
int kr_cache_txn_begin(namedb_t *cache, namedb_txn_t *txn, unsigned flags);
int kr_cache_query(struct kr_txn *txn, knot_rrset_t *rr);
int kr_cache_insert(struct kr_txn *txn, const knot_rrset_t *rr, unsigned flags);
int kr_cache_remove(struct kr_txn *txn, const knot_rrset_t *rr);
/*!
* \brief Commit existing transaction.
* \param txn transaction instance
* \return KNOT_E*
*/
int kr_cache_txn_commit(namedb_txn_t *txn);
/*!
* \brief Abort existing transaction instance.
* \param txn transaction instance
*/
void kr_cache_txn_abort(namedb_txn_t *txn);
/*!
* \brief Query the cache for given RRSet (name, type, class)
* \note The 'drift' is the time passed between the cache time of the RRSet and now (in seconds).
* \param txn transaction instance
* \param rr query RRSet (its rdataset may be changed depending on the result)
* \param timestamp current time (will be replaced with drift if successful)
* \return KNOT_E*
*/
int kr_cache_query(namedb_txn_t *txn, knot_rrset_t *rr, uint32_t *timestamp);
/*!
* \brief Insert RRSet into cache, replacing any existing data.
* \param txn transaction instance
* \param rr inserted RRSet
* \param timestamp current time
* \return KNOT_E*
*/
int kr_cache_insert(namedb_txn_t *txn, const knot_rrset_t *rr, uint32_t timestamp);
/*!
* \brief Remove RRSet from cache.
* \param txn transaction instance
* \param rr removed RRSet
* \return KNOT_E*
*/
int kr_cache_remove(namedb_txn_t *txn, const knot_rrset_t *rr);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment