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 <event> <xinfo>...:
# on_info open-clean <statistics-info-string>
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;
/*---------- 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 */
HashTable logincore;
Pathbuf pbsome, pbother;
off_t mainsz;
+ ScriptToInvoke on_info, on_mintstamp;
} Rw;
static int rw_close(Tcl_Interp *ip, Rw *rw) {
/*---------- 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;
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;
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");