diff options
author | Libor Peltan <libor.peltan@nic.cz> | 2017-06-09 13:38:49 +0200 |
---|---|---|
committer | Libor Peltan <libor.peltan@nic.cz> | 2017-06-09 13:38:49 +0200 |
commit | b26e31874cc7eb1687a396cc1fdaabc5b8138df3 (patch) | |
tree | 7007432bfeab255edf7e2b5ade3caf755a26d0c7 | |
parent | journal: calculating LMDB usage before starting txn (diff) | |
download | knot-b26e31874cc7eb1687a396cc1fdaabc5b8138df3.tar.xz knot-b26e31874cc7eb1687a396cc1fdaabc5b8138df3.zip |
journal: handling errors at getting LMDB usage
-rw-r--r-- | src/knot/journal/journal.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/knot/journal/journal.c b/src/knot/journal/journal.c index 5f946c2ca..4e7dfb72b 100644 --- a/src/knot/journal/journal.c +++ b/src/knot/journal/journal.c @@ -1246,20 +1246,30 @@ static int store_changesets(journal_t *j, list_t *changesets) // PART 2 : recalculating the previous insert's occupy change md_get_common_last_occupied(txn, &occupied_last); - md_set(txn, NULL, MDKEY_GLOBAL_LAST_TOTAL_OCCUPIED, occupied_now); - if (occupied_now != occupied_last) { - knot_dname_t *last_zone = NULL; - uint64_t lz_occupied; - md_get_common_last_inserter_zone(txn, &last_zone); - if (last_zone != NULL) { - md_get(txn, last_zone, MDKEY_PERZONE_OCCUPIED, &lz_occupied); - lz_occupied = (lz_occupied + occupied_now > occupied_last ? - lz_occupied + occupied_now - occupied_last : 0); - md_set(txn, last_zone, MDKEY_PERZONE_OCCUPIED, lz_occupied); - free(last_zone); + if (occupied_now == 0) { + // This shall not happen. We just handle it to minimize damage in case it would. Not 100% correct. + uint64_t tz_occupied; + md_get(txn, j->zone, MDKEY_PERZONE_OCCUPIED, &tz_occupied); + tz_occupied += serialized_size_total; + occupied_last += serialized_size_total; + md_set(txn, NULL, MDKEY_GLOBAL_LAST_TOTAL_OCCUPIED, occupied_last); + md_set(txn, j->zone, MDKEY_PERZONE_OCCUPIED, tz_occupied); + } else { + md_set(txn, NULL, MDKEY_GLOBAL_LAST_TOTAL_OCCUPIED, occupied_now); + if (occupied_now != occupied_last) { + knot_dname_t *last_zone = NULL; + uint64_t lz_occupied; + md_get_common_last_inserter_zone(txn, &last_zone); + if (last_zone != NULL) { + md_get(txn, last_zone, MDKEY_PERZONE_OCCUPIED, &lz_occupied); + lz_occupied = (lz_occupied + occupied_now > occupied_last ? + lz_occupied + occupied_now - occupied_last : 0); + md_set(txn, last_zone, MDKEY_PERZONE_OCCUPIED, lz_occupied); + free(last_zone); + } } + md_set_common_last_inserter_zone(txn, j->zone); } - md_set_common_last_inserter_zone(txn, j->zone); // PART 3 : check if we exceeded designed occupation and delete some uint64_t occupied = 0, occupied_max; |