[#1632] node: Subscribe on the successful container creations/removals
There is a need to sync container-related caching mechanism with the actual Sidechain changes. To do this, node should be able to listen incoming notifications about container ops. Define `PutSuccess` / `DeleteSuccess` notification event's parsers. Subscribe to these events in node app. As initial implementation node will log event receipts. Later handling is going to be practically complicated. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
d8a00c365a
commit
7c1babb7d6
5 changed files with 219 additions and 0 deletions
|
@ -63,6 +63,18 @@ func initContainerService(c *cfg) {
|
|||
neoClient: wrap,
|
||||
}
|
||||
|
||||
subscribeToContainerCreation(c, func(e event.Event) {
|
||||
c.log.Debug("container creation event's receipt",
|
||||
zap.Stringer("id", e.(containerEvent.PutSuccess).ID),
|
||||
)
|
||||
})
|
||||
|
||||
subscribeToContainerRemoval(c, func(e event.Event) {
|
||||
c.log.Debug("container removal event's receipt",
|
||||
zap.Stringer("id", e.(containerEvent.DeleteSuccess).ID),
|
||||
)
|
||||
})
|
||||
|
||||
if c.cfgMorph.disableCache {
|
||||
c.cfgObject.eaclSource = eACLFetcher
|
||||
cnrRdr.eacl = eACLFetcher
|
||||
|
@ -195,6 +207,34 @@ func addContainerAsyncNotificationHandler(c *cfg, sTyp string, h event.Handler)
|
|||
)
|
||||
}
|
||||
|
||||
// stores already registered parsers of the notification events thrown by Container contract.
|
||||
// MUST NOT be used concurrently.
|
||||
var mRegisteredParsersContainer = make(map[string]struct{})
|
||||
|
||||
// registers event parser by name once. MUST NOT be called concurrently.
|
||||
func registerEventParserOnceContainer(c *cfg, name string, p event.NotificationParser) {
|
||||
if _, ok := mRegisteredParsersContainer[name]; !ok {
|
||||
setContainerNotificationParser(c, name, p)
|
||||
mRegisteredParsersContainer[name] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// subscribes to successful container creation. Provided handler is called asynchronously
|
||||
// on corresponding routine pool. MUST NOT be called concurrently with itself and other
|
||||
// similar functions.
|
||||
func subscribeToContainerCreation(c *cfg, h event.Handler) {
|
||||
const eventNameContainerCreated = "PutSuccess"
|
||||
registerEventParserOnceContainer(c, eventNameContainerCreated, containerEvent.ParsePutSuccess)
|
||||
addContainerAsyncNotificationHandler(c, eventNameContainerCreated, h)
|
||||
}
|
||||
|
||||
// like subscribeToContainerCreation but for removal.
|
||||
func subscribeToContainerRemoval(c *cfg, h event.Handler) {
|
||||
const eventNameContainerRemoved = "DeleteSuccess"
|
||||
registerEventParserOnceContainer(c, eventNameContainerRemoved, containerEvent.ParseDeleteSuccess)
|
||||
addContainerAsyncNotificationHandler(c, eventNameContainerRemoved, h)
|
||||
}
|
||||
|
||||
func setContainerNotificationParser(c *cfg, sTyp string, p event.NotificationParser) {
|
||||
typ := event.TypeFromString(sTyp)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue