]> arthur.barton.de Git - netatalk.git/commitdiff
Fixes for new rebuild db
authorFrank Lahm <franklahm@googlemail.com>
Fri, 15 Apr 2011 19:09:02 +0000 (21:09 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Fri, 15 Apr 2011 19:09:02 +0000 (21:09 +0200)
etc/cnid_dbd/cmd_dbd.c
etc/cnid_dbd/cmd_dbd_scanvol.c
etc/cnid_dbd/db_param.h
etc/cnid_dbd/dbif.c
etc/cnid_dbd/dbif.h

index 357b1d226854a8cdbb7460abc0c7445f19e88578..59d5e6072d51905ac5f1f92e21e675008a8f28a4 100644 (file)
@@ -90,12 +90,13 @@ static struct db_param db_param = {
     NULL,                       /* Volume dirpath */
     1,                          /* bdb logfile autoremove */
     64 * 1024,                  /* bdb cachesize (64 MB) */
-    -1,                         /* not used ... */
-    -1,
-    "",
-    -1,
-    -1,
-    -1
+    0,                          /* flush_interval */
+    0,                          /* flush_frequency */
+    1000,                       /* txn_frequency */
+    0,                          /* usock_file */
+    -1,                         /* fd_table_size */
+    -1,                         /* idle_timeout */
+    -1                          /* max_vols */
 };
 static char dbpath[PATH_MAX];   /* Path to the dbd database */
 
@@ -467,9 +468,11 @@ int main(int argc, char **argv)
 
     /* Cleanup */
     dbd_log(LOGDEBUG, "Closing db");
-    if (! nocniddb && dbif_close(dbd) < 0) {
-        dbd_log( LOGSTD, "Error closing database");
-        goto exit_failure;
+    if (! nocniddb) {
+        if (dbif_close(dbd) < 0) {
+            dbd_log( LOGSTD, "Error closing database");
+            goto exit_failure;
+        }
     }
 
 exit_success:
index fbb0b7dbf15a60ff3eb8d1c3a8adfcebdd777979..dcecf5fee2c0904f1ded8285be06988bfe7963da 100644 (file)
@@ -675,6 +675,17 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
     cnid_t db_cnid, ad_cnid;
     struct adouble ad;
 
+    /* Force checkout every X items */
+    static int cnidcount = 0;
+    cnidcount++;
+    if (cnidcount > 10000) {
+        cnidcount = 0;
+        if (dbif_txn_checkpoint(dbd, 0, 0, 0) < 0) {
+            dbd_log(LOGSTD, "Error checkpointing!");
+            return 0;
+        }
+    }
+
     /* Get CNID from ad-file if volume is using AFPVOL_CACHE */
     ad_cnid = 0;
     if ( (volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
@@ -961,6 +972,7 @@ static int dbd_readdir(int volroot, cnid_t did)
 
             /* Now add this object to our rebuild dbd */
             if (cnid) {
+                static uint count = 0;
                 rqst.cnid = rply.cnid;
                 ret = dbd_rebuild_add(dbd_rebuild, &rqst, &rply);
                 dbif_txn_close(dbd_rebuild, ret);
@@ -969,6 +981,14 @@ static int dbd_readdir(int volroot, cnid_t did)
                              cnid, cwdbuf, ep->d_name);
                     longjmp(jmp, 1); /* this jumps back to cmd_dbd_scanvol() */
                 }
+                count++;
+                if (count == 10000) {
+                    if (dbif_txn_checkpoint(dbd_rebuild, 0, 0, 0) < 0) {
+                        dbd_log(LOGSTD, "Error checkpointing!");
+                        return -1;
+                    }
+                    count = 0;
+                }
             }
         }
 
@@ -1054,6 +1074,8 @@ static void delete_orphaned_cnids(DBD *dbd, DBD *dbd_rebuild, dbd_flags_t flags)
     struct cnid_dbd_rqst rqst;
     struct cnid_dbd_rply rply;
 
+    dbd->db_param.txn_frequency = 0;
+
     /* jump over rootinfo key */
     if ( dbif_idwalk(dbd, &dbd_cnid, 0) != 1)
         return;
@@ -1117,12 +1139,13 @@ static void delete_orphaned_cnids(DBD *dbd, DBD *dbd_rebuild, dbd_flags_t flags)
         }
 
         if (dbd_cnid > rebuild_cnid) {
+            dbif_idwalk(dbd, NULL, 1); /* Close cursor */
+            dbif_idwalk(dbd_rebuild, NULL, 1); /* Close cursor */
+            dbif_txn_close(dbd, 2);
+            dbif_txn_close(dbd_rebuild, 2);
             dbd_log(LOGSTD, "Ghost CNID: %u. This is fatal! Dumping rebuild db:\n", rebuild_cnid);
             dbif_dump(dbd_rebuild, 0);
             dbd_log(LOGSTD, "Send this dump and a `dbd -d ...` dump to the Netatalk Dev team!");
-            dbif_txn_close(dbd, ret);
-            dbif_idwalk(dbd, NULL, 1); /* Close cursor */
-            dbif_idwalk(dbd_rebuild, NULL, 1); /* Close cursor */
             goto cleanup;
         }
     }
@@ -1154,6 +1177,8 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
 
     /* Set cachesize for in-memory rebuild db */
     db_param.cachesize = 128 * 1024 * 1024; /* 128 MB */
+    db_param.txn_frequency = 1000;          /* close txn every 1000 objects */
+    db_param.logfile_autoremove = 1;
 
     /* Make it accessible for all funcs */
     dbd = dbd_ref;
@@ -1198,7 +1223,7 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
 
     if (setjmp(jmp) != 0) {
         ret = 0;                /* Got signal, jump from dbd_readdir */
-        goto exit;              
+        goto exit_cleanup;              
     }
 
     /* scanvol */
@@ -1207,10 +1232,13 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
         goto exit;
     }
 
+exit_cleanup:
     if (! nocniddb) {
-        /* We can only do this in exclusive mode, otherwise we might delete CNIDs added from
-           other clients in between our pass 1 and 2 */
-        if (flags & DBD_FLAGS_EXCL)
+        dbif_txn_close(dbd, 2);
+        dbif_txn_close(dbd_rebuild, 2);
+        if ((flags & DBD_FLAGS_EXCL) && !(flags & DBD_FLAGS_FORCE))
+            /* We can only do this in exclusive mode, otherwise we might delete CNIDs added from
+               other clients in between our pass 1 and 2 */
             delete_orphaned_cnids(dbd, dbd_rebuild, flags);
     }
 
@@ -1218,7 +1246,7 @@ exit:
     if (dbd_rebuild) {
         dbd_log(LOGDEBUG, "Closing tmp db");
         dbif_close(dbd_rebuild);
-#if 0
+
         if (tmpdb_path) {
             char cmd[8 + MAXPATHLEN];
             snprintf(cmd, 8 + MAXPATHLEN, "rm -f %s/*", tmpdb_path);
@@ -1227,7 +1255,6 @@ exit:
             snprintf(cmd, 8 + MAXPATHLEN, "rmdir %s", tmpdb_path);
             system(cmd);
         }        
-#endif
     }
     return ret;
 }
index ebcea6b823185494b937d31a78df6a0974e36a10..f1b188c18576fb968abbabd9e719a396cec27196 100644 (file)
@@ -22,6 +22,7 @@ struct db_param {
     int cachesize;              /* in KB */
     int flush_interval;
     int flush_frequency;
+    int txn_frequency;
     char usock_file[MAXPATHLEN + 1];    
     int fd_table_size;
     int idle_timeout;
index ea22816b1cce8944dc53c865e2a38b914091dc96..1825145b0b17f744d835072b4efcf7cdf191a767 100644 (file)
@@ -274,6 +274,8 @@ int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
         return -1;
     }
 
+    dbd->db_param = *dbp;
+
     if ((dbif_openlog(dbd)) != 0)
         return -1;
 
@@ -789,9 +791,15 @@ int dbif_txn_abort(DBD *dbd)
 }
 
 /* 
-   ret = 1 -> commit txn
-   ret = 0 -> abort txn -> exit!
+   ret = 2 -> commit txn regardless of db_param.txn_frequency
+   ret = 1 -> commit txn if db_param.txn_frequency
+   ret = 0 -> abort txn db_param.txn_frequency -> exit!
    anything else -> exit!
+
+   db_param of the db environment might specify txn_frequency > 1 in which case
+   we only close a txn every txn_frequency time. the `dbd` command uses this for the
+   temp rebuild db, cnid_dbd keeps it at 0. For increasing cnid_dbd throughput this
+   should be tuned and testes as well.
 */
 void dbif_txn_close(DBD *dbd, int ret)
 {
@@ -800,7 +808,13 @@ void dbif_txn_close(DBD *dbd, int ret)
             LOG( log_error, logtype_cnid, "Fatal error aborting transaction. Exiting!");
             exit(EXIT_FAILURE);
         }
-    } else if (ret == 1) {
+    } else if (ret == 1 || ret == 2) {
+        static uint count;
+        if (ret != 2 && dbd->db_param.txn_frequency > 1) {
+            count++;
+            if ((count % dbd->db_param.txn_frequency) != 0)
+                return;
+        }
         ret = dbif_txn_commit(dbd);
         if (  ret < 0) {
             LOG( log_error, logtype_cnid, "Fatal error committing transaction. Exiting!");
index e2903b284b7325c01991e3f1f588115b39d1b58e..c5f4f52c5c95d43137e60a18d533fe049a76ee61 100644 (file)
@@ -75,6 +75,7 @@ typedef struct {
 
 typedef struct {
     DB_ENV   *db_env;
+    struct db_param db_param;
     DB_TXN   *db_txn;
     DBC      *db_cur;              /* for dbif_walk */
     char     *db_envhome;