22import hashlib
33import json
44import os
5+ from typing import Union
56from dataclasses import dataclass
67from typing import Iterable , List , Optional , Tuple , Union
78
@@ -421,7 +422,7 @@ class LasyerMultiBlockReqMeta:
421422class MooncakeStoreConfig :
422423 local_hostname : str
423424 metadata_server : str
424- global_segment_size : int | str
425+ global_segment_size : Union [ int , str ]
425426 local_buffer_size : int
426427 protocol : str
427428 device_name : str
@@ -438,9 +439,7 @@ def from_file(file_path: str) -> "MooncakeStoreConfig":
438439 global_segment_size = _parse_global_segment_size (
439440 config .get ("global_segment_size" , DEFAULT_GLOBAL_SEGMENT_SIZE )
440441 ),
441- local_buffer_size = _parse_global_segment_size (
442- config .get ("local_buffer_size" , DEFAULT_LOCAL_BUFFER_SIZE )
443- ),
442+ local_buffer_size = config .get ("local_buffer_size" , DEFAULT_LOCAL_BUFFER_SIZE ),
444443 protocol = config .get ("protocol" , "tcp" ),
445444 device_name = config .get ("device_name" , "" ),
446445 master_server_address = config .get ("master_server_address" ),
@@ -476,13 +475,15 @@ def _parse_global_segment_size(value) -> int:
476475 try :
477476 return int (value )
478477 except (TypeError , ValueError ) as e :
479- raise TypeError (f"Unsupported type for global_segment_size: { type (value )} " ) from e
478+ raise TypeError (
479+ f"Unsupported type for global_segment_size: { type (value )} "
480+ ) from e
480481 # Clean input string
481482 cleaned_input = value .strip ().lower ()
482483 if not cleaned_input :
483484 raise ValueError ("global segment size cannot be empty." )
484485
485- UNIT_MULTIPLIERS = {
486+ UNIT_MULTIPLIERS = {
486487 'gb' : 1024 ** 3 , # 1 GB = 1024^3 bytes
487488 'mb' : 1024 ** 2 , # 1 MB = 1024^2 bytes
488489 'kb' : 1024 , # 1 KB = 1024 bytes
@@ -493,13 +494,16 @@ def _parse_global_segment_size(value) -> int:
493494 if cleaned_input .endswith (unit ):
494495 number_part = cleaned_input [:- len (unit )].strip ()
495496 if not number_part :
496- raise ValueError (f"Missing numeric value before unit '{ unit } ' in: '{ value } '" )
497+ raise ValueError (
498+ f"Missing numeric value before unit '{ unit } ' in: '{ value } '"
499+ )
497500 return _convert_to_bytes (number_part , multiplier , value )
498501 # Handle unit-less input (bytes)
499502 return _convert_to_bytes (cleaned_input , 1 , value )
500503
501504
502- def _convert_to_bytes (number_str : str , multiplier : int , original_input : str ) -> int :
505+ def _convert_to_bytes (number_str : str , multiplier : int ,
506+ original_input : str ) -> int :
503507 """
504508 Convert numeric string to byte count
505509
@@ -517,7 +521,9 @@ def _convert_to_bytes(number_str: str, multiplier: int, original_input: str) ->
517521 try :
518522 numeric_value = float (number_str )
519523 except ValueError :
520- raise ValueError (f"Invalid numeric value '{ number_str } ' in: '{ original_input } '" )
524+ raise ValueError (
525+ f"Invalid numeric value '{ number_str } ' in: '{ original_input } '"
526+ )
521527 # Calculate byte count
522528 try :
523529 byte_count = int (numeric_value * multiplier )
0 commit comments