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

レプリケーション設定時におけるinsertOne()の挙動を調整 #15109

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

samunohito
Copy link
Member

@samunohito samunohito commented Dec 9, 2024

※2024.12.0より後にしたい

What

各Repositoryが持つinsertOne()メソッドの挙動を少し変更します。
この対応により、insertOne()によるレコード挿入は必ずmasterノードで行うようになります。

Why

fix #10897

Additional info (optional)

  • ローカルにて動作確認
  • パッチの先行適用を行い現状問題なく動作しているとのこと(misskey.systems鯖缶のご厚意により… 🙏 )

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions github-actions bot added the packages/backend Server side specific issue/PR label Dec 9, 2024
@samunohito samunohito changed the title レプリケーション設定時におけるinsertOne()の挙動を調整 [wip] レプリケーション設定時におけるinsertOne()の挙動を調整 Dec 9, 2024
Copy link
Contributor

github-actions bot commented Dec 9, 2024

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 88.52459% with 7 lines in your changes missing coverage. Please review.

Project coverage is 39.97%. Comparing base (e8bf628) to head (ca03491).

Files with missing lines Patch % Lines
packages/backend/src/models/_.ts 83.78% 6 Missing ⚠️
packages/backend/src/postgres.ts 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #15109      +/-   ##
===========================================
+ Coverage    39.96%   39.97%   +0.01%     
===========================================
  Files         1563     1563              
  Lines       197752   197798      +46     
  Branches      3634     3640       +6     
===========================================
+ Hits         79031    79070      +39     
- Misses      118116   118123       +7     
  Partials       605      605              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@samunohito samunohito marked this pull request as ready for review December 10, 2024 10:15
@samunohito samunohito changed the title [wip] レプリケーション設定時におけるinsertOne()の挙動を調整 レプリケーション設定時におけるinsertOne()の挙動を調整 Dec 10, 2024
@samunohito
Copy link
Member Author

open

Copy link
Member Author

@samunohito samunohito left a comment

Choose a reason for hiding this comment

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

(pendingのままだった)

Comment on lines +106 to +107
const opt = this.manager.connection.options as PostgresConnectionOptions;
if (opt.replication) {
Copy link
Member Author

Choose a reason for hiding this comment

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

configに設定したreplicationの値が巡り巡ってこの値に入っています。
レプリケーションが無効の時はnull(かundefinedかは忘れましたが)になっているので、else(=今までの処理)に流れます。

@@ -92,14 +103,31 @@ export const miRepository = {
return this.metadata.columns.filter(column => column.isSelect && !column.isVirtual).map(column => column.databaseName);
},
async insertOne(entity, findOptions?) {
const opt = this.manager.connection.options as PostgresConnectionOptions;
if (opt.replication) {
const queryRunner = this.manager.connection.createQueryRunner('master');
Copy link
Member Author

Choose a reason for hiding this comment

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

これによりmasterノードでクエリを実行してくれるrunnerが取れます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages/backend Server side specific issue/PR
Projects
Development

Successfully merging this pull request may close these issues.

Better db replication support
1 participant