Commit b26e3187 authored by Libor Peltan's avatar Libor Peltan

journal: handling errors at getting LMDB usage

parent b3a7ddc9
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment