Skip to content

Commit

Permalink
Clean md store objects
Browse files Browse the repository at this point in the history
Clean md store objects once the max deleted objects
reach the limit.

Fixes: https://issues.redhat.com/browse/DFBUGS-1339

Signed-off-by: Vinayakswami Hariharmath <[email protected]>
  • Loading branch information
vh05 committed Jan 20, 2025
1 parent e24c627 commit 4be34e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ config.DB_CLEANER_BACK_TIME = 3 * 30 * 24 * 60 * 60 * 1000; // 3 months
config.DB_CLEANER_DOCS_LIMIT = 1000;
config.DB_CLEANER_MAX_TOTAL_DOCS = 10000;

config.MD_STORE_MAX_DELETED_OBJECTS_LIMIT = 100;
/////////////////////
// CLOUD RESOURCES //
/////////////////////
Expand Down
29 changes: 23 additions & 6 deletions src/server/bg_services/db_cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,44 @@ async function background_worker() {

async function clean_md_store(last_date_to_remove) {
const total_objects_count = await MDStore.instance().estimated_total_objects();
if (total_objects_count < config.DB_CLEANER_MAX_TOTAL_DOCS) {
if (total_objects_count < config.DB_CLEANER_MAX_TOTAL_DOCS ) {
dbg.log0(`DB_CLEANER: found less than ${config.DB_CLEANER_MAX_TOTAL_DOCS} objects in MD-STORE
${total_objects_count} objects - Skipping...`);
return;
}
const objects_to_remove = await clean_md_store_objects(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);
const blocks_to_remove = await clean_md_store_blocks(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);
const filtered_chunks = await clean_md_store_chunks(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);

dbg.log0(`DB_CLEANER: removed ${objects_to_remove.length + blocks_to_remove.length + filtered_chunks.length} documents from md-store`);
}

async function clean_md_store_objects(last_date_to_remove, limit) {
dbg.log0('DB_CLEANER: checking md-store for documents deleted before', new Date(last_date_to_remove));
const objects_to_remove = await MDStore.instance().find_deleted_objects(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);
const objects_to_remove = await MDStore.instance().find_deleted_objects(last_date_to_remove, limit);
dbg.log2('DB_CLEANER: list objects:', objects_to_remove);
if (objects_to_remove.length) {
if (objects_to_remove.length > config.MD_STORE_MAX_DELETED_OBJECTS_LIMIT) {
await P.map_with_concurrency(10, objects_to_remove, obj => db_delete_object_parts(obj));
await MDStore.instance().db_delete_objects(objects_to_remove);
}
const blocks_to_remove = await MDStore.instance().find_deleted_blocks(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);
return objects_to_remove;
}

async function clean_md_store_blocks(last_date_to_remove, limit) {
const blocks_to_remove = await MDStore.instance().find_deleted_blocks(last_date_to_remove, limit);
dbg.log2('DB_CLEANER: list blocks:', blocks_to_remove);
if (blocks_to_remove.length) await MDStore.instance().db_delete_blocks(blocks_to_remove);
const chunks_to_remove = await MDStore.instance().find_deleted_chunks(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);
return blocks_to_remove;
}

async function clean_md_store_chunks(last_date_to_remove, limit) {
const chunks_to_remove = await MDStore.instance().find_deleted_chunks(last_date_to_remove, limit);
const filtered_chunks = chunks_to_remove.filter(async chunk =>
!(await MDStore.instance().has_any_blocks_for_chunk(chunk)) &&
!(await MDStore.instance().has_any_parts_for_chunk(chunk)));
dbg.log2('DB_CLEANER: list chunks with no blocks and no parts to be removed from DB', filtered_chunks);
if (filtered_chunks.length) await MDStore.instance().db_delete_chunks(filtered_chunks);
dbg.log0(`DB_CLEANER: removed ${objects_to_remove.length + blocks_to_remove.length + filtered_chunks.length} documents from md-store`);
return filtered_chunks;
}

async function db_delete_object_parts(id) {
Expand Down Expand Up @@ -145,3 +161,4 @@ async function clean_system_store(last_date_to_remove) {

// EXPORTS
exports.background_worker = background_worker;
exports.clean_md_store_objects = clean_md_store_objects;
4 changes: 4 additions & 0 deletions src/server/bg_services/objects_reclaimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const MDStore = require('../object_services/md_store').MDStore;
const system_store = require('../system_services/system_store').get_instance();
const system_utils = require('../utils/system_utils');
const map_deleter = require('../object_services/map_deleter');
const {clean_md_store_objects} = require('./db_cleaner');
const P = require('../../util/promise');

class ObjectsReclaimer {
Expand Down Expand Up @@ -42,6 +43,9 @@ class ObjectsReclaimer {
if (has_errors) {
return config.OBJECT_RECLAIMER_ERROR_DELAY;
}

await clean_md_store_objects(Date.now());

return config.OBJECT_RECLAIMER_BATCH_DELAY;

}
Expand Down

0 comments on commit 4be34e8

Please sign in to comment.