Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildstream
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
BuildStream
buildstream
Commits
537d9408
Commit
537d9408
authored
6 years ago
by
Valentin David
Browse files
Options
Downloads
Patches
Plain Diff
Move cas server from ref-based to object-based garbage collection.
parent
bf31d6ed
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildstream/_artifactcache/cascache.py
+35
-0
35 additions, 0 deletions
buildstream/_artifactcache/cascache.py
buildstream/_artifactcache/casserver.py
+11
-3
11 additions, 3 deletions
buildstream/_artifactcache/casserver.py
with
46 additions
and
3 deletions
buildstream/_artifactcache/cascache.py
+
35
−
0
View file @
537d9408
...
...
@@ -623,6 +623,41 @@ class CASCache():
# first ref of this list will be the file modified earliest.
return
[
ref
for
_
,
ref
in
sorted
(
zip
(
mtimes
,
refs
))]
# list_objects():
#
# List cached objects in Least Recently Modified (LRM) order.
#
# Returns:
# (list) - A list of objects and timestamps in LRM order
#
def
list_objects
(
self
):
objs
=
[]
mtimes
=
[]
for
root
,
_
,
files
in
os
.
walk
(
os
.
path
.
join
(
self
.
casdir
,
'
objects
'
)):
for
filename
in
files
:
obj_path
=
os
.
path
.
join
(
root
,
filename
)
try
:
mtimes
.
append
(
os
.
path
.
getmtime
(
obj_path
))
except
FileNotFoundError
:
pass
else
:
objs
.
append
(
obj_path
)
# NOTE: Sorted will sort from earliest to latest, thus the
# first element of this list will be the file modified earliest.
return
sorted
(
zip
(
mtimes
,
objs
))
def
clean_up_refs_until
(
self
,
time
):
ref_heads
=
os
.
path
.
join
(
self
.
casdir
,
'
refs
'
,
'
heads
'
)
for
root
,
_
,
files
in
os
.
walk
(
ref_heads
):
for
filename
in
files
:
ref_path
=
os
.
path
.
join
(
root
,
filename
)
# Obtain the mtime (the time a file was last modified)
if
os
.
path
.
getmtime
(
ref_path
)
<
time
:
os
.
unlink
(
ref_path
)
# remove():
#
# Removes the given symbolic ref from the repo.
...
...
This diff is collapsed.
Click to expand it.
buildstream/_artifactcache/casserver.py
+
11
−
3
View file @
537d9408
...
...
@@ -463,12 +463,13 @@ def _clean_up_cache(cas, object_size):
return
0
# obtain a list of LRP artifacts
LRP_
artifa
cts
=
cas
.
list_
ref
s
()
LRP_
obje
cts
=
cas
.
list_
object
s
()
removed_size
=
0
# in bytes
last_mtime
=
0
while
object_size
-
removed_size
>
free_disk_space
:
try
:
to_remove
=
LRP_
artifa
cts
.
pop
(
0
)
# The first element in the list is the LRP
artifa
ct
last_mtime
,
to_remove
=
LRP_
obje
cts
.
pop
(
0
)
# The first element in the list is the LRP
obje
ct
s
except
IndexError
:
# This exception is caught if there are no more artifacts in the list
# LRP_artifacts. This means the the artifact is too large for the filesystem
...
...
@@ -477,7 +478,14 @@ def _clean_up_cache(cas, object_size):
"
the filesystem which mounts the remote
"
"
cache
"
.
format
(
object_size
))
removed_size
+=
cas
.
remove
(
to_remove
,
defer_prune
=
False
)
try
:
size
=
os
.
stat
(
to_remove
).
st_size
os
.
unlink
(
to_remove
)
removed_size
+=
size
except
FileNotFoundError
:
pass
cas
.
clean_up_refs_until
(
last_mtime
)
if
removed_size
>
0
:
logging
.
info
(
"
Successfully removed {} bytes from the cache
"
.
format
(
removed_size
))
...
...
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