@@ -58,23 +58,39 @@ async function clean_md_store(last_date_to_remove) {
58
58
${ total_objects_count } objects - Skipping...` ) ;
59
59
return ;
60
60
}
61
+ const objects_to_remove = await clean_md_store_objects ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
62
+ const blocks_to_remove = await clean_md_store_blocks ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
63
+ const filtered_chunks = await clean_md_store_chunks ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
64
+
65
+ dbg . log0 ( `DB_CLEANER: removed ${ objects_to_remove . length + blocks_to_remove . length + filtered_chunks . length } documents from md-store` ) ;
66
+ }
67
+
68
+ async function clean_md_store_objects ( last_date_to_remove , limit ) {
61
69
dbg . log0 ( 'DB_CLEANER: checking md-store for documents deleted before' , new Date ( last_date_to_remove ) ) ;
62
- const objects_to_remove = await MDStore . instance ( ) . find_deleted_objects ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
70
+ const objects_to_remove = await MDStore . instance ( ) . find_deleted_objects ( last_date_to_remove , limit ) ;
63
71
dbg . log2 ( 'DB_CLEANER: list objects:' , objects_to_remove ) ;
64
- if ( objects_to_remove . length ) {
72
+ if ( objects_to_remove . length > config . MD_STORE_MAX_DELETED_OBJECTS_LIMIT ) {
65
73
await P . map_with_concurrency ( 10 , objects_to_remove , obj => db_delete_object_parts ( obj ) ) ;
66
74
await MDStore . instance ( ) . db_delete_objects ( objects_to_remove ) ;
67
75
}
68
- const blocks_to_remove = await MDStore . instance ( ) . find_deleted_blocks ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
76
+ return objects_to_remove ;
77
+ }
78
+
79
+ async function clean_md_store_blocks ( last_date_to_remove , limit ) {
80
+ const blocks_to_remove = await MDStore . instance ( ) . find_deleted_blocks ( last_date_to_remove , limit ) ;
69
81
dbg . log2 ( 'DB_CLEANER: list blocks:' , blocks_to_remove ) ;
70
82
if ( blocks_to_remove . length ) await MDStore . instance ( ) . db_delete_blocks ( blocks_to_remove ) ;
71
- const chunks_to_remove = await MDStore . instance ( ) . find_deleted_chunks ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
83
+ return blocks_to_remove ;
84
+ }
85
+
86
+ async function clean_md_store_chunks ( last_date_to_remove , limit ) {
87
+ const chunks_to_remove = await MDStore . instance ( ) . find_deleted_chunks ( last_date_to_remove , limit ) ;
72
88
const filtered_chunks = chunks_to_remove . filter ( async chunk =>
73
89
! ( await MDStore . instance ( ) . has_any_blocks_for_chunk ( chunk ) ) &&
74
90
! ( await MDStore . instance ( ) . has_any_parts_for_chunk ( chunk ) ) ) ;
75
91
dbg . log2 ( 'DB_CLEANER: list chunks with no blocks and no parts to be removed from DB' , filtered_chunks ) ;
76
92
if ( filtered_chunks . length ) await MDStore . instance ( ) . db_delete_chunks ( filtered_chunks ) ;
77
- dbg . log0 ( `DB_CLEANER: removed ${ objects_to_remove . length + blocks_to_remove . length + filtered_chunks . length } documents from md-store` ) ;
93
+ return filtered_chunks ;
78
94
}
79
95
80
96
async function db_delete_object_parts ( id ) {
@@ -145,3 +161,4 @@ async function clean_system_store(last_date_to_remove) {
145
161
146
162
// EXPORTS
147
163
exports . background_worker = background_worker ;
164
+ exports . clean_md_store_objects = clean_md_store_objects ;
0 commit comments