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

feat(DB): Introduce DB write concern env var for createStatements (LLC-2389) #896

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ EXPRESS_PORT=8081

# If set this will override AWS access secret for FS_S3_SECRET_ACCESS_KEY and WINSTON_CLOUDWATCH_SECRET_ACCESS_KEY
#GLOBAL_AWS_IAM_SECRET_ACCESS_KEY=

# Write concern for statements insertMany
#STORE_STATEMENT_WRITE_CONCERN_DEFAULT=
4 changes: 4 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
env:
WINSTON_CONSOLE_LEVEL: none
EXPRESS_PORT: 1337
STORE_STATEMENT_WRITE_CONCERN_DEFAULT: 1

services:
mongodb:
Expand Down Expand Up @@ -93,6 +94,7 @@ jobs:
env:
WINSTON_CONSOLE_LEVEL: none
EXPRESS_PORT: 1337
STORE_STATEMENT_WRITE_CONCERN_DEFAULT: 1
STORAGE_REPO: s3
SUB_FOLDER_ACTIVITIES: gha/$GITHUB_RUN_NUMBER_$GITHUB_RUN_ATTEMPT
SUB_FOLDER_AGENTS: SUB_FOLDER_AGENTS=gha/$GITHUB_RUN_NUMBER_$GITHUB_RUN_ATTEMPT
Expand Down Expand Up @@ -153,6 +155,7 @@ jobs:
env:
WINSTON_CONSOLE_LEVEL: none
EXPRESS_PORT: 1337
STORE_STATEMENT_WRITE_CONCERN_DEFAULT: 1
STORAGE_REPO: azure
FS_AZURE_CONTAINER_SUBFOLDER: gha/$GITHUB_RUN_NUMBER_$GITHUB_RUN_ATTEMPT
FS_AZURE_ACCOUNT: ${{ secrets.FS_AZURE_ACCOUNT }}
Expand Down Expand Up @@ -209,6 +212,7 @@ jobs:
env:
WINSTON_CONSOLE_LEVEL: none
EXPRESS_PORT: 1337
STORE_STATEMENT_WRITE_CONCERN_DEFAULT: 1
STORAGE_REPO: google
FS_GOOGLE_CLOUD_BUCKET: ${{ secrets.FS_GOOGLE_CLOUD_BUCKET }}
FS_GOOGLE_CLOUD_PROJECT_ID: ${{ secrets.FS_GOOGLE_CLOUD_PROJECT_ID }}
Expand Down
12 changes: 10 additions & 2 deletions src/apps/statements/repo/modelsRepo/createStatements/mongo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable no-console */
import { ObjectId } from 'mongodb';
import { STATEMENTS_COLLECTION_NAME } from '../utils/mongoModels/constants';
import {
STATEMENTS_COLLECTION_NAME,
STORE_STATEMENT_WRITE_CONCERN_DEFAULT,
} from '../utils/mongoModels/constants';
import FacadeConfig from '../utils/mongoModels/FacadeConfig';
import { encodeDotsInStatement } from '../utils/mongoModels/replaceDotsInStatement';
import Signature from './Signature';
Expand All @@ -22,7 +26,11 @@ export default (config: FacadeConfig): Signature => {
});

const collection = (await config.db()).collection(STATEMENTS_COLLECTION_NAME);
await collection.insertMany(documents);
console.time('STATEMENT INSERTION');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logs are for measurements in the QA process only and will be removed

await collection.insertMany(documents, {
writeConcern: { w: STORE_STATEMENT_WRITE_CONCERN_DEFAULT },
});
console.timeEnd('STATEMENT INSERTION');
return opts.models;
};
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import getNumberOption from 'jscommons/dist/config/getNumberOption';

export const STATEMENTS_COLLECTION_NAME = 'statements';
export const LRS_COLLECTION_NAME = 'lrs';
export const FULL_ACTIVITIES_COLLECTION_NAME = 'fullActivities';

const WRITE_CONCERN_DEFAULT = 3;
Comment on lines +6 to +7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MongoDB's default is majority and here our default is 3. This would create behavioural change immediately upon deployment.

export const STORE_STATEMENT_WRITE_CONCERN_DEFAULT =
process.env.STORE_STATEMENT_WRITE_CONCERN_DEFAULT === 'majority'
? process.env.STORE_STATEMENT_WRITE_CONCERN_DEFAULT
: getNumberOption(process.env.STORE_STATEMENT_WRITE_CONCERN_DEFAULT, WRITE_CONCERN_DEFAULT);