Skip to content

Commit

Permalink
fix: avoid global writes for self managed sharding COMPASS-8579 (#6535)
Browse files Browse the repository at this point in the history
* fix: avoid global writes for self managed sharding COMPASS_8579

* test: add tests
  • Loading branch information
paula-stacho authored Nov 28, 2024
1 parent 0fdb9d1 commit 9fec0b0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
32 changes: 32 additions & 0 deletions packages/compass-connections/src/utils/connection-supports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const mockConnections: ConnectionInfo[] = [
instanceSize: 'M10',
clusterType: 'SHARDED',
clusterUniqueId: 'clusterUniqueId',
geoSharding: {
selfManagedSharding: false,
},
},
},
{
Expand All @@ -111,6 +114,26 @@ const mockConnections: ConnectionInfo[] = [
clusterUniqueId: 'clusterUniqueId',
},
},
{
id: 'dedicated-geo-sharded-self-managed',
connectionOptions: {
connectionString: 'mongodb://foo',
},
atlasMetadata: {
orgId: 'orgId',
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
metricsId: 'metricsId',
metricsType: 'cluster',
instanceSize: 'M30',
clusterType: 'GEOSHARDED',
clusterUniqueId: 'clusterUniqueId',
geoSharding: {
selfManagedSharding: true,
},
},
},
];

function connectionInfoById(connectionId: string): ConnectionInfo {
Expand Down Expand Up @@ -195,5 +218,14 @@ describe('connectionSupports', function () {
)
).to.be.true;
});

it('should return false if the cluster type is geosharded but self managed', function () {
expect(
connectionSupports(
connectionInfoById('dedicated-geo-sharded-self-managed'),
'globalWrites'
)
).to.be.false;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ function supportsGlobalWrites(connectionInfo: ConnectionInfo) {
return false;
}

return atlasMetadata.clusterType === 'GEOSHARDED';
return (
atlasMetadata.clusterType === 'GEOSHARDED' &&
!atlasMetadata.geoSharding?.selfManagedSharding
);
}

export function connectionSupports(
Expand Down
7 changes: 7 additions & 0 deletions packages/compass-web/src/connection-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ describe('buildConnectionInfoFromClusterDescription', function () {
dataProcessingRegion: {
regionalUrl: 'https://example.com',
},
geoSharding: {
selfManagedSharding: true,
},
replicationSpecList: [
{
regionConfigs: [
Expand Down Expand Up @@ -162,6 +165,10 @@ describe('buildConnectionInfoFromClusterDescription', function () {
instanceSize: expectedInstanceSize,
regionalBaseUrl: 'https://example.com',
clusterType: clusterDescription.clusterType,
geoSharding: {
selfManagedSharding:
clusterDescription.geoSharding?.selfManagedSharding,
},
});
});
}
Expand Down
6 changes: 6 additions & 0 deletions packages/compass-web/src/connection-storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type ClusterDescription = {
deploymentItemName: string;
replicationSpecList?: ReplicationSpec[];
isPaused?: boolean;
geoSharding?: {
selfManagedSharding?: boolean;
};
};

export type ClusterDescriptionWithDataProcessingRegion = ClusterDescription & {
Expand Down Expand Up @@ -205,6 +208,9 @@ export function buildConnectionInfoFromClusterDescription(
...getMetricsIdAndType(description, deploymentItem),
instanceSize: getInstanceSize(description),
clusterType: description.clusterType,
geoSharding: {
selfManagedSharding: description.geoSharding?.selfManagedSharding,
},
},
};
}
Expand Down
4 changes: 4 additions & 0 deletions packages/connection-info/src/connection-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export interface AtlasClusterMetadata {
* https://github.com/10gen/mms/blob/9e6bf2d81d4d85b5ac68a15bf471dcddc5922323/client/packages/types/nds/clusterDescription.ts#L12-L16
*/
clusterType: 'REPLICASET' | 'SHARDED' | 'GEOSHARDED';

geoSharding?: {
selfManagedSharding?: boolean;
};
}

export interface ConnectionInfo {
Expand Down

0 comments on commit 9fec0b0

Please sign in to comment.