Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Issue 2456603003: [Predator] Add local cache for get command output. (Closed)

Created:
4 years, 1 month ago by Sharu Jiang
Modified:
4 years, 1 month ago
CC:
chromium-reviews, infra-reviews+infra_chromium.org, chanli, lijeffrey
Target Ref:
refs/heads/master
Project:
infra
Visibility:
Public.

Description

[Predator] Add local cache for get command output. BUG=605369 Committed: https://chromium.googlesource.com/infra/infra/+/6261f070027929832dd22a109a575733e0db0aee

Patch Set 1 : . #

Total comments: 17

Patch Set 2 : Mock file IO - hold reviewing, fixing a bug. #

Patch Set 3 : Fix mock file test. #

Total comments: 2

Patch Set 4 : Rebase and move LocalCacher to util_script/ #

Total comments: 2

Patch Set 5 : Fix nits. #

Patch Set 6 : . #

Total comments: 8

Patch Set 7 : Rebase. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+85 lines, -3 lines) Patch
M appengine/findit/lib/cache_decorator.py View 1 2 3 1 chunk +1 line, -0 lines 0 comments Download
A appengine/findit/util_scripts/local_cache.py View 1 2 3 4 5 6 1 chunk +45 lines, -0 lines 0 comments Download
M appengine/findit/util_scripts/script_util.py View 1 2 3 4 5 6 2 chunks +5 lines, -2 lines 0 comments Download
A appengine/findit/util_scripts/test/local_cache_test.py View 1 2 3 4 1 chunk +32 lines, -0 lines 0 comments Download
M appengine/findit/util_scripts/test/script_util_test.py View 1 2 3 4 5 6 1 chunk +2 lines, -1 line 0 comments Download

Dependent Patchsets:

Messages

Total messages: 34 (16 generated)
Sharu Jiang
4 years, 1 month ago (2016-10-26 22:40:33 UTC) #3
Sharu Jiang
PTAL :)
4 years, 1 month ago (2016-10-26 22:42:13 UTC) #6
Martin Barbella
https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py File appengine/findit/common/cache_decorator.py (right): https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py#newcode49 appengine/findit/common/cache_decorator.py:49: _DEFAULT_LOCAL_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.cache') This shouldn't use such a ...
4 years, 1 month ago (2016-10-26 23:21:20 UTC) #7
wrengr
https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py File appengine/findit/common/cache_decorator.py (right): https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py#newcode49 appengine/findit/common/cache_decorator.py:49: _DEFAULT_LOCAL_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.cache') On 2016/10/26 23:21:20, Martin Barbella ...
4 years, 1 month ago (2016-10-27 16:36:47 UTC) #8
Sharu Jiang
https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py File appengine/findit/common/cache_decorator.py (right): https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py#newcode49 appengine/findit/common/cache_decorator.py:49: _DEFAULT_LOCAL_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.cache') On 2016/10/27 16:36:47, wrengr wrote: ...
4 years, 1 month ago (2016-10-27 21:59:06 UTC) #9
Sharu Jiang
4 years, 1 month ago (2016-10-27 22:52:29 UTC) #10
wrengr
https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py File appengine/findit/common/cache_decorator.py (right): https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py#newcode52 appengine/findit/common/cache_decorator.py:52: class Cacher(object): On 2016/10/27 21:59:05, sharu jiang wrote: > ...
4 years, 1 month ago (2016-10-28 18:02:01 UTC) #11
stgao
https://codereview.chromium.org/2456603003/diff/60001/appengine/findit/common/cache_decorator.py File appengine/findit/common/cache_decorator.py (right): https://codereview.chromium.org/2456603003/diff/60001/appengine/findit/common/cache_decorator.py#newcode146 appengine/findit/common/cache_decorator.py:146: def __init__(self, cache_dir=_DEFAULT_LOCAL_CACHE_DIR): Can we avoid the default value, ...
4 years, 1 month ago (2016-11-02 02:15:07 UTC) #12
Sharu Jiang
PTAL :) https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py File appengine/findit/common/cache_decorator.py (right): https://codereview.chromium.org/2456603003/diff/20001/appengine/findit/common/cache_decorator.py#newcode52 appengine/findit/common/cache_decorator.py:52: class Cacher(object): On 2016/10/28 18:02:00, wrengr wrote: ...
4 years, 1 month ago (2016-11-08 01:17:12 UTC) #18
stgao
lgtm with nits. https://codereview.chromium.org/2456603003/diff/180001/appengine/findit/util_scripts/local_cache.py File appengine/findit/util_scripts/local_cache.py (right): https://codereview.chromium.org/2456603003/diff/180001/appengine/findit/util_scripts/local_cache.py#newcode32 appengine/findit/util_scripts/local_cache.py:32: logging.error('Failed loading cache: %s', e) Could ...
4 years, 1 month ago (2016-11-08 22:00:43 UTC) #19
Sharu Jiang
https://codereview.chromium.org/2456603003/diff/180001/appengine/findit/util_scripts/local_cache.py File appengine/findit/util_scripts/local_cache.py (right): https://codereview.chromium.org/2456603003/diff/180001/appengine/findit/util_scripts/local_cache.py#newcode32 appengine/findit/util_scripts/local_cache.py:32: logging.error('Failed loading cache: %s', e) On 2016/11/08 22:00:43, stgao ...
4 years, 1 month ago (2016-11-11 00:54:21 UTC) #21
wrengr
https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_scripts/local_cache.py File appengine/findit/util_scripts/local_cache.py (right): https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_scripts/local_cache.py#newcode20 appengine/findit/util_scripts/local_cache.py:20: if not os.path.exists(cache_dir): # pragma: no cover. Again, this ...
4 years, 1 month ago (2016-11-11 18:26:26 UTC) #22
Sharu Jiang
https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_scripts/local_cache.py File appengine/findit/util_scripts/local_cache.py (right): https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_scripts/local_cache.py#newcode20 appengine/findit/util_scripts/local_cache.py:20: if not os.path.exists(cache_dir): # pragma: no cover. On 2016/11/11 ...
4 years, 1 month ago (2016-11-12 01:01:51 UTC) #24
Sharu Jiang
https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_scripts/local_cache.py File appengine/findit/util_scripts/local_cache.py (right): https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_scripts/local_cache.py#newcode27 appengine/findit/util_scripts/local_cache.py:27: return None On 2016/11/12 01:01:50, Sharu Jiang wrote: > ...
4 years, 1 month ago (2016-11-12 02:00:48 UTC) #26
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2456603003/320001
4 years, 1 month ago (2016-11-14 21:00:01 UTC) #29
Sharu Jiang
Commit it since it has been a long time, feel free to post comments if ...
4 years, 1 month ago (2016-11-14 21:00:51 UTC) #30
commit-bot: I haz the power
Committed patchset #8 (id:320001) as https://chromium.googlesource.com/infra/infra/+/6261f070027929832dd22a109a575733e0db0aee
4 years, 1 month ago (2016-11-14 21:16:33 UTC) #32
wrengr
4 years, 1 month ago (2016-11-14 21:48:45 UTC) #33
Message was sent while issue was closed.
https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_...
File appengine/findit/util_scripts/local_cache.py (right):

https://codereview.chromium.org/2456603003/diff/260001/appengine/findit/util_...
appengine/findit/util_scripts/local_cache.py:20: if not
os.path.exists(cache_dir): # pragma: no cover.
On 2016/11/12 01:01:50, Sharu Jiang wrote:
> On 2016/11/11 18:26:26, wrengr wrote:
> > Again, this sort of code has an inherent race condition. Should instead do
> > ``try: os.makedirs(cache_dir); except OSException as e: if ...e is directory
> > already exists...: pass; else: ...handle actual problems...``
> 
> How about using locks? Or there would be a lot exceptions created and thrown
> out.

The problem is in (the interaction with) the filesystem, not in Python itself.
Using a Python lock won't help because some other process could be the one to
create/remove the file/directory. No matter what programming language you're
using, by the time the kernel returns with the answer to ``os.path.exists`` that
answer is already stale wrt the filesystem itself. A lock within Python would
only protect against other threads in the same python process. A lockfile in the
filesystem is guaranteed to be shared across all processes, but that's just
pushing the problem elsewhere (since you need to make sure to access the
lockfile without causing the same race conditions).

There's nothing wrong with using ``try:except:`, it's the right tool for the job
here, and it's not expensive (especially when compared to the syscalls). The
only exceptions we want to discard are the ones where we tried to
``os.makedirs`` but the directory already exists; this is analogous to the
implicit ``else: pass`` branch in the current code. All other exceptions should
be passed along (just as the current code would raise those same exceptions).

Powered by Google App Engine
This is Rietveld 408576698