Skip to content

Commit

Permalink
Add logs to orphaned data recovery job (#3774)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoilie authored Aug 26, 2022
1 parent aad5c9f commit 179e41d
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export default async function ({
}: DecoratedJobParams<RecoverOrphanedDataJobParams>): Promise<
DecoratedJobReturnValue<RecoverOrphanedDataJobReturnValue>
> {
const numWalletsOnNode = await _saveWalletsOnThisNodeToRedis()
const numWalletsOnNode = await _saveWalletsOnThisNodeToRedis(logger)
const numWalletsWithNodeInReplicaSet =
await _saveWalletsWithThisNodeInReplicaToRedis(
discoveryNodeEndpoint,
logger
)
const numWalletsWithOrphanedData = await _saveWalletsWithOrphanedDataToRedis()
const numWalletsWithOrphanedData = await _saveWalletsWithOrphanedDataToRedis(
logger
)
const requestsIssued = await _batchIssueReqsToRecoverOrphanedData(
numWalletsWithOrphanedData,
discoveryNodeEndpoint,
Expand Down Expand Up @@ -88,7 +90,7 @@ export default async function ({
/**
* Queries this node's db to find all users who have data on it and adds them to a redis set.
*/
const _saveWalletsOnThisNodeToRedis = async () => {
const _saveWalletsOnThisNodeToRedis = async (logger: Logger) => {
await redisClient.del(WALLETS_ON_NODE_KEY)

type WalletSqlRow = {
Expand Down Expand Up @@ -127,6 +129,7 @@ const _saveWalletsOnThisNodeToRedis = async () => {
}

const numWalletsOnNode = await redisClient.scard(WALLETS_ON_NODE_KEY)
logger.info(`Found ${numWalletsOnNode} wallets with data on this node`)
return numWalletsOnNode
}

Expand Down Expand Up @@ -184,6 +187,9 @@ const _saveWalletsWithThisNodeInReplicaToRedis = async (
const numWalletsWithNodeInReplicaSet = await redisClient.scard(
WALLETS_WITH_NODE_IN_REPLICA_SET_KEY
)
logger.info(
`Found ${numWalletsWithNodeInReplicaSet} wallets with this node in their replica set`
)
return numWalletsWithNodeInReplicaSet
}

Expand All @@ -192,12 +198,15 @@ const _saveWalletsWithThisNodeInReplicaToRedis = async (
* (Set of orphaned wallets) = (set of wallets on this node) - (set of wallets with this node in their replica set)
* @returns number of wallets that have data orphaned on this node
*/
const _saveWalletsWithOrphanedDataToRedis = async () => {
const _saveWalletsWithOrphanedDataToRedis = async (logger: Logger) => {
const numWalletsOrphaned: number = await redisClient.sdiffstore(
WALLETS_ORPHANED_KEY,
WALLETS_ON_NODE_KEY,
WALLETS_WITH_NODE_IN_REPLICA_SET_KEY
)
logger.info(
`Found ${numWalletsOrphaned} wallets with data orphaned on this node`
)
return numWalletsOrphaned
}

Expand Down Expand Up @@ -256,6 +265,9 @@ const _batchIssueReqsToRecoverOrphanedData = async (
}
}

logger.info(
`Issued /merge_primary_and_secondary requests for ${i}/${numWalletsWithOrphanedData} wallets`
)
// Delay processing the next batch to avoid spamming requests
await Utils.timeout(ORPHAN_DATA_DELAY_BETWEEN_BATCHES_MS, false)
}
Expand Down

0 comments on commit 179e41d

Please sign in to comment.