From 4d5a1756e972ca3970cc5d7b9854a36ff3e47d1a Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 22 Jan 2006 16:00:16 +0000 Subject: [PATCH] halfway through implementing mintstamp --- cdb/cdb.tct | 13 ++++++++----- cdb/writeable.c | 30 +++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cdb/cdb.tct b/cdb/cdb.tct index 05d818b..017b4e6 100644 --- a/cdb/cdb.tct +++ b/cdb/cdb.tct @@ -58,15 +58,18 @@ Table cdbwr Cdbwr_SubCommand open 0 pathb string on_info obj - ?maxage int - # >0 means entries start with a 16-hex-digit - # time_t and a single space - # this time_t _is_ part of the value as seen ! + ?on_mintstamp obj + # on_mintstamp present and not empty list: provides a + # script which returns the current mintstamp. This + # means entries start with a 16-hex-digit signed + # integer known as a tstamp; occasionally, + # on_mintstamp will be called and then entries whose + # tstamp is < mintstamp will be deleted automatically. => iddata(&cdbtcl_rwdatabases) open-okjunk RWSCF_OKJUNK pathb string on_info obj - ?maxage int + ?on_mintstamp obj => iddata(&cdbtcl_rwdatabases) # on_info ...: # on_info open-clean diff --git a/cdb/writeable.c b/cdb/writeable.c index 0074a61..f44e881 100644 --- a/cdb/writeable.c +++ b/cdb/writeable.c @@ -94,11 +94,10 @@ static void ht_maybeupdate(HashTable *ht, const char *key, static int ht_forall(HashTable *ht, int (*fn)(const char *key, const HashValue *val, - struct ht_forall_ctx *ctx), + Tcl_HashEntry *he, struct ht_forall_ctx *ctx), struct ht_forall_ctx *ctx) { - /* Returns first positive value returned by any call to fn, or 0. - * If fn returns -1, key is deleted. */ - Tcl_HashSearch sp; + /* Returns first positive value returned by any call to fn, or 0. */ + Tcl_HashSearch sp;n Tcl_HashEntry *he; const char *key; HashValue *val; @@ -133,8 +132,7 @@ static void ht_destroy(HashTable *ht) { /*---------- Rw data structure ----------*/ typedef struct { - int ix, autocompact, maxage; -fixme implement maxage during compact; + int ix, autocompact; int cdb_fd, lock_fd; struct cdb cdb; /* valid iff cdb_fd >= 0 */ off_t cdb_bytes; /* valid iff cdb_fd >= 0 */ @@ -142,6 +140,7 @@ fixme implement maxage during compact; HashTable logincore; Pathbuf pbsome, pbother; off_t mainsz; + ScriptToInvoke on_info, on_mintstamp; } Rw; static int rw_close(Tcl_Interp *ip, Rw *rw) { @@ -336,7 +335,8 @@ static int infocb(Tcl_Interp *ip, Rw *rw, const char *arg1, /*---------- Opening ----------*/ int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb, - Tcl_Obj *on_info, int maxage, void **result) { + Tcl_Obj *on_info, Tcl_Obj *on_mintstamp, + void **result) { const Cdbwr_SubCommand *subcmd= cd; int r, rc, mainfd=-1; Rw *rw; @@ -345,12 +345,21 @@ int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb, rw= TALLOC(sizeof(*rw)); ht_setup(&rw->logincore); + scriptinv_init(&rw->on_info); + scriptinv_init(&rw->on_mintstamp); rw->cdb_fd= rw->lock_fd= -1; rw->logfile= 0; rw->maxage= maxage; pathbuf_init(&rw->pbsome, pathb); pathbuf_init(&rw->pbother, pathb); rw->autocompact= 1; + if (on_mintstamp) { + rc= scriptinv_set(&rw->on_mintstamp, ip, on_mintstamp, 0); + if (rc) goto x_rc; + } else { + rw->on_mintstamp.llength= 0; + } + mainfd= open(pathbuf_sfx(&rw->pbsome,".main"), O_RDONLY); if (mainfd<0) PE("open exist3ing database file .main"); rc= acquire_lock(ip, &rw->pbsome, &rw->lock_fd); if (rc) goto x_rc; @@ -475,6 +484,13 @@ static int compact_core(Tcl_Interp *ip, Rw *rw, unsigned long logsize) { logsize, (unsigned long)rw->mainsz); if (rc) goto x_rc; + if (rw->on_mintstamp.llength) { + rc= cht_scriptinv_invoke_fg(&rw->on_mintstamp, 0,0); + if (rc) goto x_rc; + + Tcl_GetObjResult(ip) fixme do something here + } + /* merge unsuperseded records from main into hash table */ a.mainfile= fopen(pathbuf_sfx(&rw->pbsome,".main"), "r"); -- 2.30.2