Skip to content

Commit 1ff092d

Browse files
Do safe preprocess optimizations. (#4444)
1. Don't unnecessarily list features about blobs other than names 2. Memoize leak blacklist stuff. 3. Properly skip cleanup.
1 parent 413f9cc commit 1ff092d

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/clusterfuzz/_internal/bot/tasks/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class AlreadyRunningError(Error):
8080
def cleanup_task_state():
8181
"""Cleans state before and after a task is executed."""
8282
# Cleanup stale processes.
83+
if not environment.is_tworker():
84+
return
8385
process_handler.cleanup_stale_processes()
8486

8587
# Clear build urls, temp and testcase directories.
@@ -468,7 +470,6 @@ def process_command_impl(task_name, task_argument, job_name, high_end,
468470
return run_command(task_name, task_argument, job_name, uworker_env)
469471
finally:
470472
# Final clean up.
471-
if not environment.is_tworker():
472-
cleanup_task_state()
473+
cleanup_task_state()
473474
if 'CF_TASK_ID' in os.environ:
474475
del os.environ['CF_TASK_ID']

src/clusterfuzz/_internal/fuzzing/leak_blacklist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import re
1818

1919
from clusterfuzz._internal.base import errors
20+
from clusterfuzz._internal.base import memoize
2021
from clusterfuzz._internal.datastore import data_handler
2122
from clusterfuzz._internal.datastore import data_types
2223
from clusterfuzz._internal.datastore import ndb_utils
@@ -65,7 +66,9 @@ def cleanup_global_blacklist():
6566
ndb_utils.delete_multi(blacklists_to_delete)
6667

6768

69+
@memoize.wrap(memoize.Memcache(60 * 10))
6870
def get_global_blacklisted_functions():
71+
"""Gets global blacklisted functions."""
6972
# Copy global blacklist into local blacklist.
7073
global_blacklists = data_types.Blacklist.query(
7174
data_types.Blacklist.tool_name == LSAN_TOOL_NAME)

src/clusterfuzz/_internal/google_cloud_utils/storage.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def get_bucket(self, name):
125125
"""Get a bucket."""
126126
raise NotImplementedError
127127

128-
def list_blobs(self, remote_path, recursive=True):
128+
def list_blobs(self, remote_path, recursive=True, names_only=False):
129129
"""List the blobs under the remote path."""
130130
raise NotImplementedError
131131

@@ -228,7 +228,7 @@ def get_bucket(self, name):
228228

229229
raise
230230

231-
def list_blobs(self, remote_path, recursive=True):
231+
def list_blobs(self, remote_path, recursive=True, names_only=False):
232232
"""List the blobs under the remote path."""
233233
bucket_name, path = get_bucket_name_and_path(remote_path)
234234

@@ -244,7 +244,13 @@ def list_blobs(self, remote_path, recursive=True):
244244
else:
245245
delimiter = '/'
246246

247-
iterator = bucket.list_blobs(prefix=path, delimiter=delimiter)
247+
if names_only:
248+
fields = 'items(name),nextPageToken'
249+
else:
250+
fields = None
251+
252+
iterator = bucket.list_blobs(
253+
prefix=path, delimiter=delimiter, fields=fields)
248254
for blob in iterator:
249255
properties['bucket'] = bucket_name
250256
properties['name'] = blob.name
@@ -567,8 +573,9 @@ def _list_files_nonrecursive(self, fs_path):
567573
for filename in os.listdir(fs_path):
568574
yield os.path.join(fs_path, filename)
569575

570-
def list_blobs(self, remote_path, recursive=True):
576+
def list_blobs(self, remote_path, recursive=True, names_only=False):
571577
"""List the blobs under the remote path."""
578+
del names_only
572579
bucket, _ = get_bucket_name_and_path(remote_path)
573580
fs_path = self.convert_path(remote_path)
574581

@@ -1070,7 +1077,8 @@ def get_blobs(cloud_storage_path, recursive=True):
10701077
exception_types=_TRANSIENT_ERRORS)
10711078
def list_blobs(cloud_storage_path, recursive=True):
10721079
"""Return blob names under the given cloud storage path."""
1073-
for blob in _provider().list_blobs(cloud_storage_path, recursive=recursive):
1080+
for blob in _provider().list_blobs(
1081+
cloud_storage_path, recursive=recursive, names_only=True):
10741082
yield blob['name']
10751083

10761084

0 commit comments

Comments
 (0)