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

Read node_id from discovery_nodes table in RDBMS #4042

Merged
merged 25 commits into from
Jun 29, 2023

Conversation

arcusfelis
Copy link
Contributor

@arcusfelis arcusfelis commented Jun 21, 2023

This PR addresses MIM-1916

Task: MongooseIM’s ejabberd_node_id should work without Mnesia.

As a part of adding support to disable Mnesia, we need to store node_id’s somewhere.
Currently it is a simple file with only Mnesia support.

We use node_id’s in two places:

  • MAM, to avoid collisions in the mam ids.
    we now use src/mongoose_node_num.erl file. The node id is set from mnesia or from rdbms. It is not that critical if it remains 0 though, collisions for MAM ID inside one archive are not allowed, but extremely unlikely.

  • local IQs module, so we know which node generated which IQ request, when handling IQ result that came from s2s, for example. We don’t need numbers here, we could generate a random uuid on the node start and store it across the cluster instead
    check src/mongoose_start_node_id.erl module for the logic

Change name for ejabberd_node_id - DONE (there were no ejabberd_node_id module in ejabberd, it was added in mongooseim during MAM work just the name was following the naming convention back than - i.e. every non-gen-module code has this prefix to avoid name clashing).

Maybe just adding an auto-incremented key to the discovery_nodes table is an option - DONE, but we also check for gaps now.

@mongoose-im

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 83.47% and project coverage change: +0.01 🎉

Comparison is base (712a164) 82.20% compared to head (b83dc98) 82.21%.

Additional details and impacted files
@@               Coverage Diff                @@
##           feature/cets    #4042      +/-   ##
================================================
+ Coverage         82.20%   82.21%   +0.01%     
================================================
  Files               539      541       +2     
  Lines             33952    34012      +60     
================================================
+ Hits              27909    27962      +53     
- Misses             6043     6050       +7     
Impacted Files Coverage Δ
src/mam/mod_mam_muc.erl 75.46% <ø> (ø)
src/mam/mod_mam_pm.erl 89.60% <ø> (ø)
src/ejabberd_app.erl 89.77% <73.33%> (-3.98%) ⬇️
src/mongoose_start_node_id.erl 75.00% <75.00%> (ø)
src/mongoose_cets_discovery_rdbms.erl 82.92% <82.92%> (+7.92%) ⬆️
src/ejabberd_local.erl 76.66% <100.00%> (-0.39%) ⬇️
src/ejabberd_sup.erl 78.57% <100.00%> (+0.52%) ⬆️
src/mam/mod_mam_utils.erl 89.05% <100.00%> (ø)
src/mongoose_node_num.erl 100.00% <100.00%> (ø)
src/mongoose_node_num_mnesia.erl 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mongoose-im

This comment was marked as outdated.

There are two backends: Mnesia or CETS disco.

If none backends are useful, we fallback to node_id to be 0 (which is not that major issue for MAM ID collisions)
@mongoose-im

This comment was marked as outdated.

@mongoose-im

This comment was marked as outdated.

We don't care if test2 is returned in a list returned on test2 node
@mongoose-im

This comment was marked as outdated.

@mongoose-im

This comment was marked as off-topic.

No unsigned type
@mongoose-im

This comment was marked as outdated.

@mongoose-im

This comment was marked as outdated.

@mongoose-im

This comment was marked as outdated.

@mongoose-im

This comment was marked as outdated.

@mongoose-im
Copy link
Collaborator

mongoose-im commented Jun 23, 2023

small_tests_24 / small_tests / 8978847
Reports root / small


small_tests_25_arm64 / small_tests / 8978847
Reports root / small


small_tests_25 / small_tests / 8978847
Reports root / small


ldap_mnesia_24 / ldap_mnesia / 8978847
Reports root/ big
OK: 2224 / Failed: 0 / User-skipped: 838 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_24 / pgsql_mnesia / 8978847
Reports root/ big
OK: 4198 / Failed: 0 / User-skipped: 90 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / 8978847
Reports root/ big
OK: 2224 / Failed: 0 / User-skipped: 838 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_25 / pgsql_mnesia / 8978847
Reports root/ big
OK: 4198 / Failed: 0 / User-skipped: 90 / Auto-skipped: 0


dynamic_domains_mysql_redis_25 / mysql_redis / 8978847
Reports root/ big
OK: 4172 / Failed: 0 / User-skipped: 116 / Auto-skipped: 0


dynamic_domains_mssql_mnesia_25 / odbc_mssql_mnesia / 8978847
Reports root/ big
OK: 4195 / Failed: 0 / User-skipped: 93 / Auto-skipped: 0


elasticsearch_and_cassandra_25 / elasticsearch_and_cassandra_mnesia / 8978847
Reports root/ big
OK: 2730 / Failed: 0 / User-skipped: 671 / Auto-skipped: 0


internal_mnesia_25 / internal_mnesia / 8978847
Reports root/ big
OK: 2377 / Failed: 1 / User-skipped: 693 / Auto-skipped: 0

pubsub_SUITE:dag+node_config:retrieve_configuration_test
{error,{{badmatch,false},
    [{pubsub_tools,check_response,2,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_tools.erl"},
            {line,491}]},
     {pubsub_tools,receive_response,3,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_tools.erl"},
            {line,481}]},
     {pubsub_tools,receive_and_check_response,4,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_tools.erl"},
            {line,471}]},
     {escalus_story,story,4,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
             {line,72}]},
     {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
     {test_server,run_test_case_eval1,6,
            [{file,"test_server.erl"},{line,1291}]},
     {test_server,run_test_case_eval,9,
            [{file,"test_server.erl"},{line,1223}]}]}}

Report log


pgsql_mnesia_24 / pgsql_mnesia / 8978847
Reports root/ big
OK: 4571 / Failed: 0 / User-skipped: 99 / Auto-skipped: 0


mysql_redis_25 / mysql_redis / 8978847
Reports root/ big
OK: 4557 / Failed: 0 / User-skipped: 113 / Auto-skipped: 0


pgsql_cets_25 / pgsql_cets / 8978847
Reports root/ big
OK: 4547 / Failed: 0 / User-skipped: 123 / Auto-skipped: 0


pgsql_mnesia_25 / pgsql_mnesia / 8978847
Reports root/ big
OK: 4571 / Failed: 0 / User-skipped: 99 / Auto-skipped: 0


mssql_mnesia_25 / odbc_mssql_mnesia / 8978847
Reports root/ big
OK: 4568 / Failed: 0 / User-skipped: 102 / Auto-skipped: 0

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

It's looking good in general. I added a few comments, and I have a question: I understand that we don't need numbers in ejabberd_local but what's wrong about using them, and thus avoiding the need to have two kinds of node id's? Is your intention to actually enforce a fresh id on each node restart, so that we don't try to handle a response for a request sent by a node that was already restarted?

src/ejabberd_app.erl Outdated Show resolved Hide resolved
src/ejabberd_app.erl Outdated Show resolved Hide resolved
src/mongoose_cets_discovery_rdbms.erl Show resolved Hide resolved
src/mongoose_cets_discovery_rdbms.erl Outdated Show resolved Hide resolved
src/mongoose_cets_discovery_rdbms.erl Show resolved Hide resolved
src/mongoose_start_node_id.erl Outdated Show resolved Hide resolved
@arcusfelis
Copy link
Contributor Author

Main motivation was to still able to use ejabberd_local with test presets that do not have rdbms or mnesia. So, decided to split responsibilities. Automatic cleaning on node restart comes for free in this case. I was worried a bit about conflict resolution strategy for node nums. Because changing node num in runtime would not affect any MAM logic. But for iqs routing it will break not finished replies, so decided a spend a bit of time to make iq routing not failing for sure.

@mongoose-im
Copy link
Collaborator

mongoose-im commented Jun 29, 2023

small_tests_25_arm64 / small_tests / b83dc98
Reports root / small


small_tests_24 / small_tests / b83dc98
Reports root / small


small_tests_25 / small_tests / b83dc98
Reports root / small


ldap_mnesia_24 / ldap_mnesia / b83dc98
Reports root/ big
OK: 2224 / Failed: 0 / User-skipped: 838 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_24 / pgsql_mnesia / b83dc98
Reports root/ big
OK: 4198 / Failed: 0 / User-skipped: 90 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / b83dc98
Reports root/ big
OK: 2224 / Failed: 0 / User-skipped: 838 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_25 / pgsql_mnesia / b83dc98
Reports root/ big
OK: 4198 / Failed: 0 / User-skipped: 90 / Auto-skipped: 0


pgsql_mnesia_24 / pgsql_mnesia / b83dc98
Reports root/ big
OK: 4571 / Failed: 0 / User-skipped: 99 / Auto-skipped: 0


dynamic_domains_mssql_mnesia_25 / odbc_mssql_mnesia / b83dc98
Reports root/ big
OK: 4195 / Failed: 0 / User-skipped: 93 / Auto-skipped: 0


dynamic_domains_mysql_redis_25 / mysql_redis / b83dc98
Reports root/ big
OK: 4172 / Failed: 0 / User-skipped: 116 / Auto-skipped: 0


pgsql_cets_25 / pgsql_cets / b83dc98
Reports root/ big
OK: 4547 / Failed: 0 / User-skipped: 123 / Auto-skipped: 0


internal_mnesia_25 / internal_mnesia / b83dc98
Reports root/ big
OK: 2370 / Failed: 0 / User-skipped: 692 / Auto-skipped: 0


elasticsearch_and_cassandra_25 / elasticsearch_and_cassandra_mnesia / b83dc98
Reports root/ big
OK: 2730 / Failed: 0 / User-skipped: 671 / Auto-skipped: 0


mysql_redis_25 / mysql_redis / b83dc98
Reports root/ big
OK: 4557 / Failed: 0 / User-skipped: 113 / Auto-skipped: 0


pgsql_mnesia_25 / pgsql_mnesia / b83dc98
Reports root/ big
OK: 4571 / Failed: 0 / User-skipped: 99 / Auto-skipped: 0


mssql_mnesia_25 / odbc_mssql_mnesia / b83dc98
Reports root/ big
OK: 4568 / Failed: 0 / User-skipped: 102 / Auto-skipped: 0

@chrzaszcz chrzaszcz merged commit 461ba2d into feature/cets Jun 29, 2023
4 checks passed
@chrzaszcz chrzaszcz deleted the feature-cets-node_id branch June 29, 2023 09:09
@chrzaszcz chrzaszcz added this to the 6.2.0 milestone Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants