chiark / gitweb /
halfway through implementing mintstamp
authorian <ian>
Sun, 22 Jan 2006 16:00:16 +0000 (16:00 +0000)
committerian <ian>
Sun, 22 Jan 2006 16:00:16 +0000 (16:00 +0000)
cdb/cdb.tct
cdb/writeable.c

index 05d818be1b803c18d2245edccd780976f1200aa0..017b4e63abedb69b96503f61c75b6a5e7cb5756b 100644 (file)
@@ -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 <event> <xinfo>...:
                # on_info open-clean <statistics-info-string>
index 0074a6126181e2d76378c1ca21099346223ccbaa..f44e8815dfd6fd6223b9057d603da1cd7f913801 100644 (file)
@@ -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");