Show the sum of every policy's amount in /recon/async

After the release of Swift ver. 2.0.0, some recon responses do not
show each policy's information yet. To make things worse, some recon
results only count on policy-0's score, therefore the total is not
shown in the recon results.

With this patch, async_pending count of recon results becomes
policy-aware. Suppose a number of async_pending files for policy-0 is 2
and a number for policy-1 is 3, recon sums up every policy's amount
as follows.

$ curl http://<host>:<port>/recon/async
{"async_pending": 5} # It showed 2 before this commit

Related-Bug: 1375332
Change-Id: Ifc88b8c9e06b9f022a926a87ed807e938e1e0412
This commit is contained in:
Daisuke Morita 2014-09-30 11:06:08 -04:00
parent 75cca49334
commit 2792fe81a9
1 changed files with 14 additions and 6 deletions

View File

@ -22,17 +22,25 @@ from ConfigParser import ConfigParser
from gettext import gettext as _
from swift.common.utils import get_logger, dump_recon_cache
from swift.obj.diskfile import ASYNCDIR_BASE
def get_async_count(device_dir, logger):
async_count = 0
for i in os.listdir(device_dir):
asyncdir = os.path.join(device_dir, i, "async_pending")
if os.path.isdir(asyncdir):
for entry in os.listdir(asyncdir):
if os.path.isdir(os.path.join(asyncdir, entry)):
async_hdir = os.path.join(asyncdir, entry)
async_count += len(os.listdir(async_hdir))
device = os.path.join(device_dir, i)
for asyncdir in os.listdir(device):
# skip stuff like "accounts", "containers", etc.
if not (asyncdir == ASYNCDIR_BASE or
asyncdir.startswith(ASYNCDIR_BASE + '-')):
continue
async_pending = os.path.join(device, asyncdir)
if os.path.isdir(async_pending):
for entry in os.listdir(async_pending):
if os.path.isdir(os.path.join(async_pending, entry)):
async_hdir = os.path.join(async_pending, entry)
async_count += len(os.listdir(async_hdir))
return async_count