Skip to content

Commit 66c3e61

Browse files
authored
feat(shell-api): add automerge information to sh.status() MONGOSH-1649 (#2422)
1 parent 8395a18 commit 66c3e61

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

packages/shell-api/src/helpers.ts

+13
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ export async function getPrintableShardStatus(
327327
autosplit === null || autosplit.enabled ? 'yes' : 'no',
328328
};
329329
})(),
330+
(async (): Promise<void> => {
331+
// Is automerge currently enabled, available since >= 7.0
332+
const automerge = await settingsColl.findOne({ _id: 'automerge' });
333+
if (automerge) {
334+
result.automerge = {
335+
'Currently enabled': automerge.enabled ? 'yes' : 'no',
336+
};
337+
}
338+
})(),
330339
(async (): Promise<void> => {
331340
// Is the balancer currently enabled
332341
const balancerEnabled = await settingsColl.findOne({ _id: 'balancer' });
@@ -713,6 +722,10 @@ export type ShardingStatusResult = {
713722
autosplit: {
714723
'Currently enabled': 'yes' | 'no';
715724
};
725+
/** Shown if explicitly set, available and enabled by default from 7.0.0 */
726+
automerge?: {
727+
'Currently enabled': 'yes' | 'no';
728+
};
716729
balancer: {
717730
'Currently enabled': 'yes' | 'no';
718731
'Currently running': 'yes' | 'no' | 'unknown';

packages/shell-api/src/shard.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,18 @@ describe('Shard', function () {
24682468
]);
24692469
});
24702470
});
2471+
describe('with a 7.0+ server', function () {
2472+
skipIfServerVersion(mongos, '< 7.0');
2473+
2474+
it('displays automerge status, if explicitly set', async function () {
2475+
await sh.startAutoMerger();
2476+
const result = await sh.status();
2477+
2478+
expect(result.value.automerge).to.deep.equal({
2479+
'Currently enabled': 'yes',
2480+
});
2481+
});
2482+
});
24712483
});
24722484
describe('turn on sharding', function () {
24732485
it('enableSharding for a db', async function () {
@@ -2516,6 +2528,35 @@ describe('Shard', function () {
25162528
);
25172529
});
25182530
});
2531+
describe('automerge', function () {
2532+
it('not shown if sh.status() if not explicitly enabled', async function () {
2533+
// It might be explicitly set from 7.0
2534+
skipIfServerVersion(mongos, '>= 7.0');
2535+
2536+
// Ensure no previous automerge settings are present
2537+
await instanceState.currentDb
2538+
.getSiblingDB('config')
2539+
.getCollection('settings')
2540+
.deleteOne({ _id: 'automerge' });
2541+
2542+
expect((await sh.status()).value.automerge).is.undefined;
2543+
});
2544+
describe('from 7.0', function () {
2545+
skipIfServerVersion(mongos, '< 7.0'); // Available from 7.0
2546+
it('stops correctly', async function () {
2547+
expect((await sh.stopAutoMerger()).acknowledged).to.equal(true);
2548+
expect(
2549+
((await sh.status()).value.automerge ?? {})['Currently enabled']
2550+
).to.equal('no');
2551+
});
2552+
it('enables correctly', async function () {
2553+
expect((await sh.startAutoMerger()).acknowledged).to.equal(true);
2554+
expect(
2555+
((await sh.status()).value.automerge ?? {})['Currently enabled']
2556+
).to.equal('yes');
2557+
});
2558+
});
2559+
});
25192560
describe('autosplit', function () {
25202561
skipIfServerVersion(mongos, '> 6.x'); // Auto-splitter is removed in 7.0
25212562
it('disables correctly', async function () {

0 commit comments

Comments
 (0)