Merge pull request #12774 from overleaf/ds-em-mongo-secondary-db-fix

Bug fix - Mongo DB secondary preference

GitOrigin-RevId: d9adc0a7e1ee5085b34c5c1ddfdc715967607fc3
This commit is contained in:
Jessica Lawshe 2023-04-27 08:56:31 -05:00 committed by Copybot
parent afb810c2a1
commit 0de648eecd
5 changed files with 18 additions and 8 deletions

View file

@ -18,6 +18,7 @@ const ProjectGetter = require('../Project/ProjectGetter')
const ProjectUpdateHandler = require('../Project/ProjectUpdateHandler')
const { Project } = require('../../models/Project')
const { ObjectId } = require('mongodb')
const { READ_PREFERENCE_SECONDARY } = require('../../infrastructure/mongodb')
const MILISECONDS_IN_DAY = 86400000
module.exports = InactiveProjectManager = {
@ -71,7 +72,7 @@ module.exports = InactiveProjectManager = {
.select('_id')
.sort({ _id: 1 })
.limit(limit)
.read('secondary')
.read(READ_PREFERENCE_SECONDARY)
.exec(function (err, projects) {
if (err != null) {
logger.err({ err }, 'could not get projects for deactivating')

View file

@ -20,6 +20,7 @@ const TpdsUpdateSender = require('../ThirdPartyDataStore/TpdsUpdateSender')
const ChatApiHandler = require('../Chat/ChatApiHandler')
const moment = require('moment')
const { promiseMapWithLimit } = require('../../util/promises')
const { READ_PREFERENCE_SECONDARY } = require('../../infrastructure/mongodb')
const EXPIRE_PROJECTS_AFTER_DAYS = 90
const PROJECT_EXPIRATION_BATCH_SIZE = 10000
@ -94,7 +95,7 @@ async function expireDeletedProjectsAfterDuration() {
{ 'deleterData.deletedProjectId': 1 }
)
.limit(PROJECT_EXPIRATION_BATCH_SIZE)
.read('secondary')
.read(READ_PREFERENCE_SECONDARY)
const projectIds = _.shuffle(
deletedProjects.map(
deletedProject => deletedProject.deleterData.deletedProjectId

View file

@ -12,10 +12,10 @@ if (
)
}
const READ_PREFERENCE_PRIMARY = ReadPreference.primary
const READ_PREFERENCE_PRIMARY = ReadPreference.primary.mode
const READ_PREFERENCE_SECONDARY = Settings.mongo.hasSecondaries
? ReadPreference.secondary
: ReadPreference.secondaryPreferred
? ReadPreference.secondary.mode
: ReadPreference.secondaryPreferred.mode
let setupDbPromise
async function waitForDb() {

View file

@ -20,7 +20,7 @@ const modulePath = path.join(
'../../../../app/src/Features/InactiveData/InactiveProjectManager'
)
const { expect } = require('chai')
const { ObjectId } = require('mongodb')
const { ObjectId, ReadPreference } = require('mongodb')
describe('InactiveProjectManager', function () {
beforeEach(function () {
@ -42,6 +42,10 @@ describe('InactiveProjectManager', function () {
'../Project/ProjectUpdateHandler': this.ProjectUpdateHandler,
'../Project/ProjectGetter': this.ProjectGetter,
'../../models/Project': {},
'../../infrastructure/mongodb': {
ObjectId,
READ_PREFERENCE_SECONDARY: ReadPreference.secondaryPreferred.mode,
},
},
})
return (this.project_id = '1234')

View file

@ -6,7 +6,7 @@ const tk = require('timekeeper')
const moment = require('moment')
const { Project } = require('../helpers/models/Project')
const { DeletedProject } = require('../helpers/models/DeletedProject')
const { ObjectId } = require('mongodb')
const { ObjectId, ReadPreference } = require('mongodb')
const Errors = require('../../../../app/src/Features/Errors/Errors')
describe('ProjectDeleter', function () {
@ -160,7 +160,11 @@ describe('ProjectDeleter', function () {
'../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
'../Docstore/DocstoreManager': this.DocstoreManager,
'./ProjectDetailsHandler': this.ProjectDetailsHandler,
'../../infrastructure/mongodb': { db: this.db, ObjectId },
'../../infrastructure/mongodb': {
db: this.db,
ObjectId,
READ_PREFERENCE_SECONDARY: ReadPreference.secondaryPreferred.mode,
},
'../History/HistoryManager': this.HistoryManager,
'../../models/ProjectAuditLogEntry': {
ProjectAuditLogEntry: this.ProjectAuditLogEntry,