X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fcnid_dbd%2Fdbif.c;h=125be0093e55cf53ef2312a9ad7eef56bb263dec;hb=3815df691518846b035effeb798677655f74e3e6;hp=2b5b91ac0f3bcdd7f397b26193840e9f193bbf2d;hpb=ff3b4646472add7902b0d36dd1a941ec1a54e999;p=netatalk.git diff --git a/etc/cnid_dbd/dbif.c b/etc/cnid_dbd/dbif.c index 2b5b91ac..125be009 100644 --- a/etc/cnid_dbd/dbif.c +++ b/etc/cnid_dbd/dbif.c @@ -105,6 +105,10 @@ static int dbif_init_rootinfo(DBD *dbd, int version) if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0) return -1; + if (dbif_txn_commit(dbd) != 1) { + LOG(log_error, logtype_cnid, "dbif_init_rootinfo: cant commit txn"); + return -1; + } return 0; } @@ -121,6 +125,9 @@ static int dbif_getversion(DBD *dbd, uint32_t *version) DBT key, data; int ret; + LOG(log_maxdebug, logtype_cnid, "dbif_getversion: reading version info"); + + *version = -1; memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); key.data = ROOTINFO_KEY; @@ -134,9 +141,11 @@ static int dbif_getversion(DBD *dbd, uint32_t *version) ret = 1; break; case 0: /* not found */ + LOG(log_debug, logtype_cnid, "dbif_getversion: no version info found"); ret = 0; break; default: + LOG(log_error, logtype_cnid, "dbif_getversion: database error"); ret = -1; break; } @@ -147,7 +156,7 @@ static int dbif_getversion(DBD *dbd, uint32_t *version) /*! * Set CNID database version number * - * Initializes rootinfo key as neccessary, as does dbif_getversion + * Initializes rootinfo key as neccessary * @returns -1 on error, 0 on success */ static int dbif_setversion(DBD *dbd, uint32_t version) @@ -185,16 +194,22 @@ static int dbif_setversion(DBD *dbd, uint32_t version) } /*! - * Upgrade CNID database versions + * Upgrade CNID database versions, initialize rootinfo key as as necessary in dbif_setversion() * * For now this does nothing, as upgrading from ver. 0 to 1 is done in dbif_open */ +#define UNINTIALIZED_DB UINT32_MAX static int dbif_upgrade(DBD *dbd) { - uint32_t version; + uint32_t version = CNID_VERSION_UNINTIALIZED_DB; if (dbif_getversion(dbd, &version) == -1) return -1; + if (version == CNID_VERSION_UNINTIALIZED_DB) { + version = CNID_VERSION; + if (dbif_setversion(dbd, CNID_VERSION) != 0) + return -1; + } /* * Do upgrade stuff ... @@ -371,6 +386,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; @@ -612,6 +629,10 @@ int dbif_open(DBD *dbd, struct db_param *dbp, int reindex) if (reindex) LOG(log_info, logtype_cnid, "Reindexing name index..."); + /* + * Upgrading from version 0 to 1 requires adding the name index below which + * must be done by specifying the DB_CREATE flag + */ uint32_t version = CNID_VERSION; if (dbd->db_envhome && !reindex) { if (dbif_getversion(dbd, &version) == -1) @@ -986,9 +1007,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) { @@ -997,7 +1024,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!");