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

Side by Side Diff: client/run_isolated.py

Issue 2853413002: Add unit test to clean_caches() (Closed)
Patch Set: os.path.relpath Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/named_cache.py ('k') | client/tests/isolateserver_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2012 The LUCI Authors. All rights reserved. 2 # Copyright 2012 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 """Runs a command with optional isolated input/output. 6 """Runs a command with optional isolated input/output.
7 7
8 Despite name "run_isolated", can run a generic non-isolated command specified as 8 Despite name "run_isolated", can run a generic non-isolated command specified as
9 args. 9 args.
10 10
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 pins={ 817 pins={
818 'client_package': { 818 'client_package': {
819 'package_name': client.package_name, 819 'package_name': client.package_name,
820 'version': client.instance_id, 820 'version': client.instance_id,
821 }, 821 },
822 'packages': package_pins, 822 'packages': package_pins,
823 }) 823 })
824 824
825 825
826 def clean_caches(options, isolate_cache, named_cache_manager): 826 def clean_caches(options, isolate_cache, named_cache_manager):
827 """Trims isolated and named caches.""" 827 """Trims isolated and named caches.
828 # Which cache to trim first? Which of caches was used least recently? 828
829 The goal here is to coherently trim both caches, deleting older items
830 independent of which container they belong to.
831 """
832 # TODO(maruel): Trim CIPD cache the same way.
833 total = 0
829 with named_cache_manager.open(): 834 with named_cache_manager.open():
830 oldest_isolated = isolate_cache.get_oldest() 835 oldest_isolated = isolate_cache.get_oldest()
831 oldest_named = named_cache_manager.get_oldest() 836 oldest_named = named_cache_manager.get_oldest()
832 trimmers = [ 837 trimmers = [
833 ( 838 (
834 isolate_cache.trim, 839 isolate_cache.trim,
835 isolate_cache.get_timestamp(oldest_isolated) if oldest_isolated else 0, 840 isolate_cache.get_timestamp(oldest_isolated) if oldest_isolated else 0,
836 ), 841 ),
837 ( 842 (
838 lambda: named_cache_manager.trim(options.min_free_space), 843 lambda: named_cache_manager.trim(options.min_free_space),
839 named_cache_manager.get_timestamp(oldest_named) if oldest_named else 0, 844 named_cache_manager.get_timestamp(oldest_named) if oldest_named else 0,
840 ), 845 ),
841 ] 846 ]
842 trimmers.sort(key=lambda (_, ts): ts) 847 trimmers.sort(key=lambda (_, ts): ts)
848 # TODO(maruel): This is incorrect, we want to trim 'items' that are strictly
849 # the oldest independent of in which cache they live in. Right now, the
850 # cache with the oldest item pays the price.
843 for trim, _ in trimmers: 851 for trim, _ in trimmers:
844 trim() 852 total += trim()
845 isolate_cache.cleanup() 853 isolate_cache.cleanup()
854 return total
846 855
847 856
848 def create_option_parser(): 857 def create_option_parser():
849 parser = logging_utils.OptionParserWithLogging( 858 parser = logging_utils.OptionParserWithLogging(
850 usage='%prog <options> [command to run or extra args]', 859 usage='%prog <options> [command to run or extra args]',
851 version=__version__, 860 version=__version__,
852 log_file=RUN_ISOLATED_LOG_FILE) 861 log_file=RUN_ISOLATED_LOG_FILE)
853 parser.add_option( 862 parser.add_option(
854 '--clean', action='store_true', 863 '--clean', action='store_true',
855 help='Cleans the cache, trimming it necessary and remove corrupted items ' 864 help='Cleans the cache, trimming it necessary and remove corrupted items '
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 return 1 1060 return 1
1052 1061
1053 1062
1054 if __name__ == '__main__': 1063 if __name__ == '__main__':
1055 subprocess42.inhibit_os_error_reporting() 1064 subprocess42.inhibit_os_error_reporting()
1056 # Ensure that we are always running with the correct encoding. 1065 # Ensure that we are always running with the correct encoding.
1057 fix_encoding.fix_encoding() 1066 fix_encoding.fix_encoding()
1058 file_path.enable_symlink() 1067 file_path.enable_symlink()
1059 1068
1060 sys.exit(main(sys.argv[1:])) 1069 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « client/named_cache.py ('k') | client/tests/isolateserver_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698