Skip to content
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

Check WAL shipping setup only in archiver mode #720

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
54 changes: 33 additions & 21 deletions barman/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,27 +641,39 @@ def check_archive(self, check_strategy):
of the results of the various checks
"""
check_strategy.init_check("WAL archive")
# Make sure that WAL archiving has been setup
# XLOG_DB needs to exist and its size must be > 0
# NOTE: we do not need to acquire a lock in this phase
xlogdb_empty = True
if os.path.exists(self.xlogdb_file_name):
with open(self.xlogdb_file_name, "rb") as fxlogdb:
if os.fstat(fxlogdb.fileno()).st_size > 0:
xlogdb_empty = False

# NOTE: This check needs to be only visible if it fails
if xlogdb_empty:
# Skip the error if we have a terminated backup
# with status WAITING_FOR_WALS.
# TODO: Improve this check
backup_id = self.get_last_backup_id([BackupInfo.WAITING_FOR_WALS])
if not backup_id:
check_strategy.result(
self.config.name,
False,
hint="please make sure WAL shipping is setup",
)
if not os.access(self.config.wals_directory, os.W_OK):
check_strategy.result(
self.config.name, False,
hint=f"wals_directory {self.config.wals_directory} must be writable"
Copy link
Contributor

Choose a reason for hiding this comment

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

This f string should be fine for future Barman releases because they will require Python 3.6 as a minimum. If we did want to backport it to the 3.4.x branch then it would need to be compatible with Python 2.7 but that would be a small enough change to deal with if it came up.

)
return
if self.config.archiver:
# Make sure that WAL archiving has been setup
# XLOG_DB needs to exist and its size must be > 0
# NOTE: we do not need to acquire a lock in this phase
xlogdb_empty = True
if os.path.exists(self.xlogdb_file_name):
with open(self.xlogdb_file_name, "rb") as fxlogdb:
if os.fstat(fxlogdb.fileno()).st_size > 0:
xlogdb_empty = False

# NOTE: This check needs to be only visible if it fails
if xlogdb_empty:
# Skip the error if we have a terminated backup
# with status WAITING_FOR_WALS.
# TODO: Improve this check
backup_id = self.get_last_backup_id([BackupInfo.WAITING_FOR_WALS])
if not backup_id:
check_strategy.result(
self.config.name,
False,
hint="please make sure WAL shipping is setup",
)
if self.config.streaming_archiver:
if not glob(os.path.join(self.config.streaming_wals_directory,
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately when I suggested this check I didn't take into account the fact that the .partial file is not always going to be present. For example, when a WAL switch occurs there is no guarantee that the .partial file for the next segment will have been created by the time the completed segment is renamed.

While there's still a need to improve on how Barman verifies WAL streaming is working, checking for the .partial file is not the way to do it and we'll need to come up with something better.

"*" + PARTIAL_EXTENSION)):
check_strategy.result(self.config.name, False,
hint="partial file should be present")

# Check the number of wals in the incoming directory
self._check_wal_queue(check_strategy, "incoming", "archiver")
Expand Down