Skip to content

Commit f02b958

Browse files
committed
Always leave at least 5 last binlog files
1 parent 9d7f746 commit f02b958

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mysql_ch_replicator/binlog_replicator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,12 @@ def get_next_file_name(self, db_name: str):
285285
return new_file_name
286286

287287
def remove_old_files(self, ts_from):
288+
PRESERVE_FILES_COUNT = 5
289+
288290
subdirs = [f.path for f in os.scandir(self.data_dir) if f.is_dir()]
289291
for db_name in subdirs:
290292
existing_file_nums = get_existing_file_nums(self.data_dir, db_name)[:-1]
291-
for file_num in existing_file_nums:
293+
for file_num in existing_file_nums[:-PRESERVE_FILES_COUNT]:
292294
file_path = os.path.join(self.data_dir, db_name, f'{file_num}.bin')
293295
modify_time = os.path.getmtime(file_path)
294296
if modify_time <= ts_from:

0 commit comments

Comments
 (0)