Skip to content

Commit a19c7cd

Browse files
casteryhfacebook-github-bot
authored andcommitted
fix controller endpoint (#74)
Summary: Monarch is enforcing the following check. This diff is a fix. ValueError: <class 'torchstore.controller.Controller'> mixes both async and sync endpoints.Synchronous endpoints cannot be mixed with async endpoints because they can cause the asyncio loop to deadlock if they wait.sync: ['get_controller_strategy', 'keys', 'locate_volumes', 'notify_delete', 'notify_put'] async: ['init', 'teardown'] Reviewed By: amirafzali, LucasLLC Differential Revision: D86155590
1 parent 9dd276c commit a19c7cd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

torchstore/controller.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ async def init(
120120
self.is_initialized = True
121121

122122
@endpoint
123-
def get_controller_strategy(self) -> TorchStoreStrategy:
123+
async def get_controller_strategy(self) -> TorchStoreStrategy:
124124
self.assert_initialized()
125125
assert self.strategy is not None, "Strategy is not set"
126126
return self.strategy
127127

128128
@endpoint
129-
def locate_volumes(
129+
async def locate_volumes(
130130
self,
131131
key: str,
132132
) -> Dict[str, StorageInfo]:
@@ -178,7 +178,9 @@ def locate_volumes(
178178
return volume_map
179179

180180
@endpoint
181-
def notify_put(self, key: str, request: Request, storage_volume_id: str) -> None:
181+
async def notify_put(
182+
self, key: str, request: Request, storage_volume_id: str
183+
) -> None:
182184
"""Notify the controller that data has been stored in a storage volume.
183185
184186
This should called after a successful put operation to
@@ -220,13 +222,13 @@ async def teardown(self) -> None:
220222
self.num_storage_volumes = None
221223

222224
@endpoint
223-
def keys(self, prefix=None) -> List[str]:
225+
async def keys(self, prefix=None) -> List[str]:
224226
if prefix is None:
225227
return list(self.keys_to_storage_volumes.keys())
226228
return self.keys_to_storage_volumes.keys().filter_by_prefix(prefix)
227229

228230
@endpoint
229-
def notify_delete(self, key: str, storage_volume_id: str) -> None:
231+
async def notify_delete(self, key: str, storage_volume_id: str) -> None:
230232
"""
231233
Notify the controller that deletion of data is initiated in a storage volume.
232234

0 commit comments

Comments
 (0)