Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1f100fd4
authored
Feb 26, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: fixed garbage_collector to check child_disks before delete
parent
e80ebd16
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
circle/storage/models.py
+23
-0
circle/storage/tasks/periodic_tasks.py
+1
-5
No files found.
circle/storage/models.py
View file @
1f100fd4
...
...
@@ -10,6 +10,7 @@ from django.utils import timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
model_utils.models
import
TimeStampedModel
from
sizefield.models
import
FileSizeField
from
datetime
import
timedelta
from
acl.models
import
AclBase
from
.tasks
import
local_tasks
,
remote_tasks
...
...
@@ -45,6 +46,11 @@ class DataStore(Model):
else
:
raise
WorkerNotFound
()
def
get_deletable_disks
(
self
):
return
[
disk
.
filename
for
disk
in
self
.
disk_set
.
filter
(
destroyed__isnull
=
False
)
if
disk
.
is_deletable
()]
class
Disk
(
AclBase
,
TimeStampedModel
):
...
...
@@ -126,6 +132,23 @@ class Disk(AclBase, TimeStampedModel):
'raw-rw'
:
'vd'
,
}[
self
.
type
]
def
is_deletable
(
self
):
"""Returns True if no child and disk is destroyed."""
time_before
=
timezone
.
now
()
-
timedelta
(
days
=
1
)
if
self
.
destroyed
>
time_before
or
self
.
has_active_child
():
return
False
else
:
return
True
def
has_active_child
(
self
):
"""Returns True if disk have iactive childs."""
time_before
=
timezone
.
now
()
-
timedelta
(
days
=
1
)
for
child
in
self
.
derivatives
.
all
():
if
child
.
destroyed
>
time_before
or
None
:
return
True
else
:
return
False
def
is_in_use
(
self
):
"""Returns True if disc is attached to an active VM else False"""
return
any
([
i
.
state
!=
'STOPPED'
for
i
in
self
.
instance_set
.
all
()])
...
...
circle/storage/tasks/periodic_tasks.py
View file @
1f100fd4
from
storage.models
import
DataStore
import
os
from
django.utils
import
timezone
from
datetime
import
timedelta
from
manager.mancelery
import
celery
import
logging
from
storage.tasks
import
remote_tasks
...
...
@@ -20,10 +18,8 @@ def garbage_collector(timeout=15):
:type timeoit: int
"""
for
ds
in
DataStore
.
objects
.
all
():
time_before
=
timezone
.
now
()
-
timedelta
(
days
=
1
)
file_list
=
os
.
listdir
(
ds
.
path
)
disk_list
=
[
disk
.
filename
for
disk
in
ds
.
disk_set
.
filter
(
destroyed__lt
=
time_before
)]
disk_list
=
ds
.
get_deletable_disks
()
queue_name
=
ds
.
get_remote_queue_name
(
'storage'
)
for
i
in
set
(
file_list
)
.
intersection
(
disk_list
):
logger
.
info
(
"Image:
%
s at Datastore:
%
s moved to trash folder."
%
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment