diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts index cf7f5c59..8a63185c 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts @@ -12,8 +12,6 @@ import { AuthorizationDocument } from '../model/AuthorizationDocument'; export const DOCUMENT_COLLECTION_NAME = 'documents'; export const AUTHORIZATION_COLLECTION_NAME = 'authorizations'; - -// RND-644 export const CONCURRENCY_COLLECTION_NAME = 'concurrency'; let singletonClient: MongoClient | null = null; @@ -50,7 +48,7 @@ export async function getNewClient(): Promise { const concurrencyCollection: Collection = newClient .db(databaseName) .collection(CONCURRENCY_COLLECTION_NAME); - await concurrencyCollection.createIndex({ meadowlarkId: 1, documentUuid: 1 }, { unique: true }); // RND-644 + await concurrencyCollection.createIndex({ meadowlarkId: 1, documentUuid: 1 }, { unique: true }); return newClient; } catch (e) { @@ -98,7 +96,7 @@ export function getDocumentCollection(client: MongoClient): Collection { return client.db(Config.get('MEADOWLARK_DATABASE_NAME')).collection(AUTHORIZATION_COLLECTION_NAME); } -// RND-644 + export function getConcurrencyCollection(client: MongoClient): Collection { return client.db(Config.get('MEADOWLARK_DATABASE_NAME')).collection(CONCURRENCY_COLLECTION_NAME); } @@ -150,7 +148,7 @@ export const asUpsert = (session: ClientSession): ReplaceOptions => ({ upsert: t export const limitFive = (session: ClientSession): FindOptions => ({ limit: 5, session }); /** - * Alternative to writeLockReferencedDocuments function. RND-644 + * Alternative to writeLockReferencedDocuments function. * */ export async function insertMeadowlarkIdOnConcurrencyCollection( concurrencyCollection: Collection, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Delete.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Delete.ts index adb62286..bd29c199 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Delete.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Delete.ts @@ -83,7 +83,7 @@ async function checkForReferencesToDocument( export async function deleteDocumentByMeadowlarkIdTransaction( { documentUuid, validateNoReferencesToDocument, traceId }: DeleteRequest, mongoCollection: Collection, - concurrencyCollection: Collection, // RND-644 + concurrencyCollection: Collection, session: ClientSession, ): Promise { if (validateNoReferencesToDocument) { @@ -109,11 +109,11 @@ export async function deleteDocumentByMeadowlarkIdTransaction( }, ]; - await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); const { acknowledged, deletedCount } = await mongoCollection.deleteOne({ documentUuid }, { session }); - await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); if (!acknowledged) { const msg = diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts index 9a3fc7a4..f7d81553 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts @@ -154,7 +154,7 @@ async function updateAllowingIdentityChange( document: MeadowlarkDocument, updateRequest: UpdateRequest, mongoCollection: Collection, - concurrencyCollection: Collection, // RND-644 + concurrencyCollection: Collection, session: ClientSession, ): Promise { const { documentUuid, resourceInfo, traceId, security } = updateRequest; @@ -165,7 +165,7 @@ async function updateAllowingIdentityChange( })); concurrencyDocuments.push({ meadowlarkId: updateRequest.meadowlarkId, documentUuid: updateRequest.documentUuid }); - await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // Optimize happy path by trying a replacement update, which will succeed if there is no identity change const tryUpdateByReplacementResult: UpdateResult | null = await tryUpdateByReplacement( @@ -175,7 +175,7 @@ async function updateAllowingIdentityChange( session, ); - await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); if (tryUpdateByReplacementResult != null) { // Ensure referenced documents are not modified in other transactions @@ -251,7 +251,7 @@ async function updateDisallowingIdentityChange( document: MeadowlarkDocument, updateRequest: UpdateRequest, mongoCollection: Collection, - concurrencyCollection: Collection, // RND-644 + concurrencyCollection: Collection, session: ClientSession, ): Promise { // Perform the document update @@ -269,7 +269,7 @@ async function updateDisallowingIdentityChange( })); concurrencyDocuments.push({ meadowlarkId: updateRequest.meadowlarkId, documentUuid: updateRequest.documentUuid }); - await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); const tryUpdateByReplacementResult: UpdateResult | null = await tryUpdateByReplacement( document, @@ -278,7 +278,7 @@ async function updateDisallowingIdentityChange( session, ); - await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); if (tryUpdateByReplacementResult != null) return tryUpdateByReplacementResult; @@ -354,7 +354,7 @@ async function checkForInvalidReferences( async function updateDocumentByDocumentUuidTransaction( updateRequest: UpdateRequest, mongoCollection: Collection, - concurrencyCollection: Collection, // RND-644 + concurrencyCollection: Collection, session: ClientSession, ): Promise { const { meadowlarkId, documentUuid, resourceInfo, documentInfo, edfiDoc, validateDocumentReferencesExist, security } = @@ -381,7 +381,7 @@ async function updateDocumentByDocumentUuidTransaction( lastModifiedAt: documentInfo.requestTimestamp, }); if (resourceInfo.allowIdentityUpdates) { - return updateAllowingIdentityChange(document, updateRequest, mongoCollection, concurrencyCollection, session); // RND-644 + return updateAllowingIdentityChange(document, updateRequest, mongoCollection, concurrencyCollection, session); } return updateDisallowingIdentityChange(document, updateRequest, mongoCollection, concurrencyCollection, session); } @@ -398,7 +398,7 @@ export async function updateDocumentByDocumentUuid( Logger.info(`${moduleName}.updateDocumentByDocumentUuid ${documentUuid}`, traceId); const mongoCollection: Collection = getDocumentCollection(client); - const concurrencyCollection: Collection = getConcurrencyCollection(client); // RND-644 + const concurrencyCollection: Collection = getConcurrencyCollection(client); const session: ClientSession = client.startSession(); let updateResult: UpdateResult = { response: 'UNKNOWN_FAILURE' }; @@ -411,7 +411,7 @@ export async function updateDocumentByDocumentUuid( updateResult = await updateDocumentByDocumentUuidTransaction( updateRequest, mongoCollection, - concurrencyCollection, // RND-644 + concurrencyCollection, session, ); if (updateResult.response !== 'UPDATE_SUCCESS') { diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts index af1679e9..de7ed27d 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts @@ -36,7 +36,7 @@ const moduleName: string = 'mongodb.repository.Upsert'; export async function upsertDocumentTransaction( { resourceInfo, documentInfo, meadowlarkId, edfiDoc, validateDocumentReferencesExist, traceId, security }: UpsertRequest, mongoCollection: Collection, - concurrencyCollection: Collection, // RND-644 + concurrencyCollection: Collection, session: ClientSession, documentFromUpdate?: MeadowlarkDocument, ): Promise { @@ -148,7 +148,7 @@ export async function upsertDocumentTransaction( })); concurrencyDocuments.push({ meadowlarkId, documentUuid }); - await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // Perform the document upsert Logger.debug(`${moduleName}.upsertDocumentTransaction Upserting document uuid ${documentUuid}`, traceId); @@ -158,7 +158,7 @@ export async function upsertDocumentTransaction( asUpsert(session), ); - await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644 + await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); if (!acknowledged) { const msg = diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts index 3b9aabad..6c0b6b2d 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts @@ -199,7 +199,6 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted // **** The insert of AcademicWeek document should have been successful expect(upsertedCount).toBe(1); - // RND-644 // Adds the academic week and the, to be updated, school to the concurrency collection. const concurrencyDocumentsAcademicWeek: ConcurrencyDocument[] = []; concurrencyDocumentsAcademicWeek.push({ meadowlarkId: academicWeekMeadowlarkId, documentUuid }); @@ -212,7 +211,6 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted // ---- await upsertSession.commitTransaction(); - // RND-644 const concurrencyDocumentsSchool: ConcurrencyDocument[] = []; concurrencyDocumentsSchool.push({ meadowlarkId: schoolMeadowlarkId, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Update.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Update.test.ts index 7a80f169..a5fbca8e 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Update.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Update.test.ts @@ -200,7 +200,6 @@ describe('given an upsert (update) concurrent with an insert referencing the to- // **** The insert of AcademicWeek document should have been successful expect(upsertedCount).toBe(1); - // RND-644 // Adds the academic week and the, to be updated, school to the concurrency collection. const concurrencyDocumentsAcademicWeek: ConcurrencyDocument[] = []; concurrencyDocumentsAcademicWeek.push({ meadowlarkId: academicWeekMeadowlarkId, documentUuid }); @@ -213,7 +212,6 @@ describe('given an upsert (update) concurrent with an insert referencing the to- // ---- await upsertSession.commitTransaction(); - // RND-644 const concurrencyDocumentsSchool: ConcurrencyDocument[] = []; concurrencyDocumentsSchool.push({ meadowlarkId: schoolMeadowlarkId,