|
15 | 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 |
|
17 | 17 | import storage from "local-storage-fallback";
|
18 |
| -import { IErasureCodeCalc, IStorageFactors } from "./types"; |
19 | 18 |
|
20 | 19 | import get from "lodash/get";
|
21 | 20 |
|
22 |
| -const minMemReq = 2147483648; // Minimal Memory required for MinIO in bytes |
23 |
| - |
24 | 21 | const units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
25 | 22 | const k8sUnits = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"];
|
26 |
| -const k8sCalcUnits = ["B", ...k8sUnits]; |
27 | 23 |
|
28 | 24 | export const niceBytes = (x: string, showK8sUnits: boolean = false) => {
|
29 | 25 | let n = parseInt(x, 10) || 0;
|
@@ -54,170 +50,6 @@ export const clearSession = () => {
|
54 | 50 | deleteCookie("idp-refresh-token");
|
55 | 51 | };
|
56 | 52 |
|
57 |
| -//getBytes, converts from a value and a unit from units array to bytes as a string |
58 |
| -export const getBytes = ( |
59 |
| - value: string, |
60 |
| - unit: string, |
61 |
| - fromk8s: boolean = false, |
62 |
| -): string => { |
63 |
| - return getBytesNumber(value, unit, fromk8s).toString(10); |
64 |
| -}; |
65 |
| - |
66 |
| -//getBytesNumber, converts from a value and a unit from units array to bytes |
67 |
| -const getBytesNumber = ( |
68 |
| - value: string, |
69 |
| - unit: string, |
70 |
| - fromk8s: boolean = false, |
71 |
| -): number => { |
72 |
| - const vl: number = parseFloat(value); |
73 |
| - |
74 |
| - const unitsTake = fromk8s ? k8sCalcUnits : units; |
75 |
| - |
76 |
| - const powFactor = unitsTake.findIndex((element) => element === unit); |
77 |
| - |
78 |
| - if (powFactor === -1) { |
79 |
| - return 0; |
80 |
| - } |
81 |
| - const factor = Math.pow(1024, powFactor); |
82 |
| - const total = vl * factor; |
83 |
| - |
84 |
| - return total; |
85 |
| -}; |
86 |
| - |
87 |
| -export const setMemoryResource = ( |
88 |
| - memorySize: number, |
89 |
| - capacitySize: string, |
90 |
| - maxMemorySize: number, |
91 |
| -) => { |
92 |
| - // value always comes as Gi |
93 |
| - const requestedSizeBytes = getBytes(memorySize.toString(10), "Gi", true); |
94 |
| - const memReqSize = parseInt(requestedSizeBytes, 10); |
95 |
| - if (maxMemorySize === 0) { |
96 |
| - return { |
97 |
| - error: "There is no memory available for the selected number of nodes", |
98 |
| - request: 0, |
99 |
| - limit: 0, |
100 |
| - }; |
101 |
| - } |
102 |
| - |
103 |
| - if (maxMemorySize < minMemReq) { |
104 |
| - return { |
105 |
| - error: "There are not enough memory resources available", |
106 |
| - request: 0, |
107 |
| - limit: 0, |
108 |
| - }; |
109 |
| - } |
110 |
| - |
111 |
| - if (memReqSize < minMemReq) { |
112 |
| - return { |
113 |
| - error: "The requested memory size must be greater than 2Gi", |
114 |
| - request: 0, |
115 |
| - limit: 0, |
116 |
| - }; |
117 |
| - } |
118 |
| - if (memReqSize > maxMemorySize) { |
119 |
| - return { |
120 |
| - error: |
121 |
| - "The requested memory is greater than the max available memory for the selected number of nodes", |
122 |
| - request: 0, |
123 |
| - limit: 0, |
124 |
| - }; |
125 |
| - } |
126 |
| - |
127 |
| - const capSize = parseInt(capacitySize, 10); |
128 |
| - let memLimitSize = memReqSize; |
129 |
| - // set memory limit based on the capacitySize |
130 |
| - // if capacity size is lower than 1TiB we use the limit equal to request |
131 |
| - if (capSize >= parseInt(getBytes("1", "Pi", true), 10)) { |
132 |
| - memLimitSize = Math.max( |
133 |
| - memReqSize, |
134 |
| - parseInt(getBytes("64", "Gi", true), 10), |
135 |
| - ); |
136 |
| - } else if (capSize >= parseInt(getBytes("100", "Ti"), 10)) { |
137 |
| - memLimitSize = Math.max( |
138 |
| - memReqSize, |
139 |
| - parseInt(getBytes("32", "Gi", true), 10), |
140 |
| - ); |
141 |
| - } else if (capSize >= parseInt(getBytes("10", "Ti"), 10)) { |
142 |
| - memLimitSize = Math.max( |
143 |
| - memReqSize, |
144 |
| - parseInt(getBytes("16", "Gi", true), 10), |
145 |
| - ); |
146 |
| - } else if (capSize >= parseInt(getBytes("1", "Ti"), 10)) { |
147 |
| - memLimitSize = Math.max( |
148 |
| - memReqSize, |
149 |
| - parseInt(getBytes("8", "Gi", true), 10), |
150 |
| - ); |
151 |
| - } |
152 |
| - |
153 |
| - return { |
154 |
| - error: "", |
155 |
| - request: memReqSize, |
156 |
| - limit: memLimitSize, |
157 |
| - }; |
158 |
| -}; |
159 |
| - |
160 |
| -// Erasure Code Parity Calc |
161 |
| -export const erasureCodeCalc = ( |
162 |
| - parityValidValues: string[], |
163 |
| - totalDisks: number, |
164 |
| - pvSize: number, |
165 |
| - totalNodes: number, |
166 |
| -): IErasureCodeCalc => { |
167 |
| - // Parity Values is empty |
168 |
| - if (parityValidValues.length < 1) { |
169 |
| - return { |
170 |
| - error: 1, |
171 |
| - defaultEC: "", |
172 |
| - erasureCodeSet: 0, |
173 |
| - maxEC: "", |
174 |
| - rawCapacity: "0", |
175 |
| - storageFactors: [], |
176 |
| - }; |
177 |
| - } |
178 |
| - |
179 |
| - const totalStorage = totalDisks * pvSize; |
180 |
| - const maxEC = parityValidValues[0]; |
181 |
| - const maxParityNumber = parseInt(maxEC.split(":")[1], 10); |
182 |
| - |
183 |
| - const erasureStripeSet = maxParityNumber * 2; // ESS is calculated by multiplying maximum parity by two. |
184 |
| - |
185 |
| - const storageFactors: IStorageFactors[] = parityValidValues.map( |
186 |
| - (currentParity) => { |
187 |
| - const parityNumber = parseInt(currentParity.split(":")[1], 10); |
188 |
| - const storageFactor = |
189 |
| - erasureStripeSet / (erasureStripeSet - parityNumber); |
190 |
| - |
191 |
| - const maxCapacity = Math.floor(totalStorage / storageFactor); |
192 |
| - const maxTolerations = |
193 |
| - totalDisks - Math.floor(totalDisks / storageFactor); |
194 |
| - return { |
195 |
| - erasureCode: currentParity, |
196 |
| - storageFactor, |
197 |
| - maxCapacity: maxCapacity.toString(10), |
198 |
| - maxFailureTolerations: maxTolerations, |
199 |
| - }; |
200 |
| - }, |
201 |
| - ); |
202 |
| - |
203 |
| - let defaultEC = maxEC; |
204 |
| - |
205 |
| - const fourVar = parityValidValues.find((element) => element === "EC:4"); |
206 |
| - |
207 |
| - if (fourVar) { |
208 |
| - defaultEC = "EC:4"; |
209 |
| - } |
210 |
| - |
211 |
| - return { |
212 |
| - error: 0, |
213 |
| - storageFactors, |
214 |
| - maxEC, |
215 |
| - rawCapacity: totalStorage.toString(10), |
216 |
| - erasureCodeSet: erasureStripeSet, |
217 |
| - defaultEC, |
218 |
| - }; |
219 |
| -}; |
220 |
| - |
221 | 53 | // 92400 seconds -> 1 day, 1 hour, 40 minutes.
|
222 | 54 | export const niceTimeFromSeconds = (seconds: number): string => {
|
223 | 55 | const days = Math.floor(seconds / (3600 * 24));
|
|
0 commit comments