Skip to content
Merged
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
77 changes: 76 additions & 1 deletion packages/shell-api/src/shard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ describe('Shard', function () {
expect(reshardCollectionStub.firstCall.args).to.deep.equal([
'db.coll',
{ key: 1 },
{ numInitialChunks: 1000, forceRedistribution: true },
{ forceRedistribution: true },
]);
});

Expand Down Expand Up @@ -1860,6 +1860,81 @@ describe('Shard', function () {
{ numInitialChunks: 1, forceRedistribution: true },
]);
});

it('allows user to pass collation', async function () {
const expectedResult = { ok: 1 };

const shardCollectionStub = sinon
.stub(shard, 'shardCollection')
.resolves(expectedResult);
const reshardCollectionStub = sinon
.stub(shard, 'reshardCollection')
.resolves(expectedResult);

await shard.shardAndDistributeCollection('db.coll', { key: 1 }, true, {
collation: { locale: 'simple' },
});

expect(shardCollectionStub.calledOnce).to.equal(true);
expect(shardCollectionStub.firstCall.args).to.deep.equal([
'db.coll',
{
key: 1,
},
true,
{
collation: { locale: 'simple' },
},
]);

expect(reshardCollectionStub.calledOnce).to.equal(true);
expect(reshardCollectionStub.firstCall.args).to.deep.equal([
'db.coll',
{ key: 1 },
{ collation: { locale: 'simple' }, forceRedistribution: true },
]);
});

it('allows user to pass shard-specific options and ignores them when resharding', async function () {
const expectedResult = { ok: 1 };

const shardCollectionStub = sinon
.stub(shard, 'shardCollection')
.resolves(expectedResult);
const reshardCollectionStub = sinon
.stub(shard, 'reshardCollection')
.resolves(expectedResult);

await shard.shardAndDistributeCollection('db.coll', { key: 1 }, true, {
presplitHashedZones: true,
timeseries: {
timeField: 'ts',
},
});

expect(shardCollectionStub.calledOnce).to.equal(true);
expect(shardCollectionStub.firstCall.args).to.deep.equal([
'db.coll',
{
key: 1,
},
true,
{
presplitHashedZones: true,
timeseries: {
timeField: 'ts',
},
},
]);

expect(reshardCollectionStub.calledOnce).to.equal(true);
expect(reshardCollectionStub.firstCall.args).to.deep.equal([
'db.coll',
{ key: 1 },
{ forceRedistribution: true },
]);
});

it('returns whatever shard.reshardCollection returns', async function () {
const expectedResult = { ok: 1 };
sinon.stub(shard, 'reshardCollection').resolves(expectedResult);
Expand Down
26 changes: 17 additions & 9 deletions packages/shell-api/src/shard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,16 +710,24 @@ export default class Shard extends ShellApiWithMongoClass {
options,
});
await this.shardCollection(ns, key, unique, options);
// SERVER-92762: Prevent unequal data distribution by setting
// numInitialChunks to 1000.
const numInitialChunks =
typeof unique === 'object'
? unique.numInitialChunks
: options?.numInitialChunks;
return await this.reshardCollection(ns, key, {
numInitialChunks: numInitialChunks ?? 1000,

if (typeof unique === 'object') {
options = unique;
}

const reshardOptions: Document = {
forceRedistribution: true,
});
};

if (options?.numInitialChunks !== undefined) {
reshardOptions.numInitialChunks = options.numInitialChunks;
}

if (options?.collation !== undefined) {
Copy link
Collaborator Author

@nirinchev nirinchev Feb 21, 2025

Choose a reason for hiding this comment

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

I'm not 100% sure about this one, but reading the docs for reshardCollection, it appears that there are cases where collation must be included. We would already be passing it correctly to shardCollection, but were previously ignoring it for reshardCollection, which would have resulted in the latter failing.

reshardOptions.collation = options.collation;
}

return await this.reshardCollection(ns, key, reshardOptions);
}

@serverVersions(['8.0.0', ServerVersions.latest])
Expand Down
Loading