Skip to content

Commit

Permalink
kv: Attempt to notify watchers when disconnected
Browse files Browse the repository at this point in the history
Use the local cache to notify anything locally if possible.
This allows us to use a watch early in the process.

Signed-off-by: Joshua Hesketh <jhesketh@suse.com>
  • Loading branch information
jhesketh committed Dec 10, 2021
1 parent 1c0c3e8 commit a138cd6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/gravel/controllers/kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def _config_notify(
logger.debug(
f"Got notify on config object {notify_id} {notifier_id} {watch_id} {key}"
)
self._notify_watches(key)

def _notify_watches(self, key: str):
if key not in self._watches:
return

Expand Down Expand Up @@ -322,6 +325,10 @@ async def put(self, key: str, value: str) -> None:
except Exception as e:
# e.g. RADOS state (You cannot perform that operation on a Rados object in state configuring.)
logger.exception(str(e))
else:
# When we're not connected to ioctx we should try to notify any
# watchers that we may be aware of via the cache
self._notify_watches(key)

logger.debug(f"Writing {key}: {value} to local cache")
self._db[key] = bvalue
Expand Down

0 comments on commit a138cd6

Please sign in to comment.