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

CON-250 - stateMachine updates to consume primarySyncFromSecondary (Divergent state recovery #3) #3426

Merged
merged 39 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5c4c6d7
global user write lock
SidSethi Jul 10, 2022
99f28bb
Merge branch 'master' into ss-global-user-writelock
SidSethi Jul 11, 2022
1694d6b
Done
SidSethi Jul 11, 2022
5d3108c
nit
SidSethi Jul 11, 2022
cc4fad3
primarySyncFromSecondary
SidSethi Jul 12, 2022
b734f85
delete nodesync file
SidSethi Jul 12, 2022
816d307
lint
SidSethi Jul 12, 2022
80adb05
Merge branch 'ss-global-user-writelock' into ss-dsr-primarySyncFromSe…
SidSethi Jul 12, 2022
5a4e74f
Comments
SidSethi Jul 12, 2022
966028c
whoops
SidSethi Jul 12, 2022
567eb0d
first
SidSethi Jul 12, 2022
f80ec78
More
SidSethi Jul 12, 2022
bcd871b
more
SidSethi Jul 12, 2022
9a605a1
broken
SidSethi Jul 12, 2022
0293a68
finally
SidSethi Jul 12, 2022
1df5b50
Add mergePrimaryAndSecondaryEnabled envvar
SidSethi Jul 12, 2022
2e55a9d
pls work
SidSethi Jul 12, 2022
b075877
fix
SidSethi Jul 12, 2022
2e005db
Remove write lock middleware
SidSethi Jul 12, 2022
fd3a213
Merge branch 'master' into ss-global-user-writelock
SidSethi Jul 12, 2022
5a61327
Remove redisKey + UserWrite
SidSethi Jul 12, 2022
bc872dc
Merge branch 'ss-global-user-writelock' into ss-dsr-primarySyncFromSe…
SidSethi Jul 12, 2022
4aa353a
Merge branch 'master' into ss-global-user-writelock
SidSethi Jul 12, 2022
0393d46
Merge branch 'ss-global-user-writelock' into ss-dsr-primarySyncFromSe…
SidSethi Jul 12, 2022
3add5a6
Merge branch 'master' into ss-dsr-primarySyncFromSecondary-v2
SidSethi Jul 12, 2022
3de1182
More
SidSethi Jul 13, 2022
c5ad4a1
Merge branch 'master' into ss-dsr-primarySyncFromSecondary-v2
SidSethi Jul 13, 2022
e3b77d6
Merge branch 'master' into ss-dsr-primarySyncFromSecondary-v2
SidSethi Jul 13, 2022
d2f0fb7
Merge branch 'master' into ss-dsr-primarySyncFromSecondary-v2
SidSethi Jul 13, 2022
2ad6aeb
Test fixes
SidSethi Jul 13, 2022
3ae544d
Merge branch 'ss-dsr-primarySyncFromSecondary-v2' into ss-dsr-findsyn…
SidSethi Jul 13, 2022
b88aa63
Merge branch 'master' into ss-dsr-findsyncrequest
SidSethi Jul 14, 2022
0574109
broken
SidSethi Jul 14, 2022
c0c4130
y
SidSethi Jul 14, 2022
b7cfe73
it worksgit status
SidSethi Jul 14, 2022
01b7295
Fix tests
SidSethi Jul 14, 2022
bf9c66d
Revert "Fix tests"
SidSethi Jul 14, 2022
55bbff2
Actually fix tests
SidSethi Jul 14, 2022
be39777
Merge branch 'master' into ss-dsr-findsyncrequest
SidSethi Jul 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions creator-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
} = require('./URSMRegistrationComponentService')
const { ensureStorageMiddleware } = require('../../middlewares')
const { enqueueSync } = require('./syncQueueComponentService')
const processSync = require('../../services/sync/processSync')
const secondarySyncFromPrimary = require('../../services/sync/secondarySyncFromPrimary')

const router = express.Router()

Expand Down Expand Up @@ -90,7 +90,7 @@ const syncRouteController = async (req, res) => {
* Else, debounce + add sync to queue
*/
if (immediate) {
const errorObj = await processSync(
const errorObj = await secondarySyncFromPrimary(
serviceRegistry,
walletPublicKeys,
creatorNodeEndpoint,
Expand Down
6 changes: 4 additions & 2 deletions creator-node/src/dbManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ class DBManager {
queryObj.clock = selectCNodeUserClockSubqueryLiteral

// Create new Data table entry with queryObj using new CNodeUser.clock
const file = await sequelizeTableInstance.create(queryObj, { transaction })
const newDataRecord = await sequelizeTableInstance.create(queryObj, {
transaction
})

return file.dataValues
return newDataRecord.dataValues
}

/**
Expand Down
50 changes: 41 additions & 9 deletions creator-node/src/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,55 @@ async function authMiddleware(req, res, next) {
next()
}

/** Ensure resource write access */
async function syncLockMiddleware(req, res, next) {
/**
* Acquire wallet write lock; return 423 error if already held
*/
async function acquireWalletWriteLock(req, res, next) {
const redisClient = req.app.get('redisClient')

if (req.session && req.session.wallet) {
const redisClient = req.app.get('redisClient')
const redisKey = redisClient.getNodeSyncRedisKey(req.session.wallet)
const lockHeld = await redisClient.lock.getLock(redisKey)
if (lockHeld) {
const wallet = req.session.wallet

try {
await redisClient.WalletWriteLock.acquire(
wallet,
redisClient.WalletWriteLock.VALID_ACQUIRERS.UserWrite
)
} catch (e) {
return sendResponse(
req,
res,
errorResponse(
423,
`Cannot change state of wallet ${req.session.wallet}. Node sync currently in progress.`
`Cannot change state of wallet ${wallet}. Another write in progress.`
)
)
}
}
req.logger.info(`syncLockMiddleware succeeded`)

req.logger.debug(`acquireWalletWriteLock succeeded`)
next()
}

/**
* Release wallet write lock
*/
async function releaseWalletWriteLock(req, res, next) {
const redisClient = req.app.get('redisClient')

if (req.session && req.session.wallet) {
const wallet = req.session.wallet

try {
await redisClient.WalletWriteLock.release(wallet)
} catch (e) {
req.logger.warn(
`releaseWalletWriteLock Failure for wallet ${wallet} - ${e.message}`
)
}
}

req.logger.debug(`acquireWalletWriteLock succeeded`)
next()
}

Expand Down Expand Up @@ -852,7 +883,8 @@ module.exports = {
ensureStorageMiddleware,
ensureValidSPMiddleware,
issueAndWaitForSecondarySyncRequests,
syncLockMiddleware,
acquireWalletWriteLock,
releaseWalletWriteLock,
getOwnEndpoint,
getCreatorNodeEndpoints
}
Loading