Commit 9404f864 authored by Felix Seibert's avatar Felix Seibert
Browse files

implement random assignment ignoring folder sizes

parent b20524e2
import random
from xtreemfs_client import osd
from xtreemfs_client import folder
class DataDistribution(object):
......@@ -102,12 +103,12 @@ class DataDistribution(object):
the assignment is stable (i.e., folders already assigned to an OSD are not reassigned to another OSD).
new_folders = []
for folder in folders:
containing_osd = self.get_containing_osd(
for a_folder in folders:
containing_osd = self.get_containing_osd(
if containing_osd is not None:
containing_osd.add_folder(, folder.size)
containing_osd.add_folder(, a_folder.size)
if debug:
print("dataDistribution: random_osd_assignment: " + str(random_osd_assignment))
......@@ -116,13 +117,13 @@ class DataDistribution(object):
# totally random OSD assignment, even ignoring OSD capacities
# (might lead to I/O errors when too many groups are assigned to an OSD)
if random_osd_assignment and ignore_osd_capacities:
if random_osd_assignment and ignore_osd_capacities and not ignore_folder_sizes:
if debug:
print("using totally random osd assignment")
for folder in new_folders:
for a_folder in new_folders:
random_osd = random.choice(list(self.OSDs.values()))
random_osd.add_folder(, folder.size)
random_osd.add_folder(, a_folder.size)
return osds_for_new_folders
......@@ -133,20 +134,29 @@ class DataDistribution(object):
"not given!")
if debug:
print("using random osd assignment, respecting osd capacities")
for folder in new_folders:
for a_folder in new_folders:
suitable_osds = [] # list of OSDs with enough capacity
for one_osd in self.OSDs.values():
if osd_information[one_osd.uuid][capacity] - one_osd.total_folder_size - folder.size >= 0:
if osd_information[one_osd.uuid][capacity] - one_osd.total_folder_size - a_folder.size >= 0:
suitable_random_osd = random.choice(suitable_osds)
suitable_random_osd.add_folder(, folder.size)
suitable_random_osd.add_folder(, a_folder.size)
return osds_for_new_folders
# random OSD assignment ignoring folder sizes
elif random_osd_assignment and ignore_folder_sizes:
return None
if debug:
print("using random osd assignment ignoring folder sizes")
average_folder_size = self.get_average_folder_size()
if average_folder_size == 0:
average_folder_size = 1
modified_folders = list(map(lambda f: folder.Folder(, average_folder_size, f.origin), folders))
return self.add_folders(modified_folders)
# balanced deterministic OSD assignment
# (following largest processing time first or post-greedy approach)
......@@ -164,15 +174,15 @@ class DataDistribution(object):
for osd_uuid in self.OSDs.keys():
osd_ratios[osd_uuid] = float(1)
for folder in new_folders:
for a_folder in new_folders:
least_used_osd = None
for one_osd in self.OSDs.values():
if (least_used_osd is None) or \
one_osd.total_folder_size / osd_ratios[one_osd.uuid] \
<= least_used_osd.total_folder_size / osd_ratios[least_used_osd.uuid]:
least_used_osd = one_osd
least_used_osd.add_folder(, folder.size)
least_used_osd.add_folder(, a_folder.size)
return osds_for_new_folders
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment