Skip to content

Commit 0c30e54

Browse files
committed
Prevent myhoard starting more than one backup stream
Multiple backup streams add complexity and instability, increasing load on the server for negligible benefit. It is better to complete the current backup before devoting resources to beginning a second stream. This also has the side-effect of better handling situations where one stream appears to fail, then recovers, and interferes with a new backup stream: until the first one is finished, a second one will not start, after which the first one is gone.
1 parent 1237b89 commit 0c30e54

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

myhoard/backup_stream.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ def running(self):
252252
yield
253253
self.stop()
254254

255+
def is_in_terminal_state(self) -> bool:
256+
"""Returns if the stream has finished operating, successfully or not"""
257+
return bool(self.state.get("broken_info") or self.state.get("closed_info") or self.state.get("completed_info"))
258+
255259
def activate(self) -> None:
256260
with self.lock:
257261
if self.mode != self.Mode.promoted:

myhoard/controller.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,12 @@ def _check_binlog_apply_status(self) -> None:
802802
self.state_manager.update_state(promote_details=promote_details)
803803

804804
def _create_new_backup_stream_if_requested_and_max_streams_not_exceeded(self):
805-
# Only ever have two open backup streams. Uploading binlogs to more streams than that is
806-
# unlikely to improve the system behavior. We'll create new backup stream once the latter
807-
# one catches up with the first, the first is marked as closed, and removed from our list.
808-
if len(self.backup_streams) >= 2:
809-
return
805+
# Only ever have one "active" backup stream.
806+
# Having multiple backup streams adds complexity, increases node resource usage, and
807+
# more easily triggers various latent bugs.
808+
for existing_backup_stream in self.backup_streams:
809+
if not existing_backup_stream.is_in_terminal_state():
810+
return
810811
with self.lock:
811812
if self.state["backup_request"]:
812813
request: BackupRequest = self.state["backup_request"]

0 commit comments

Comments
 (0)