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

Side by Side Diff: appengine/isolate/model.py

Issue 1866753008: Add ability to linkify hashes on isolate server (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Address feedback Created 4 years, 8 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
OLDNEW
1 # Copyright 2014 The LUCI Authors. All rights reserved. 1 # Copyright 2014 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed by the Apache v2.0 license that can be 2 # Use of this source code is governed by the Apache v2.0 license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This module defines Isolate Server model(s).""" 5 """This module defines Isolate Server model(s)."""
6 6
7 import datetime 7 import datetime
8 import hashlib 8 import hashlib
9 import logging 9 import logging
10 import random 10 import random
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return entry_key_from_id('%s/%s' % (namespace, hash_key)) 126 return entry_key_from_id('%s/%s' % (namespace, hash_key))
127 127
128 128
129 def entry_key_from_id(key_id): 129 def entry_key_from_id(key_id):
130 """Returns the ndb.Key for the key_id.""" 130 """Returns the ndb.Key for the key_id."""
131 hash_key = key_id.rsplit('/', 1)[1] 131 hash_key = key_id.rsplit('/', 1)[1]
132 N = config.settings().sharding_letters 132 N = config.settings().sharding_letters
133 return ndb.Key( 133 return ndb.Key(
134 ContentEntry, key_id, 134 ContentEntry, key_id,
135 parent=datastore_utils.shard_key(hash_key, N, 'ContentShard')) 135 parent=datastore_utils.shard_key(hash_key, N, 'ContentShard'))
136 136
M-A Ruel 2016/04/14 14:05:06 2 lines between file level symbols
kjlubick 2016/04/14 14:57:37 Done.
137 def get_content(namespace, hash_key):
138 """Returns the content from either memcache or datastore.
M-A Ruel 2016/04/14 14:05:06 Add a note that it doesn't return content from GCS
kjlubick 2016/04/14 14:57:37 Done.
139
140 Raises LookupError if the content cannot be found.
141 Raises ValueError if the hash_key is invalid."""
M-A Ruel 2016/04/14 14:05:06 """ on a separate line
kjlubick 2016/04/14 14:57:37 Done.
142 memcache_entry = memcache.get(hash_key, namespace='table_%s' % namespace)
143 if memcache_entry is not None:
144 return memcache_entry
145 else:
146 # Raises ValueError
147 key = get_entry_key(namespace, hash_key)
148 entity = key.get()
149 if entity is None:
150 raise LookupError("namespace %s, key %s does not refer to anything" %
151 (namespace, hash_key))
152 return entity.content
153
137 154
138 def expiration_jitter(now, expiration): 155 def expiration_jitter(now, expiration):
139 """Returns expiration/next_tag pair to set in a ContentEntry.""" 156 """Returns expiration/next_tag pair to set in a ContentEntry."""
140 jittered = random.uniform(1, 1.2) * expiration 157 jittered = random.uniform(1, 1.2) * expiration
141 expiration = now + datetime.timedelta(seconds=jittered) 158 expiration = now + datetime.timedelta(seconds=jittered)
142 next_tag = now + datetime.timedelta(seconds=jittered*0.1) 159 next_tag = now + datetime.timedelta(seconds=jittered*0.1)
143 return expiration, next_tag 160 return expiration, next_tag
144 161
145 162
146 def expand_content(namespace, source): 163 def expand_content(namespace, source):
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ndb.delete_multi(keys_to_delete) 228 ndb.delete_multi(keys_to_delete)
212 # Note that some content entries may NOT have corresponding GS files. That 229 # Note that some content entries may NOT have corresponding GS files. That
213 # happens for small entries stored inline in the datastore or memcache. Since 230 # happens for small entries stored inline in the datastore or memcache. Since
214 # this function operates only on keys, it can't distinguish "large" entries 231 # this function operates only on keys, it can't distinguish "large" entries
215 # stored in GS from "small" ones stored inline. So instead it tries to delete 232 # stored in GS from "small" ones stored inline. So instead it tries to delete
216 # all corresponding GS files, silently skipping ones that are not there. 233 # all corresponding GS files, silently skipping ones that are not there.
217 gcs.delete_files( 234 gcs.delete_files(
218 config.settings().gs_bucket, 235 config.settings().gs_bucket,
219 (i.id() for i in keys_to_delete), 236 (i.id() for i in keys_to_delete),
220 ignore_missing=True) 237 ignore_missing=True)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698