Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
CON-328 Add manual mergePrimaryAndSecondary route for testing#3685
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5a25cac1eb888668a925a88cb36af650db3ec74f93b14bb75ca786427de7d22dc626dbab5454af1390d723372907b256bdb159a33ba2d1bd0e4d65ae209883b7a089ce5637ab82ee9c38cb28163f59d509c77dacdd9ce07f68f9e5548c5fdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -15,3 +15,4 @@ coverage/ | ||
| .nyc_output/ | ||
| compose/env/tmp*/ | ||
| file_storage/ | ||
| build/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,10 @@ const { | ||
| respondToURSMRequestForSignature | ||
| } = require('./URSMRegistrationComponentService') | ||
| const { ensureStorageMiddleware } = require('../../middlewares') | ||
| const { | ||
| SyncType, | ||
| SYNC_MODES | ||
| } = require('../../services/stateMachineManager/stateMachineConstants') | ||
| const { | ||
| enqueueSync, | ||
| processManualImmediateSync | ||
| @@ -159,6 +163,50 @@ const syncRouteController = async (req, res) => { | ||
| return successResponse() | ||
| } | ||
| /** | ||
| * Adds a job to manualSyncQueue to issue a sync to secondary with syncMode MergePrimaryAndSecondary | ||
| * @notice This will only work if called on a primary for a user | ||
| */ | ||
| const mergePrimaryAndSecondaryController = async (req, res) => { | ||
SidSethi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const serviceRegistry = req.app.get('serviceRegistry') | ||
| const manualSyncQueue = serviceRegistry.manualSyncQueue | ||
| const config = serviceRegistry.nodeConfig | ||
| const selfEndpoint = config.get('creatorNodeEndpoint') | ||
| const wallet = req.query.wallet | ||
| const endpoint = req.query.endpoint | ||
| if (!wallet || !endpoint) { | ||
| return errorResponseBadRequest(`Must provide wallet and endpoint params`) | ||
| } | ||
| const syncType = SyncType.Manual | ||
| const syncMode = SYNC_MODES.MergePrimaryAndSecondary | ||
| const immediate = true | ||
| const syncRequestParameters = { | ||
| baseURL: endpoint, | ||
| url: '/sync', | ||
| method: 'post', | ||
| data: { | ||
| wallet: [wallet], | ||
| creator_node_endpoint: selfEndpoint, | ||
| sync_type: syncType, | ||
| immediate, | ||
| from_manual_route: true | ||
| } | ||
| } | ||
| await manualSyncQueue.add({ | ||
| syncType, | ||
| syncMode, | ||
| syncRequestParameters | ||
| }) | ||
| return successResponse() | ||
| } | ||
| // Routes | ||
| router.get( | ||
| @@ -170,5 +218,9 @@ router.post( | ||
| ensureStorageMiddleware, | ||
| handleResponse(syncRouteController) | ||
| ) | ||
| router.post( | ||
| '/merge_primary_and_secondary', | ||
| handleResponse(mergePrimaryAndSecondaryController) | ||
| ) | ||
| module.exports = router | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,7 +30,7 @@ module.exports = async function primarySyncFromSecondary({ | ||
| }) { | ||
| const logPrefix = `[primarySyncFromSecondary][Wallet: ${wallet}][Secondary: ${secondary}]` | ||
| const logger = genericLogger.child(logContext) | ||
| logger.info(`[primarySyncFromSecondary] [Wallet: ${wallet}] Beginning...`) | ||
| logger.info(`${logPrefix} Beginning...`) | ||
| const start = Date.now() | ||
| // This is used only for logging record endpoint of requesting node | ||
| @@ -53,13 +53,21 @@ module.exports = async function primarySyncFromSecondary({ | ||
| ) | ||
| // TODO should be able to pass this through from StateMachine / caller | ||
| const userReplicaSet = await getUserReplicaSet({ | ||
| let userReplicaSet = await getUserReplicaSet({ | ||
| wallet, | ||
| selfEndpoint, | ||
| logger, | ||
| libs | ||
| }) | ||
| // Error if this node is not primary for user | ||
| if (userReplicaSet[0] !== selfEndpoint) { | ||
| throw new Error(`Failure - this node is not primary for user`) | ||
| } | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😬 this should have been locked down earlier Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check out my comment below and lmk what you think. we should fetch this data from chain vs discovery | ||
| // filter out current node from user's replica set | ||
| userReplicaSet = userReplicaSet.filter((url) => url !== selfEndpoint) | ||
| // Keep importing data from secondary until full clock range has been retrieved | ||
| let completed = false | ||
| let exportClockRangeMin = 0 | ||
| @@ -448,7 +456,7 @@ async function filterOutAlreadyPresentDBEntries({ | ||
| return filteredEntries | ||
| } | ||
| async function getUserReplicaSet({ wallet, selfEndpoint, libs, logger }) { | ||
| async function getUserReplicaSet({ wallet, libs, logger }) { | ||
| try { | ||
| let userReplicaSet = await getCreatorNodeEndpoints({ | ||
SidSethi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| libs, | ||
| @@ -459,9 +467,6 @@ async function getUserReplicaSet({ wallet, selfEndpoint, libs, logger }) { | ||
| myCnodeEndpoint: null | ||
| }) | ||
| // filter out current node from user's replica set | ||
| userReplicaSet = userReplicaSet.filter((url) => url !== selfEndpoint) | ||
| // Spread + set uniq's the array | ||
| userReplicaSet = [...new Set(userReplicaSet)] | ||
Uh oh!
There was an error while loading. Please reload this page.