Skip to content

Commit

Permalink
Merge pull request #907 from dannon/quota_bugfix
Browse files Browse the repository at this point in the history
Quota bugfixes
  • Loading branch information
blankenberg committed Oct 14, 2015
2 parents 977ef6b + c05315c commit 005561c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/galaxy/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,14 +1322,14 @@ def path_rewriter( path ):
tool=self.tool, stdout=job.stdout, stderr=job.stderr )
job.command_line = self.command_line

bytes = 0
collected_bytes = 0
# Once datasets are collected, set the total dataset size (includes extra files)
for dataset_assoc in job.output_datasets:
dataset_assoc.dataset.dataset.set_total_size()
bytes += dataset_assoc.dataset.dataset.get_total_size()
collected_bytes += dataset_assoc.dataset.dataset.get_total_size()

if job.user:
job.user.total_disk_usage += bytes
job.user.adjust_total_disk_usage(collected_bytes)

# Empirically, we need to update job.user and
# job.workflow_invocation_step.workflow_invocation in separate
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/hdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def purge( self, hda, flush=True):
super( HDAManager, self ).purge( hda, flush=flush )
# decrease the user's space used
if quota_amount_reduction:
user.total_disk_usage -= quota_amount_reduction
user.adjust_total_disk_usage(-quota_amount_reduction)
return hda

# .... states
Expand Down
5 changes: 4 additions & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def set_disk_usage( self, bytes ):

total_disk_usage = property( get_disk_usage, set_disk_usage )

def adjust_total_disk_usage( self, amount ):
self.disk_usage = func.coalesce(self.table.c.disk_usage, 0) + amount

@property
def nice_total_disk_usage( self ):
"""
Expand Down Expand Up @@ -1103,7 +1106,7 @@ def add_dataset( self, dataset, parent_id=None, genome_build=None, set_hid=True,
if set_hid:
dataset.hid = self._next_hid()
if quota and self.user:
self.user.total_disk_usage += dataset.quota_amount( self.user )
self.user.adjust_total_disk_usage(dataset.quota_amount(self.user))
dataset.history = self
if genome_build not in [None, '?']:
self.genome_build = genome_build
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/web/framework/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def handle_user_login( self, user ):
if prev_galaxy_session.user is None:
# Increase the user's disk usage by the amount of the previous history's datasets if they didn't already own it.
for hda in history.datasets:
user.total_disk_usage += hda.quota_amount( user )
user.adjust_total_disk_usage(hda.quota_amount(user))
elif self.galaxy_session.current_history:
history = self.galaxy_session.current_history
if (not history and users_last_session and
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/controllers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ def _purge( self, trans, dataset_id ):
# HDA is purgeable
# Decrease disk usage first
if user:
user.total_disk_usage -= hda.quota_amount( user )
user.adjust_total_disk_usage(-hda.quota_amount(user))
# Mark purged
hda.purged = True
trans.sa_session.add( hda )
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/webapps/galaxy/controllers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _list_delete( self, trans, histories, purge=False ):
if purge and trans.app.config.allow_user_dataset_purge:
for hda in history.datasets:
if trans.user:
trans.user.total_disk_usage -= hda.quota_amount( trans.user )
trans.user.adjust_total_disk_usage(-hda.quota_amount(trans.user))
hda.purged = True
trans.sa_session.add( hda )
trans.log_event( "HDA id %s has been purged" % hda.id )
Expand Down Expand Up @@ -1112,7 +1112,7 @@ def purge_deleted_datasets( self, trans ):
if not hda.deleted or hda.purged:
continue
if trans.user:
trans.user.total_disk_usage -= hda.quota_amount( trans.user )
trans.user.adjust_total_disk_usage(-hda.quota_amount(trans.user))
hda.purged = True
trans.sa_session.add( hda )
trans.log_event( "HDA id %s has been purged" % hda.id )
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def delete_current( self, trans, purge=False ):
if purge and trans.app.config.allow_user_dataset_purge:
for hda in history.datasets:
if trans.user:
trans.user.total_disk_usage -= hda.quota_amount( trans.user )
trans.user.adjust_total_disk_usage(-hda.quota_amount(trans.user))
hda.purged = True
trans.sa_session.add( hda )
trans.log_event( "HDA id %s has been purged" % hda.id )
Expand Down
2 changes: 1 addition & 1 deletion scripts/cleanup_datasets/cleanup_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def _purge_dataset( app, dataset, remove_from_disk, info_only=False ):
if hda.history.user is not None and hda.history.user not in usage_users:
usage_users.append( hda.history.user )
for user in usage_users:
user.total_disk_usage -= dataset.get_total_size()
user.adjust_total_disk_usage(-dataset.get_total_size())
app.sa_session.add( user )
print "Purging dataset id", dataset.id
dataset.purged = True
Expand Down
11 changes: 11 additions & 0 deletions test/unit/test_galaxy_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ def test_collections_in_library_folders(self):
# self.assertEquals(len(loaded_dataset_collection.datasets), 2)
# assert loaded_dataset_collection.collection_type == "pair"

def test_default_disk_usage( self ):
model = self.model

u = model.User( email="disk_default@test.com", password="password" )
self.persist( u )
u.adjust_total_disk_usage( 1 )
u_id = u.id
self.expunge()
user_reload = model.session.query( model.User ).get( u_id )
assert user_reload.disk_usage == 1

def test_basic( self ):
model = self.model

Expand Down

0 comments on commit 005561c

Please sign in to comment.