Skip to content

Commit 8e873de

Browse files
committed
[Feature] [Fix] Load Mooncake config from dict, when lack params, load from env config file.
1 parent 4e8af97 commit 8e873de

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

docs/source/getting-started/example/mooncake_conn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ To use the Mooncake connector, you need to configure the `connector_config` dict
5353
The metadata server of the mooncake transfer engine.
5454
- `master_server_address`:
5555
The IP address and the port of the master daemon process of MooncakeStore.
56-
- `protocl` *(optional)*:
56+
- `protocol` *(optional)*:
5757
If not provided, it defaults to **tcp**.
5858
- `device_name` *(optional)*:
5959
The device to be used for data transmission, it is required when “protocol” is set to “rdma”. If multiple NIC devices are used, they can be separated by commas such as “erdma_0,erdma_1”. Please note that there are no spaces between them.

unifiedcache/ucm_connector/ucm_mooncake.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from unifiedcache.ucm_connector import Task, UcmKVStoreBase
1515

1616
TIMEOUT_S_THR: int = 60 * 60
17-
DEFAULT_GLOBAL_SEGMENT_SIZE: int = 1 * 1024 * 1024 * 1024 # 3.125 GiB
18-
DEFAULT_LOCAL_BUFFER_SIZE: int = 1 * 1024 * 1024 * 1024 # 1.0 GiB
17+
DEFAULT_GLOBAL_SEGMENT_SIZE: int = 3355443200 # 3.125 GiB
18+
DEFAULT_LOCAL_BUFFER_SIZE: int = 1073741824 # 1.0 GiB
1919

2020
logger = init_logger(__name__)
2121

@@ -111,11 +111,10 @@ def __init__(self, config: Dict = {}):
111111

112112
try:
113113
self.store = MooncakeDistributedStore()
114-
if config != {}:
115-
mooncake_config = MooncakeStoreConfig.load_from_dict(config)
116-
else:
117-
mooncake_config = MooncakeStoreConfig.load_from_env()
118-
logger.info("Mooncake Configuration loaded successfully.")
114+
115+
mooncake_config = MooncakeStoreConfig.load_from_dict(config)
116+
logger.info("Mooncake Configuration loaded from dict successfully.")
117+
119118
self.store.setup(
120119
mooncake_config.local_hostname,
121120
mooncake_config.metadata_server,
@@ -129,6 +128,34 @@ def __init__(self, config: Dict = {}):
129128
except ValueError as e:
130129
logger.error("Configuration loading failed: %s", e)
131130
raise
131+
except TypeError:
132+
logger.warning(
133+
"Lack of configuration, loading Mooncake configuration from environment variables instead."
134+
)
135+
try:
136+
mooncake_config = MooncakeStoreConfig.load_from_env()
137+
logger.info("Mooncake Configuration loaded from env successfully.")
138+
self.store.setup(
139+
mooncake_config.local_hostname,
140+
mooncake_config.metadata_server,
141+
mooncake_config.global_segment_size,
142+
mooncake_config.local_buffer_size,
143+
mooncake_config.protocol,
144+
mooncake_config.device_name,
145+
mooncake_config.master_server_address,
146+
)
147+
except ValueError as e:
148+
logger.error(
149+
"Configuration loading failed: %s \n Please check the dict params or edit the config file and set path.",
150+
e,
151+
)
152+
raise
153+
except Exception as exc:
154+
logger.error(
155+
"An error occurred while loading the configuration: %s", exc
156+
)
157+
raise
158+
132159
except Exception as exc:
133160
logger.error("An error occurred while loading the configuration: %s", exc)
134161
raise

0 commit comments

Comments
 (0)