Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Felix Seibert
xtreemfs_client
Commits
902eb9ad
Commit
902eb9ad
authored
Apr 17, 2018
by
Felix Seibert
Browse files
add rebalance_lpt method and test
parent
d3ade2d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_dataDistribution.py
View file @
902eb9ad
...
...
@@ -188,6 +188,23 @@ class TestDataDistribution(unittest.TestCase):
average
=
(
sum
(
folder_sizes
)
*
num_folders
)
/
(
num_osds
*
len
(
osd_capacities
))
self
.
assertEqual
(
average
,
distribution
.
get_average_total_folder_size
())
def
test_rebalance_lpt
(
self
):
folder_sizes
=
[
1
]
num_folders
=
8
osd_capacities
=
[
10
]
num_osds
=
4
distribution
=
dataDistribution
.
DataDistribution
()
distribution
.
add_osd_list
(
create_test_osd_list
(
num_osds
,
osd_capacities
))
distribution
.
add_folders
(
create_test_folder_list
(
num_folders
,
folder_sizes
),
random_osd_assignment
=
True
)
distribution
.
rebalance_lpt
()
osds
=
distribution
.
get_osd_list
()
total_folder_sizes
=
list
(
map
(
lambda
x
:
distribution
.
OSDs
[
x
].
total_folder_size
,
osds
))
# we should obtain a perfectly balanced distribution
self
.
assertEqual
(
min
(
total_folder_sizes
),
max
(
total_folder_sizes
))
def
create_test_osd_list
(
num_osds
,
osd_capacities
):
test_osds
=
[]
for
i
in
range
(
0
,
num_osds
):
...
...
xtreemfs_client/dataDistribution.py
View file @
902eb9ad
...
...
@@ -231,6 +231,27 @@ class DataDistribution(object):
least_used_osd
.
uuid
))
return
osds_for_new_folders
def
rebalance_lpt
(
self
,
rebalance_factor
=
1
,
osd_information
=
None
,
capacity
=
''
):
movements
=
{}
folders_to_be_reassigned
=
[]
reassignment_limit
=
self
.
get_average_total_folder_size
()
*
rebalance_factor
# for each OSD, remove the smallest folder until its total_folder_size does not exceed the reassignment_limit
for
osd
in
self
.
OSDs
.
values
():
while
osd
.
total_folder_size
>
reassignment_limit
:
folder_id
,
folder_size
=
osd
.
get_smallest_folder
()
folders_to_be_reassigned
.
append
(
folder
.
Folder
(
folder_id
,
folder_size
,
None
))
movements
[
folder_id
]
=
osd
.
uuid
osd
.
remove_folder
(
folder_id
)
new_assignments
=
self
.
add_folders
(
folders_to_be_reassigned
,
osd_information
=
osd_information
,
ratio_parameter
=
capacity
)
for
folder_id
,
target
in
new_assignments
:
movements
[
folder_id
]
=
(
movements
[
folder_id
],
target
)
return
movements
def
update_folder
(
self
,
folder
,
size
):
"""
updates the size of a given folder
...
...
Write
Preview
Supports
Markdown
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