Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
4b80f4c1
Commit
4b80f4c1
authored
8 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
Task #10009: updating of cache; more logging; less frequent check
parent
b6d400b2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/DataManagement/StorageQueryService/cache.py
+25
-14
25 additions, 14 deletions
SAS/DataManagement/StorageQueryService/cache.py
with
25 additions
and
14 deletions
SAS/DataManagement/StorageQueryService/cache.py
+
25
−
14
View file @
4b80f4c1
...
@@ -28,7 +28,7 @@ from lofar.mom.momqueryservice.config import DEFAULT_MOMQUERY_BUSNAME, DEFAULT_M
...
@@ -28,7 +28,7 @@ from lofar.mom.momqueryservice.config import DEFAULT_MOMQUERY_BUSNAME, DEFAULT_M
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
MAX_CACHE_ENTRY_AGE
=
datetime
.
timedelta
(
minutes
=
60
)
MAX_CACHE_ENTRY_AGE
=
datetime
.
timedelta
(
days
=
1
)
class
CacheManager
:
class
CacheManager
:
def
__init__
(
self
,
def
__init__
(
self
,
...
@@ -201,11 +201,17 @@ class CacheManager:
...
@@ -201,11 +201,17 @@ class CacheManager:
with
self
.
_cacheLock
:
with
self
.
_cacheLock
:
path_cache
=
self
.
_cache
[
'
path_du_results
'
]
path_cache
=
self
.
_cache
[
'
path_du_results
'
]
old_entries
=
[
cache_entry
for
cache_entry
in
path_cache
.
values
()
old_entries
=
[
cache_entry
for
cache_entry
in
path_cache
.
values
()
if
now
-
cache_entry
[
'
cache_timestamp
'
]
>
MAX_CACHE_ENTRY_AGE
if
now
-
cache_entry
[
'
cache_timestamp
'
]
>
MAX_CACHE_ENTRY_AGE
]
or
cache_entry
.
get
(
'
needs_update
'
)]
needs_update_entries
=
[
cache_entry
for
cache_entry
in
path_cache
.
values
()
if
cache_entry
.
get
(
'
needs_update
'
,
False
)]
if
old_entries
:
updateable_entries
=
old_entries
+
needs_update_entries
logger
.
info
(
'
%s old cache entries need to be updated
'
,
len
(
old_entries
))
if
updateable_entries
:
logger
.
info
(
'
%s old cache entries need to be updated, #age:%s #needs_update:%s
'
,
len
(
updateable_entries
),
len
(
old_entries
),
len
(
needs_update_entries
))
# sort them oldest to newest, 'needs_update' paths first
# sort them oldest to newest, 'needs_update' paths first
def
compareFunc
(
entry1
,
entry2
):
def
compareFunc
(
entry1
,
entry2
):
...
@@ -220,29 +226,34 @@ class CacheManager:
...
@@ -220,29 +226,34 @@ class CacheManager:
return
1
return
1
return
0
return
0
old
_entries
=
sorted
(
old
_entries
,
cmp
=
compareFunc
)
updateable
_entries
=
sorted
(
updateable
_entries
,
cmp
=
compareFunc
)
cacheUpdateStart
=
datetime
.
datetime
.
utcnow
()
cacheUpdateStart
=
datetime
.
datetime
.
utcnow
()
for
i
,
cache_entry
in
enumerate
(
old
_entries
):
for
i
,
cache_entry
in
enumerate
(
updateable
_entries
):
try
:
try
:
path
=
cache_entry
.
get
(
'
path
'
)
path
=
cache_entry
.
get
(
'
path
'
)
if
path
:
if
path
:
logger
.
info
(
'
examining old entry %s/%s in cache: %s
'
,
i
,
len
(
old_entries
),
path
)
logger
.
info
(
'
examining entry %s/%s in cache. timestamp:%s age:%s needs_update:%s path: %s
'
,
i
,
len
(
updateable_entries
),
cache_entry
[
'
cache_timestamp
'
],
now
-
cache_entry
[
'
cache_timestamp
'
],
cache_entry
.
get
(
'
needs_update
'
,
False
),
path
)
result
=
du_getDiskUsageForPath
(
path
)
result
=
du_getDiskUsageForPath
(
path
)
if
result
[
'
found
'
]:
logger
.
debug
(
'
trying to update old entry in cache: %s
'
,
result
)
logger
.
debug
(
'
trying to update old entry in cache: %s
'
,
result
)
self
.
_updateCache
(
result
)
self
.
_updateCache
(
result
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
logger
.
error
(
str
(
e
))
if
not
self
.
_updateCacheThreadRunning
:
if
not
self
.
_updateCacheThreadRunning
:
return
return
if
datetime
.
datetime
.
utcnow
()
-
cacheUpdateStart
>
datetime
.
timedelta
(
minutes
=
5
):
if
datetime
.
datetime
.
utcnow
()
-
cacheUpdateStart
>
datetime
.
timedelta
(
minutes
=
10
):
# break out of cache update loop if full update takes more than
5
min
# break out of cache update loop if full update takes more than
10
min
# next loop we'll start with the oldest cache entries again
# next loop we'll start with the oldest cache entries again
logger
.
info
(
'
skipping remaining %s old cache entries updates, they will be updated next time
'
,
len
(
old
_entries
)
-
i
)
logger
.
info
(
'
skipping remaining %s old cache entries updates, they will be updated next time
'
,
len
(
updateable
_entries
)
-
i
)
break
break
for
i
in
range
(
60
):
for
i
in
range
(
60
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment