The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Simple rbtree based cache. More...
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/heap.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/value.h>
#include "../../rlm_cache.h"
Go to the source code of this file.
Data Structures | |
struct | rlm_cache_rb_entry_t |
struct | rlm_cache_rbtree_mutable_t |
struct | rlm_cache_rbtree_t |
Functions | |
static int | cache_acquire (void **handle, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request) |
Lock the rbtree. More... | |
static rlm_cache_entry_t * | cache_entry_alloc (UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request) |
Custom allocation function for the driver. More... | |
static int8_t | cache_entry_cmp (void const *one, void const *two) |
Compare two entries by key. More... | |
static uint64_t | cache_entry_count (UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle) |
Return the number of entries in the cache. More... | |
static cache_status_t | cache_entry_expire (UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, fr_value_box_t const *key) |
Free an entry and remove it from the data store. More... | |
static cache_status_t | cache_entry_find (rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, fr_value_box_t const *key) |
Locate a cache entry. More... | |
static cache_status_t | cache_entry_insert (rlm_cache_config_t const *config, void *instance, request_t *request, void *handle, rlm_cache_entry_t const *c) |
Insert a new entry into the data store. More... | |
static cache_status_t | cache_entry_set_ttl (UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, rlm_cache_entry_t *c) |
Update the TTL of an entry. More... | |
static int8_t | cache_heap_cmp (void const *one, void const *two) |
Compare two entries by expiry time. More... | |
static void | cache_release (UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED rlm_cache_handle_t *handle) |
Release an entry unlocking any mutexes. More... | |
static int | mod_detach (module_detach_ctx_t const *mctx) |
Cleanup a cache_rbtree instance. More... | |
static int | mod_instantiate (module_inst_ctx_t const *mctx) |
Create a new cache_rbtree instance. More... | |
Variables | |
rlm_cache_driver_t | rlm_cache_rbtree |
Simple rbtree based cache.
Definition in file rlm_cache_rbtree.c.
struct rlm_cache_rb_entry_t |
Definition at line 41 of file rlm_cache_rbtree.c.
Data Fields | ||
---|---|---|
rlm_cache_entry_t | fields | Entry data. |
fr_heap_index_t | heap_id | Offset used for expiry heap. |
fr_rb_node_t | node | Entry used for lookups. |
struct rlm_cache_rbtree_mutable_t |
Definition at line 30 of file rlm_cache_rbtree.c.
Data Fields | ||
---|---|---|
fr_rb_tree_t * | cache | Tree for looking up cache keys. |
fr_heap_t * | heap | For managing entry expiry. |
pthread_mutex_t | mutex | Protect the tree from multiple readers/writers. |
struct rlm_cache_rbtree_t |
Definition at line 37 of file rlm_cache_rbtree.c.
Data Fields | ||
---|---|---|
rlm_cache_rbtree_mutable_t * | mutable | Mutable instance data. |
|
static |
Lock the rbtree.
[out] | handle | Where to write pointer to handle to access the cache with. |
[in] | config | for this instance of the rlm_cache module. |
[in] | instance | Driver specific instance data. |
[in] | request | The current request. |
Definition at line 255 of file rlm_cache_rbtree.c.
|
static |
Custom allocation function for the driver.
Allows allocation of cache entry structures with additional fields.
Definition at line 77 of file rlm_cache_rbtree.c.
|
static |
Compare two entries by key.
There may only be one entry with the same key.
Definition at line 52 of file rlm_cache_rbtree.c.
|
static |
Return the number of entries in the cache.
[in] | config | for this instance of the rlm_cache module. |
[in] | instance | Driver specific instance data. |
[in] | request | The current request. |
handle | the driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided. |
Definition at line 239 of file rlm_cache_rbtree.c.
|
static |
Free an entry and remove it from the data store.
[in] | config | for this instance of the rlm_cache module. |
[in] | instance | Driver specific instance data. |
[in] | request | The current request. |
[in] | handle | the driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided. |
[in] | key | of entry to expire. |
Definition at line 140 of file rlm_cache_rbtree.c.
|
static |
Locate a cache entry.
If a cache entry is found, but the cache entry needs to be deserialized, the driver is expected to allocate an appropriately sized rlm_cache_entry_t, perform the deserialisation, and write a pointer to the new entry to out, returning CACHE_OK.
If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.
[out] | out | Where to write a pointer to the retrieved entry (if there was one). |
[in] | config | for this instance of the rlm_cache module. |
[in] | instance | Driver specific instance data. |
[in] | request | The current request. |
[in] | handle | the driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided. |
[in] | key | to use to lookup cache entry |
Definition at line 97 of file rlm_cache_rbtree.c.
|
static |
Insert a new entry into the data store.
Serialize (if necessary) the entry passed to us, and write it to the cache with the key c->key.
The cache entry should not be freed by the driver, irrespective of success or failure. If the entry needs to be freed after insertion because a local copy should not be kept, the driver should provide a cache_entry_free_t callback.
If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.
config | for this instance of the rlm_cache module. |
instance | Driver specific instance data. |
request | The current request. |
handle | the driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided. |
c | to insert. |
Definition at line 168 of file rlm_cache_rbtree.c.
|
static |
Update the TTL of an entry.
If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.
[in] | config | for this instance of the rlm_cache module. |
[in] | instance | Driver specific instance data. |
[in] | request | The current request. |
[in] | handle | the driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided. |
[in] | c | to update the TTL of. c->ttl will have been set to the new value. |
Definition at line 210 of file rlm_cache_rbtree.c.
|
static |
Compare two entries by expiry time.
There may be multiple entries with the same expiry time.
Definition at line 64 of file rlm_cache_rbtree.c.
|
static |
Release an entry unlocking any mutexes.
[in] | config | for this instance of the rlm_cache module. |
[in] | instance | Driver specific instance data. |
[in] | request | The current request. |
[in] | handle | to release. |
Definition at line 275 of file rlm_cache_rbtree.c.
|
static |
Cleanup a cache_rbtree instance.
Definition at line 288 of file rlm_cache_rbtree.c.
|
static |
Create a new cache_rbtree instance.
[in] | mctx | Data required for instantiation. |
Definition at line 319 of file rlm_cache_rbtree.c.
rlm_cache_driver_t rlm_cache_rbtree |
Definition at line 358 of file rlm_cache_rbtree.c.