Skip to content

Clean md store objects #8700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 22 additions & 5 deletions src/server/bg_services/db_cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,39 @@ async function clean_md_store(last_date_to_remove) {
${total_objects_count} objects - Skipping...`);
return;
}
const objects_to_remove = await clean_md_store_objects(last_date_to_remove, config.DB_CLEANER_DOCS_LIMIT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you rearrange the same code in smaller functions? I'm not sure if it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. looking to clean only deleted md objects and other calls in the function not needed. Divided the function into 3 sub functions.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we adding this limit? why not deleting less?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the good number ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think number is arbitrary, but we can go with 10 or 20 for example

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());
Copy link
Contributor

@jackyalbo jackyalbo Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this belongs here... why should we run db_cleaner inside object_reclaimer - db_cleaner will run on objects with no regard to the list that was reclaimed (and of course, we don't want to db-delete objects that were just marked as deleted completely from the DB!). I think what we wanted here is a new functionality that for each of the objects, will check how many deleted objects we have with the same key and, if it's more than X - delete the older copies - @dannyzaken to keep me honest here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jira issue (https://issues.redhat.com/browse/DFBUGS-1339) is specifically mentioned that we can call clean the deleted objects from the md store in object reclaimer. Thought this is the place. @dannyzaken Please correct me here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vh05 I didn't intend for the description in Jira to be specific instructions on how to fix it. I wanted to provide some general context.
I don't see a reason to call from object_reclaimer to the db_cleaner. These are two separate bg_workers.


return config.OBJECT_RECLAIMER_BATCH_DELAY;

}
Expand Down
Loading