summaryrefslogtreecommitdiffstats
path: root/source3/lib/gencache.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-03-10 15:41:32 +0100
committerJeremy Allison <jra@samba.org>2014-03-11 19:56:46 +0100
commit8c01dbc0586d89f974f08a30f7c7a8ed4f7f7813 (patch)
treec3b7b2a030caceb517408a3f40fcdc742d4814ab /source3/lib/gencache.c
parent80e5ae1cefd86397200c4e322c93a89efcd6bad8 (diff)
downloadsamba-8c01dbc0586d89f974f08a30f7c7a8ed4f7f7813.tar.gz
samba-8c01dbc0586d89f974f08a30f7c7a8ed4f7f7813.tar.xz
samba-8c01dbc0586d89f974f08a30f7c7a8ed4f7f7813.zip
gencache: Add gencache values to memcache
gencache_parse calling tdb shows up in profiles when we do a lot of open/close traffic with large ACLs. For every file we convert unix ids to sids, and in the domain member case this goes through gencache. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Mar 11 19:56:47 CET 2014 on sn-devel-104
Diffstat (limited to 'source3/lib/gencache.c')
-rw-r--r--source3/lib/gencache.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 168b51191e..0fb1fd8280 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -25,6 +25,7 @@
#include "system/filesys.h"
#include "system/glob.h"
#include "util_tdb.h"
+#include "memcache.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_TDB
@@ -37,6 +38,7 @@
static struct tdb_context *cache;
static struct tdb_context *cache_notrans;
+static int cache_notrans_seqnum;
/**
* @file gencache.c
@@ -112,6 +114,7 @@ static bool gencache_init(void)
cache_notrans = tdb_open_log(cache_fname, 0,
TDB_CLEAR_IF_FIRST|
TDB_INCOMPATIBLE_HASH|
+ TDB_SEQNUM|
TDB_NOSYNC,
open_flags, 0644);
if (cache_notrans == NULL) {
@@ -413,6 +416,7 @@ static bool gencache_pull_timeout(char *val, time_t *pres, char **pendptr)
struct gencache_parse_state {
void (*parser)(time_t timeout, DATA_BLOB blob, void *private_data);
void *private_data;
+ bool is_memcache;
};
static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
@@ -434,6 +438,13 @@ static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
blob = data_blob_const(
endptr+1, data.dsize - PTR_DIFF(endptr+1, data.dptr));
state->parser(t, blob, state->private_data);
+
+ if (!state->is_memcache) {
+ memcache_add(NULL, GENCACHE_RAM,
+ data_blob_const(key.dptr, key.dsize),
+ data_blob_const(data.dptr, data.dsize));
+ }
+
return 0;
}
@@ -444,6 +455,7 @@ bool gencache_parse(const char *keystr,
{
struct gencache_parse_state state;
TDB_DATA key = string_term_tdb_data(keystr);
+ DATA_BLOB memcache_val;
int ret;
if (keystr == NULL) {
@@ -459,6 +471,31 @@ bool gencache_parse(const char *keystr,
state.parser = parser;
state.private_data = private_data;
+ if (memcache_lookup(NULL, GENCACHE_RAM,
+ data_blob_const(key.dptr, key.dsize),
+ &memcache_val)) {
+ /*
+ * Make sure that nobody has changed the gencache behind our
+ * back.
+ */
+ int current_seqnum = tdb_get_seqnum(cache_notrans);
+ if (current_seqnum == cache_notrans_seqnum) {
+ /*
+ * Ok, our memcache is still current, use it without
+ * going to the tdb files.
+ */
+ state.is_memcache = true;
+ gencache_parse_fn(key, make_tdb_data(memcache_val.data,
+ memcache_val.length),
+ &state);
+ return true;
+ }
+ memcache_flush(NULL, GENCACHE_RAM);
+ cache_notrans_seqnum = current_seqnum;
+ }
+
+ state.is_memcache = false;
+
ret = tdb_parse_record(cache_notrans, key, gencache_parse_fn, &state);
if (ret == 0) {
return true;