]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb1_tdb.c
tdb2: log allocation failures in tdb1 backend.
[ccan] / ccan / tdb2 / tdb1_tdb.c
index 0e3cc13caba9f9ab4093de2c0325a34012b74715..45db2ba33b08d1ab83be22f989715cbfd002b745 100644 (file)
@@ -89,11 +89,18 @@ static tdb1_off_t tdb1_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash
                if (tdb1_rec_read(tdb, rec_ptr, r) == -1)
                        return 0;
 
-               if (!TDB1_DEAD(r) && hash==r->full_hash
-                   && key.dsize==r->key_len
-                   && tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r),
-                                     r->key_len, tdb1_key_compare,
-                                     NULL) == 0) {
+               tdb->stats.compares++;
+               if (TDB1_DEAD(r)) {
+                       tdb->stats.compare_wrong_bucket++;
+               } else if (key.dsize != r->key_len) {
+                       tdb->stats.compare_wrong_keylen++;
+               } else if (hash != r->full_hash) {
+                       tdb->stats.compare_wrong_rechash++;
+               } else if (tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r),
+                                          r->key_len, tdb1_key_compare,
+                                          NULL) != 0) {
+                       tdb->stats.compare_wrong_keycmp++;
+               } else {
                        return rec_ptr;
                }
                /* detect tight infinite loop */
@@ -491,7 +498,9 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key,
           fails and we are left with a dead spot in the tdb. */
 
        if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) {
-               tdb->last_error = TDB_ERR_OOM;
+               tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
+                                            "tdb1_store: out of memory"
+                                            " allocating copy");
                goto fail;
        }
 
@@ -786,6 +795,7 @@ int tdb1_wipe_all(struct tdb_context *tdb)
                }
        }
 
+       tdb1_increment_seqnum_nonblock(tdb);
        tdb_unlockall(tdb);
        return 0;