Commit 8a130903 authored by Felix Seibert's avatar Felix Seibert
Browse files

new add_folders signature, add_folders randomly respecting osd capacities.

parent c8d32a4a
......@@ -85,13 +85,20 @@ class DataDistribution(object):
self.OSDs[new_osd].add_folder(folder_id, self.OSDs[old_osd.uuid].folders[folder_id])
self.OSDs[old_osd.uuid].remove_folder(folder_id)
def add_folders(self, folders, osd_information=None, ratio_parameter='', random_osd_assignment=False):
def add_folders(self, folders,
osd_information=None, ratio_parameter='', capacity='',
ignore_osd_capacities=True,
random_osd_assignment=False,
ignore_folder_sizes=False):
# TODO update doc
"""
adds a list of folders to the data distribution.
if not specified otherwise, the assignments are calculated using the LPT algorithm.
returns a list of assignments from folders to OSDs, for which (folders) there was previously no assignment.
if the optional arguments are given, OSDs are assigned data proportionally to their ratio_parameter.
the assignment is stable (i.e., folders already assigned to an OSD are not reassigned to another OSD).
"""
new_folders = []
for folder in folders:
......@@ -107,8 +114,8 @@ 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:
print("using random osd assignment")
if random_osd_assignment and ignore_osd_capacities:
print("using totally random osd assignment")
for folder in new_folders:
random_osd = random.choice(list(self.OSDs.values()))
random_osd.add_folder(folder.id, folder.size)
......@@ -116,6 +123,23 @@ class DataDistribution(object):
random_osd.uuid))
return osds_for_new_folders
# random OSD assignment respecting OSD capacities
elif random_osd_assignment and not ignore_osd_capacities:
if osd_information is None or ratio_parameter == '':
raise ValueError("ignore_osd_capacities=False is not possible if osd_information or capacity is"
"not given!")
print("using random osd assignment, respecting osd capacities")
for 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:
suitable_osds.append(one_osd)
suitable_random_osd = random.choice(suitable_osds)
suitable_random_osd.add_folder(folder.id, folder.size)
osds_for_new_folders.append((folder.id,
suitable_random_osd.uuid))
return osds_for_new_folders
# balanced deterministic OSD assignment
# (following largest processing time first or post-greedy approach)
list.sort(new_folders, key=lambda x: x.size, reverse=True)
......
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