Skip to content

Commit 5fd16b3

Browse files
committed
Add a simple prediction script for metadatat size
Signed-off-by: mulhern <amulhern@redhat.com>
1 parent e2898db commit 5fd16b3

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
pylint
2222
python3-dbus
2323
python3-dbus-python-client-gen
24+
python3-justbytes
2425
python3-matplotlib
2526
python3-numpy
2627
python3-pygithub

.github/workflows/weekly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
pylint
2020
python3-dbus
2121
python3-dbus-python-client-gen
22+
python3-justbytes
2223
python3-matplotlib
2324
python3-numpy
2425
python3-pygithub
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/python3
2+
"""
3+
pool_metadata_size_estimate: estimate the inrease of pool level metadata due to
4+
addition of blockdevs.
5+
"""
6+
7+
# isort: STDLIB
8+
import argparse
9+
10+
# isort: THIRDPARTY
11+
from justbytes import Range
12+
13+
STRING = 255
14+
UUID = 36
15+
16+
17+
def metadata_str(value):
18+
"""
19+
Parse a value representing the size of a metadata string.
20+
"""
21+
value = int(value)
22+
if value > 255:
23+
raise argparse.ArgumentTypeError(
24+
f"Exceeds maximum length {STRING} for metadata string."
25+
)
26+
27+
if value < 0:
28+
raise argparse.ArgumentTypeError("Negative lengths prohbited.")
29+
30+
return value
31+
32+
33+
def nat(value):
34+
"""
35+
Parse a value representing a natural number.
36+
"""
37+
value = int(value)
38+
if value < 0:
39+
raise argparse.ArgumentTypeError("Must be a natural number.")
40+
return value
41+
42+
43+
def gen_parser():
44+
"""
45+
Generate parser.
46+
"""
47+
parser = argparse.ArgumentParser(
48+
description=(
49+
"Calculate size increase in Stratis pool-level metadata due to "
50+
"addition of new devices."
51+
)
52+
)
53+
54+
parser.add_argument(
55+
"num_devices",
56+
help="Number of devices to be added",
57+
type=nat,
58+
)
59+
60+
parser.add_argument(
61+
"--hardware-info",
62+
dest="hardware_info",
63+
help="Bytes required to represent hardware info.",
64+
type=metadata_str,
65+
)
66+
67+
parser.add_argument(
68+
"--user-info",
69+
dest="user_info",
70+
help="Bytes required to represent user info.",
71+
type=metadata_str,
72+
)
73+
74+
return parser
75+
76+
77+
def f(*, hardware_info=None, user_info=None):
78+
"""
79+
Calculate the bytes required to store num_devices in metadata.
80+
81+
:param hardware_info: the len of the hardware info
82+
:param user_info: the len of the user info
83+
"""
84+
commas = (0 if hardware_info is None else 1) + (0 if user_info is None else 1)
85+
86+
m = (
87+
commas
88+
+ (0 if hardware_info is None else hardware_info + 18)
89+
+ (0 if user_info is None else user_info + 13)
90+
+ (UUID + 9)
91+
+ 3
92+
)
93+
94+
return m
95+
96+
97+
def main():
98+
"""
99+
Main method
100+
"""
101+
102+
parser = gen_parser()
103+
args = parser.parse_args()
104+
105+
num_devices = args.num_devices
106+
107+
user_info = args.user_info
108+
hardware_info = args.hardware_info
109+
110+
m = f(hardware_info=hardware_info, user_info=user_info)
111+
print(f"Slope: {m} bytes")
112+
prediction = m * num_devices
113+
print(f"Predicted use: {prediction} bytes, approx {Range(prediction)}")
114+
115+
116+
if __name__ == "__main__":
117+
main()

0 commit comments

Comments
 (0)