Close the discovery store

This commit is contained in:
Arnaud 2025-12-24 17:09:20 +04:00
parent 60861d6af8
commit 831068e68e
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
2 changed files with 20 additions and 8 deletions

View File

@ -206,6 +206,7 @@ proc stop*(s: CodexServer) {.async.} =
@[
s.codexNode.switch.stop(),
s.codexNode.stop(),
s.codexNode.discovery.stop(),
s.repoStore.stop(),
s.maintenance.stop(),
]
@ -220,7 +221,8 @@ proc stop*(s: CodexServer) {.async.} =
raiseAssert "Failed to stop Storage node"
proc close*(s: CodexServer) {.async.} =
var futures = @[s.codexNode.close(), s.repoStore.close()]
var futures =
@[s.codexNode.close(), s.repoStore.close(), s.codexNode.discovery.close()]
let res = await noCancel allFinishedFailed[void](futures)
@ -282,12 +284,15 @@ proc new*(
msg: "Unable to create discovery directory for block store: " & discoveryDir
)
let providersPath = config.dataDir / CodexDhtProvidersNamespace
let discoveryStoreRes = LevelDbDatastore.new(providersPath)
if discoveryStoreRes.isErr:
error "Failed to initialize discovery datastore",
path = providersPath, err = discoveryStoreRes.error.msg
let
discoveryStore = Datastore(
LevelDbDatastore.new(config.dataDir / CodexDhtProvidersNamespace).expect(
"Should create discovery datastore!"
)
)
discoveryStore =
Datastore(discoveryStoreRes.expect("Should create discovery datastore!"))
discovery = Discovery.new(
switch.peerInfo.privateKey,

View File

@ -44,6 +44,7 @@ type Discovery* = ref object of RootObj
# address that the node can be connected on
dhtRecord*: ?SignedPeerRecord # record to advertice DHT connection information
isStarted: bool
store: Datastore
proc toNodeId*(cid: Cid): NodeId =
## Cid to discovery id
@ -218,6 +219,11 @@ proc stop*(d: Discovery) {.async: (raises: []).} =
except CatchableError as exc:
error "Error stopping discovery", exc = exc.msg
proc close*(d: Discovery) {.async: (raises: []).} =
let res = await noCancel d.store.close()
if res.isErr:
error "Error closing discovery store", error = res.error().msg
proc new*(
T: type Discovery,
key: PrivateKey,
@ -230,8 +236,9 @@ proc new*(
## Create a new Discovery node instance for the given key and datastore
##
var self =
Discovery(key: key, peerId: PeerId.init(key).expect("Should construct PeerId"))
var self = Discovery(
key: key, peerId: PeerId.init(key).expect("Should construct PeerId"), store: store
)
self.updateAnnounceRecord(announceAddrs)