@@ -8,6 +8,7 @@ const config = require('../../../config');
8
8
const MDStore = require ( '../object_services/md_store' ) . MDStore ;
9
9
const system_store = require ( '../system_services/system_store' ) . get_instance ( ) ;
10
10
const nodes_store = require ( '../node_services/nodes_store' ) . NodesStore . instance ( ) ;
11
+ const replication_store = require ( '../system_services/replication_store' ) . instance ( ) ;
11
12
const system_utils = require ( '../utils/system_utils' ) ;
12
13
const db_client = require ( '../../util/db_client' ) ;
13
14
const md_aggregator = require ( './md_aggregator' ) ;
@@ -47,6 +48,7 @@ async function background_worker() {
47
48
await clean_md_store ( last_date_to_remove ) ;
48
49
await clean_nodes_store ( last_date_to_remove ) ;
49
50
await clean_system_store ( last_date_to_remove ) ;
51
+ await clean_replication_store ( last_date_to_remove ) ;
50
52
dbg . log0 ( 'DB_CLEANER:' , 'END' ) ;
51
53
return config . DB_CLEANER_CYCLE ;
52
54
}
@@ -107,6 +109,25 @@ async function clean_nodes_store(last_date_to_remove) {
107
109
dbg . log0 ( `DB_CLEANER: removed ${ filtered_nodes . length } documents from nodes-store` ) ;
108
110
}
109
111
112
+ async function clean_replication_store ( last_date_to_remove ) {
113
+ const total_replication_rules_count = await replication_store . count_total_replication_rules ( ) ;
114
+ if ( total_replication_rules_count < config . DB_CLEANER_MAX_TOTAL_DOCS ) {
115
+ dbg . log0 ( `DB_CLEANER: found less than ${ config . DB_CLEANER_MAX_TOTAL_DOCS } replication rules in replication-store
116
+ ${ total_replication_rules_count } replication rules - Skipping...` ) ;
117
+ return ;
118
+ }
119
+ dbg . log0 ( 'DB_CLEANER: checking replication-store for replication rules deleted before' , new Date ( last_date_to_remove ) ) ;
120
+ const replication_rules = await replication_store . find_deleted_rules ( last_date_to_remove , config . DB_CLEANER_DOCS_LIMIT ) ;
121
+ if ( replication_rules . length === 0 ) {
122
+ dbg . log0 ( "No replication rules to delete." ) ;
123
+ return ;
124
+ }
125
+ const rr_ids = db_client . instance ( ) . uniq_ids ( replication_rules , '_id' ) ;
126
+ dbg . log0 ( 'DB_CLEANER: found deleted replication rules:' , rr_ids ) ;
127
+ await replication_store . actual_delete_replication_by_id ( rr_ids ) ;
128
+ dbg . log0 ( `DB_CLEANER: removed ${ rr_ids . length } replication rules from replication-store` ) ;
129
+ }
130
+
110
131
async function clean_system_store ( last_date_to_remove ) {
111
132
const total_accounts_count = await system_store . count_total_docs ( 'accounts' ) ;
112
133
const total_buckets_count = await system_store . count_total_docs ( 'buckets' ) ;
0 commit comments