Skip to content

Commit

Permalink
split getting array from listing out to _extract_listing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmacro committed Dec 7, 2023
1 parent 16dd424 commit 42b9fdc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
30 changes: 19 additions & 11 deletions lib/reindex/s3_bucketd.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,12 @@ def get_next_upload_id(p):
upload_id=key['value']['UploadId']))
return keys

def _sum_objects(self, bucket, listing):
def _sum_objects(self, bucket, listing, only_latest_when_locked = False):
count = 0
total_size = 0
last_key = None
for status_code, payload in listing:
contents = payload['Versions'] if isinstance(payload, dict) else payload
if contents is None:
_log.error('Invalid contents in listing. bucket:%s status_code:%s'%(bucket.name, status_code))
raise InvalidListing(bucket.name)
for obj in contents:
try:
for obj in listing:
if isinstance(obj['value'], dict):
# bucketd v6 returns a dict:
data = obj.get('value', {})
Expand All @@ -254,16 +250,26 @@ def _sum_objects(self, bucket, listing):
is_latest = obj['key'] != last_key
last_key = obj['key']

if self._only_latest_when_locked and bucket.object_lock_enabled and not is_latest:
if only_latest_when_locked and bucket.object_lock_enabled and not is_latest:
_log.debug('Skipping versioned key: %s'%obj['key'])
continue

count += 1
total_size += size


except InvalidListing:
_log.error('Invalid contents in listing. bucket:%s status_code:%s'%(bucket.name, status_code))
raise InvalidListing(bucket.name)
return count, total_size

def _extract_listing(self, key, listing):
for status_code, payload in listing:
contents = payload[key] if isinstance(payload, dict) else payload
if contents is None:
raise InvalidListing('')
for obj in contents:
yield obj

def count_bucket_contents(self, bucket):

def get_key_marker(p):
Expand All @@ -283,7 +289,8 @@ def get_vid_marker(p):
'versionIdMarker': get_vid_marker,
}

count, total_size = self._sum_objects(bucket, self._list_bucket(bucket.name, **params))
listing = self._list_bucket(bucket.name, **params)
count, total_size = self._sum_objects(bucket, self._extract_listing('Versions', listing), self._only_latest_when_locked)
return BucketContents(
bucket=bucket,
obj_count=count,
Expand Down Expand Up @@ -312,7 +319,8 @@ def get_next_marker(p):
'listingType': 'Delimiter',
}

count, total_size = self._sum_objects(shadow_bucket, self._list_bucket(shadow_bucket_name, **params))
listing = self._list_bucket(shadow_bucket_name, **params)
count, total_size = self._sum_objects(shadow_bucket, self._extract_listing('Contents', listing))
return BucketContents(
bucket=shadow_bucket,
obj_count=0, # MPU parts are not counted towards numberOfObjects
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/cron/testReindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ describe('UtapiReindex', () => {
bucketName: bucket,
contentLength: 1024,
})
.setBucketContent({
bucketName: MPUBucket,
contentLength: 1024,
})
.setBucketCount(count)
.createBuckets();
.setBucketContent({

Check failure on line 234 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 24 spaces but found 20
bucketName: MPUBucket,

Check failure on line 235 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 28 spaces but found 24
contentLength: 1024,

Check failure on line 236 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 28 spaces but found 24
})

Check failure on line 237 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 24 spaces but found 20
.setBucketCount(count)

Check failure on line 238 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 24 spaces but found 20
.createBuckets();

Check failure on line 239 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 24 spaces but found 20

function job() {
reindex._scheduleJob();
Expand Down

0 comments on commit 42b9fdc

Please sign in to comment.