From 1c3f5ddb04c75d71cdc5c31534f78a95010c5a88 Mon Sep 17 00:00:00 2001 From: gagik Date: Mon, 31 Mar 2025 13:24:37 +0200 Subject: [PATCH 1/6] feat(shell-api): add automerge information to sh.status() MONGOSH-1649 --- packages/shell-api/src/helpers.spec.ts | 1 + packages/shell-api/src/helpers.ts | 12 ++++++++++++ packages/shell-api/src/shard.spec.ts | 2 ++ 3 files changed, 15 insertions(+) diff --git a/packages/shell-api/src/helpers.spec.ts b/packages/shell-api/src/helpers.spec.ts index f39227fe02..34278d058e 100644 --- a/packages/shell-api/src/helpers.spec.ts +++ b/packages/shell-api/src/helpers.spec.ts @@ -224,6 +224,7 @@ describe('getPrintableShardStatus', function () { ); expect(status['most recently active mongoses']).to.have.lengthOf(1); expect(status.autosplit['Currently enabled']).to.equal('yes'); + expect(status.automerge['Currently enabled']).to.equal('yes'); expect(status.balancer['Currently enabled']).to.equal('yes'); expect( status.balancer['Failed balancer rounds in last 5 attempts'] diff --git a/packages/shell-api/src/helpers.ts b/packages/shell-api/src/helpers.ts index 403f5a12ae..eb6008bb11 100644 --- a/packages/shell-api/src/helpers.ts +++ b/packages/shell-api/src/helpers.ts @@ -327,6 +327,14 @@ export async function getPrintableShardStatus( autosplit === null || autosplit.enabled ? 'yes' : 'no', }; })(), + (async (): Promise => { + // Is automerge currently enabled, available since >= 7.0 + const automerge = await settingsColl.findOne({ _id: 'automerge' }); + result.automerge = { + 'Currently enabled': + automerge === null || automerge.enabled ? 'yes' : 'no', + }; + })(), (async (): Promise => { // Is the balancer currently enabled const balancerEnabled = await settingsColl.findOne({ _id: 'balancer' }); @@ -713,6 +721,10 @@ export type ShardingStatusResult = { autosplit: { 'Currently enabled': 'yes' | 'no'; }; + /** Available from 7.0.0 */ + automerge: { + 'Currently enabled': 'yes' | 'no'; + }; balancer: { 'Currently enabled': 'yes' | 'no'; 'Currently running': 'yes' | 'no' | 'unknown'; diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index d797666a0f..bfb7ac1bec 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -2419,6 +2419,7 @@ describe('Shard', function () { 'shardingVersion', 'shards', 'autosplit', + 'automerge', 'balancer', 'databases', ]); @@ -2463,6 +2464,7 @@ describe('Shard', function () { 'shardingVersion', 'shards', 'autosplit', + 'automerge', 'balancer', 'databases', ]); From cfb1c3a10ff7888f32ce08c1c8762437a58bac5e Mon Sep 17 00:00:00 2001 From: gagik Date: Mon, 31 Mar 2025 13:59:53 +0200 Subject: [PATCH 2/6] test: add start and stop automerge tests --- packages/shell-api/src/shard.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index bfb7ac1bec..ecd3fdc70a 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -2518,6 +2518,21 @@ describe('Shard', function () { ); }); }); + describe('automerge', function () { + skipIfServerVersion(mongos, '< 7.0'); // Available from 7.0 + it('stops correctly', async function () { + expect((await sh.stopAutoMerger()).acknowledged).to.equal(true); + expect( + (await sh.status()).value.automerge['Currently enabled'] + ).to.equal('no'); + }); + it('enables correctly', async function () { + expect((await sh.startAutoMerger()).acknowledged).to.equal(true); + expect( + (await sh.status()).value.automerge['Currently enabled'] + ).to.equal('yes'); + }); + }); describe('autosplit', function () { skipIfServerVersion(mongos, '> 6.x'); // Auto-splitter is removed in 7.0 it('disables correctly', async function () { From 721736a993136b7b286c588b6e8db10c2098c0cc Mon Sep 17 00:00:00 2001 From: gagik Date: Tue, 1 Apr 2025 11:34:11 +0200 Subject: [PATCH 3/6] fix: do not show if not explicitly enabled --- packages/shell-api/src/helpers.spec.ts | 2 +- packages/shell-api/src/helpers.ts | 13 +++++++------ packages/shell-api/src/shard.spec.ts | 27 +++++++++++++++----------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/shell-api/src/helpers.spec.ts b/packages/shell-api/src/helpers.spec.ts index 34278d058e..2df2741fed 100644 --- a/packages/shell-api/src/helpers.spec.ts +++ b/packages/shell-api/src/helpers.spec.ts @@ -224,7 +224,7 @@ describe('getPrintableShardStatus', function () { ); expect(status['most recently active mongoses']).to.have.lengthOf(1); expect(status.autosplit['Currently enabled']).to.equal('yes'); - expect(status.automerge['Currently enabled']).to.equal('yes'); + expect((status.automerge ?? {})['Currently enabled']).to.equal('yes'); expect(status.balancer['Currently enabled']).to.equal('yes'); expect( status.balancer['Failed balancer rounds in last 5 attempts'] diff --git a/packages/shell-api/src/helpers.ts b/packages/shell-api/src/helpers.ts index eb6008bb11..69ec523e08 100644 --- a/packages/shell-api/src/helpers.ts +++ b/packages/shell-api/src/helpers.ts @@ -330,10 +330,11 @@ export async function getPrintableShardStatus( (async (): Promise => { // Is automerge currently enabled, available since >= 7.0 const automerge = await settingsColl.findOne({ _id: 'automerge' }); - result.automerge = { - 'Currently enabled': - automerge === null || automerge.enabled ? 'yes' : 'no', - }; + if (automerge) { + result.automerge = { + 'Currently enabled': automerge.enabled ? 'yes' : 'no', + }; + } })(), (async (): Promise => { // Is the balancer currently enabled @@ -721,8 +722,8 @@ export type ShardingStatusResult = { autosplit: { 'Currently enabled': 'yes' | 'no'; }; - /** Available from 7.0.0 */ - automerge: { + /** Shown if explicitly set, available and enabled by default from 7.0.0 */ + automerge?: { 'Currently enabled': 'yes' | 'no'; }; balancer: { diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index ecd3fdc70a..1fcaf25ac5 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -2519,18 +2519,23 @@ describe('Shard', function () { }); }); describe('automerge', function () { - skipIfServerVersion(mongos, '< 7.0'); // Available from 7.0 - it('stops correctly', async function () { - expect((await sh.stopAutoMerger()).acknowledged).to.equal(true); - expect( - (await sh.status()).value.automerge['Currently enabled'] - ).to.equal('no'); + it('not shown if sh.status() if not explicitly enabled', async function () { + expect((await sh.status()).value.automerge).is.undefined; }); - it('enables correctly', async function () { - expect((await sh.startAutoMerger()).acknowledged).to.equal(true); - expect( - (await sh.status()).value.automerge['Currently enabled'] - ).to.equal('yes'); + describe('from 7.0', function () { + skipIfServerVersion(mongos, '< 7.0'); // Available from 7.0 + it('stops correctly', async function () { + expect((await sh.stopAutoMerger()).acknowledged).to.equal(true); + expect( + ((await sh.status()).value.automerge ?? {})['Currently enabled'] + ).to.equal('no'); + }); + it('enables correctly', async function () { + expect((await sh.startAutoMerger()).acknowledged).to.equal(true); + expect( + ((await sh.status()).value.automerge ?? {})['Currently enabled'] + ).to.equal('yes'); + }); }); }); describe('autosplit', function () { From 56150621c999d1b442bd1da01bf483fcfd282bc9 Mon Sep 17 00:00:00 2001 From: gagik Date: Tue, 1 Apr 2025 12:29:30 +0200 Subject: [PATCH 4/6] fix: test automerge separately --- packages/shell-api/src/helpers.spec.ts | 1 - packages/shell-api/src/shard.spec.ts | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/shell-api/src/helpers.spec.ts b/packages/shell-api/src/helpers.spec.ts index 2df2741fed..f39227fe02 100644 --- a/packages/shell-api/src/helpers.spec.ts +++ b/packages/shell-api/src/helpers.spec.ts @@ -224,7 +224,6 @@ describe('getPrintableShardStatus', function () { ); expect(status['most recently active mongoses']).to.have.lengthOf(1); expect(status.autosplit['Currently enabled']).to.equal('yes'); - expect((status.automerge ?? {})['Currently enabled']).to.equal('yes'); expect(status.balancer['Currently enabled']).to.equal('yes'); expect( status.balancer['Failed balancer rounds in last 5 attempts'] diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index 1fcaf25ac5..14cb46d735 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -2419,7 +2419,6 @@ describe('Shard', function () { 'shardingVersion', 'shards', 'autosplit', - 'automerge', 'balancer', 'databases', ]); @@ -2464,12 +2463,23 @@ describe('Shard', function () { 'shardingVersion', 'shards', 'autosplit', - 'automerge', 'balancer', 'databases', ]); }); }); + describe('with a 7.0+ server', function () { + skipIfServerVersion(mongos, '< 7.0'); + + it('displays automerge status, if explicitly set', async function () { + await sh.startAutoMerger(); + const result = await sh.status(); + + expect(result.value.automerge).to.deep.equal({ + 'Currently enabled': 'yes', + }); + }); + }); }); describe('turn on sharding', function () { it('enableSharding for a db', async function () { From 4b531d9fc0b337c0ab3b8760b3ec9b472b8a9dd7 Mon Sep 17 00:00:00 2001 From: gagik Date: Tue, 1 Apr 2025 14:31:06 +0200 Subject: [PATCH 5/6] fix: do not assume not explicitly enabled by default for 7.0+ It's possible the setting can exist in the cluster we're using so we shouldn't have a test assuming it'd be undefined (and thus not show) for versions >= 7 --- packages/shell-api/src/shard.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index 14cb46d735..b304304589 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -2530,6 +2530,8 @@ describe('Shard', function () { }); describe('automerge', function () { it('not shown if sh.status() if not explicitly enabled', async function () { + // It might be explicitly set from 7.0 + skipIfServerVersion(mongos, '>= 7.0'); expect((await sh.status()).value.automerge).is.undefined; }); describe('from 7.0', function () { From 3496b4b2803d73bc814f71977bb2a440bdad2c29 Mon Sep 17 00:00:00 2001 From: gagik Date: Wed, 2 Apr 2025 10:33:55 +0200 Subject: [PATCH 6/6] fix: delete automerge settings before checking for omission --- packages/shell-api/src/shard.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index b304304589..cfc6fd37fa 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -2532,6 +2532,13 @@ describe('Shard', function () { it('not shown if sh.status() if not explicitly enabled', async function () { // It might be explicitly set from 7.0 skipIfServerVersion(mongos, '>= 7.0'); + + // Ensure no previous automerge settings are present + await instanceState.currentDb + .getSiblingDB('config') + .getCollection('settings') + .deleteOne({ _id: 'automerge' }); + expect((await sh.status()).value.automerge).is.undefined; }); describe('from 7.0', function () {