Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await CN services before starting server #3937

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions creator-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,13 @@ const startAppForWorker = async () => {
}
})

const nodeMode = config.get('devMode') ? 'Dev Mode' : 'Production Mode'

await serviceRegistry.initServices()
const nodeMode = config.get('devMode') ? 'Dev Mode' : 'Production Mode'
logger.info(`Initialized services (Node running in ${nodeMode})`)
serviceRegistry.initServicesAsynchronously()
const appInfo = initializeApp(getPort(), serviceRegistry)
logger.info('Initialized app and server')

// Make the first worker wait for some services to be fully up before spinning up other workers
serviceRegistry.initServicesAsynchronously()
if (clusterUtils.isThisWorkerInit()) {
await serviceRegistry.initServicesThatRequireServer(appInfo.app)
} else {
serviceRegistry.initServicesThatRequireServer(appInfo.app)
}
await serviceRegistry.initServicesThatRequireServer(appInfo.app)

if (clusterUtils.isThisWorkerInit() && process.send) {
process.send({ cmd: 'initComplete' })
Expand Down
52 changes: 25 additions & 27 deletions creator-node/src/serviceRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ class ServiceRegistry {

this.synchronousServicesInitialized = true

// Cannot progress without recovering spID from node's record on L1 ServiceProviderFactory contract
// Retries indefinitely
await this._recoverNodeL1Identity()

// Init StateMachineManager
this.stateMachineManager = new StateMachineManager()
const {
monitorStateQueue,
findSyncRequestsQueue,
findReplicaSetUpdatesQueue,
cNodeEndpointToSpIdMapQueue,
manualSyncQueue,
recurringSyncQueue,
updateReplicaSetQueue,
recoverOrphanedDataQueue
} = await this.stateMachineManager.init(this.libs, this.prometheusRegistry)
this.monitorStateQueue = monitorStateQueue
this.findSyncRequestsQueue = findSyncRequestsQueue
this.findReplicaSetUpdatesQueue = findReplicaSetUpdatesQueue
this.cNodeEndpointToSpIdMapQueue = cNodeEndpointToSpIdMapQueue
this.manualSyncQueue = manualSyncQueue
this.recurringSyncQueue = recurringSyncQueue
this.updateReplicaSetQueue = updateReplicaSetQueue
this.recoverOrphanedDataQueue = recoverOrphanedDataQueue

logInfoWithDuration(
{ logger: genericLogger, startTime: start },
'ServiceRegistry || Initialized synchronous services'
Expand Down Expand Up @@ -287,8 +312,6 @@ class ServiceRegistry {
/**
* Some services require the node server to be running in order to initialize. Run those here.
* Specifically:
* - recover node L1 identity (requires node health check from server to return success)
* - initialize SnapbackSM service (requires node L1 identity)
* - construct SyncQueue (requires node L1 identity)
* - register node on L2 URSM contract (requires node L1 identity)
* - construct & init SkippedCIDsRetryQueue (requires SyncQueue)
Expand All @@ -297,31 +320,6 @@ class ServiceRegistry {
async initServicesThatRequireServer(app) {
const start = getStartTime()

// Cannot progress without recovering spID from node's record on L1 ServiceProviderFactory contract
// Retries indefinitely
await this._recoverNodeL1Identity()

// Init StateMachineManager
this.stateMachineManager = new StateMachineManager()
const {
monitorStateQueue,
findSyncRequestsQueue,
findReplicaSetUpdatesQueue,
cNodeEndpointToSpIdMapQueue,
manualSyncQueue,
recurringSyncQueue,
updateReplicaSetQueue,
recoverOrphanedDataQueue
} = await this.stateMachineManager.init(this.libs, this.prometheusRegistry)
this.monitorStateQueue = monitorStateQueue
this.findSyncRequestsQueue = findSyncRequestsQueue
this.findReplicaSetUpdatesQueue = findReplicaSetUpdatesQueue
this.cNodeEndpointToSpIdMapQueue = cNodeEndpointToSpIdMapQueue
this.manualSyncQueue = manualSyncQueue
this.recurringSyncQueue = recurringSyncQueue
this.updateReplicaSetQueue = updateReplicaSetQueue
this.recoverOrphanedDataQueue = recoverOrphanedDataQueue

// SyncQueue construction (requires L1 identity)
// Note - passes in reference to instance of self (serviceRegistry), a very sub-optimal workaround
this.syncQueue = new SyncQueue(config, this.redis, this)
Expand Down