Skip to content

Commit

Permalink
Add property wal_directory
Browse files Browse the repository at this point in the history
Add property `wal_directory` to find a proper place of wal files based
on Postgesql version.
  • Loading branch information
erthalion authored and Oleksii Kliukin committed Jun 12, 2017
1 parent d64ca0f commit fd37d8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pg_view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def main():
# initialize the disks stat collector process and create an exchange queue
q = JoinableQueue(1)
work_directories = [cl['wd'] for cl in clusters if 'wd' in cl]
collector = DetachedDiskStatCollector(q, work_directories)
collector = DetachedDiskStatCollector(q, work_directories, dbver)
collector.start()
consumer = DiskCollectorConsumer(q)

Expand Down
27 changes: 21 additions & 6 deletions pg_view/collectors/partition_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class PartitionStatCollector(StatCollector):
DISK_STAT_FILE = '/proc/diskstats'
DATA_NAME = 'data'
XLOG_NAME = 'xlog'
XLOG_SUBDIR = 'pg_xlog/'
BLOCK_SIZE = 1024

def __init__(self, dbname, dbversion, work_directory, consumer):
Expand Down Expand Up @@ -206,13 +205,29 @@ def output(self, method):
class DetachedDiskStatCollector(Process):
""" This class runs in a separate process and runs du and df """

def __init__(self, q, work_directories):
OLD_WAL_SUBDIR = '/pg_xlog/'
WAL_SUBDIR = '/pg_wal/'

NEW_WAL_SINCE = 10.0

def __init__(self, q, work_directories, db_version):
super(DetachedDiskStatCollector, self).__init__()
self.work_directories = work_directories
self.q = q
self.daemon = True
self.db_version = db_version
self.df_cache = {}

@property
def wal_directory(self):
""" Since Postgresql 10.0 wal directory was renamed, so we need to
choose actual wal directory based on a db_version.
"""
if self.db_version < DetachedDiskStatCollector.NEW_WAL_SINCE:
return DetachedDiskStatCollector.OLD_WAL_SUBDIR
else:
return DetachedDiskStatCollector.WAL_SUBDIR

def run(self):
while True:
# wait until the previous data is consumed
Expand All @@ -233,14 +248,14 @@ def get_du_data(self, wd):
result = {'data': [], 'xlog': []}
try:
data_size = self.run_du(wd, BLOCK_SIZE)
xlog_size = self.run_du(wd + '/pg_xlog/', BLOCK_SIZE)
xlog_size = self.run_du(wd + self.wal_directory, BLOCK_SIZE)
except Exception as e:
logger.error('Unable to read free space information for the pg_xlog and data directories for the directory\
{0}: {1}'.format(wd, e))
else:
# XXX: why do we pass the block size there?
result['data'] = str(data_size), wd
result['xlog'] = str(xlog_size), wd + '/pg_xlog'
result['xlog'] = str(xlog_size), wd + self.wal_directory
return result

@staticmethod
Expand Down Expand Up @@ -276,15 +291,15 @@ def get_df_data(self, work_directory):
result = {'data': [], 'xlog': []}
# obtain the device names
data_dev = self.get_mounted_device(self.get_mount_point(work_directory))
xlog_dev = self.get_mounted_device(self.get_mount_point(work_directory + '/pg_xlog/'))
xlog_dev = self.get_mounted_device(self.get_mount_point(work_directory + self.wal_directory))
if data_dev not in self.df_cache:
data_vfs = os.statvfs(work_directory)
self.df_cache[data_dev] = data_vfs
else:
data_vfs = self.df_cache[data_dev]

if xlog_dev not in self.df_cache:
xlog_vfs = os.statvfs(work_directory + '/pg_xlog/')
xlog_vfs = os.statvfs(work_directory + self.wal_directory)
self.df_cache[xlog_dev] = xlog_vfs
else:
xlog_vfs = self.df_cache[xlog_dev]
Expand Down

0 comments on commit fd37d8c

Please sign in to comment.