Skip to content

Commit

Permalink
Stop services giving the same ID to all their sandboxes
Browse files Browse the repository at this point in the history
This helps in case of task that require multiple sandboxes (like those
of Communication type) to reduce mutual interferences.
  • Loading branch information
lw committed Jul 6, 2014
1 parent 7b692dc commit 8bfe636
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cms/grading/Sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ class IsolateSandbox(SandboxBase):
command number N.
"""
next_id = 0

def __init__(self, file_cacher=None, temp_dir=None):
"""Initialization.
Expand All @@ -765,15 +767,19 @@ def __init__(self, file_cacher=None, temp_dir=None):
"""
SandboxBase.__init__(self, file_cacher)

# Get our shard number, to use as a unique identifier for the
# sandbox on this machine. FIXME This is the only use of
# FileCacher.service, and it's an improper use! Avoid it!
# Isolate only accepts ids between 0 and 99. We assign the
# range [(shard+1)*10, (shard+2)*10) to each Worker and keep
# the range [0, 10) for other uses (command-line scripts like
# cmsMake or direct console users of isolate). Inside each
# range ids are assigned sequentially, with a wrap-around.
# FIXME This is the only use of FileCacher.service, and it's an
# improper use! Avoid it!
if file_cacher is not None and file_cacher.service is not None:
# We add 1 to avoid conflicting with console users of the
# sandbox who use the default box id of 0.
box_id = file_cacher.service.shard + 1
box_id = ((file_cacher.service.shard + 1) * 10
+ (IsolateSandbox.next_id % 10)) % 100
else:
box_id = 0
box_id = IsolateSandbox.next_id % 10
IsolateSandbox.next_id += 1

# We create a directory "tmp" inside the outer temporary directory,
# because the sandbox will bind-mount the inner one. The sandbox also
Expand Down

0 comments on commit 8bfe636

Please sign in to comment.