-
Notifications
You must be signed in to change notification settings - Fork 245
feat: add sharded state COMPASS-8279 #6304
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9c255d6
setup sharded state
mabaasit c8c1ade
Merge branch 'main' into sharded-state
paula-stacho 1771242
small fixes
paula-stacho b62fb1c
some more fixes + tests
paula-stacho 9da1f6b
more tests
paula-stacho 3709b00
update tests
paula-stacho 7cb7a51
lodash
paula-stacho e6fb8e9
logId
paula-stacho 6f9e7b2
Merge branch 'main' into sharded-state
paula-stacho facd106
logId
paula-stacho 9bce1fa
address PR suggestions
paula-stacho 5093e36
update test
paula-stacho 734225b
update another test
paula-stacho eabd0ff
Update packages/compass-global-writes/src/components/states/shard-key…
paula-stacho 7d9dda9
address PR suggestions & update tests
paula-stacho 6075f25
.
paula-stacho 525f044
Update packages/compass-global-writes/src/store/reducer.ts
paula-stacho e61b120
fix test
paula-stacho bc0793a
fix link
paula-stacho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/compass-global-writes/src/components/shard-zones-table.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import React from 'react'; | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableHead, | ||
| HeaderRow, | ||
| HeaderCell, | ||
| Row, | ||
| Cell, | ||
| css, | ||
| } from '@mongodb-js/compass-components'; | ||
| import type { ShardZoneData } from '../store/reducer'; | ||
|
|
||
| const containerStyles = css({ | ||
| maxWidth: '700px', | ||
| height: '400px', | ||
| }); | ||
|
|
||
| export function ShardZonesTable({ | ||
| shardZones, | ||
| }: { | ||
| shardZones: ShardZoneData[]; | ||
| }) { | ||
| return ( | ||
| // TODO: Add option to search and group zones by ShardZoneData.typeOneIsoCode | ||
| // and display them in nested row | ||
| <Table className={containerStyles} title="Zone Mapping"> | ||
| <TableHead isSticky> | ||
| <HeaderRow> | ||
| <HeaderCell>Location Name</HeaderCell> | ||
| <HeaderCell>Zone</HeaderCell> | ||
| </HeaderRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {shardZones.map((shardZone, index) => { | ||
| return ( | ||
| <Row key={index}> | ||
| <Cell>{shardZone.country}</Cell> | ||
| <Cell> | ||
| {shardZone.zoneName}({shardZone.zoneLocations.join(', ')}) | ||
| </Cell> | ||
| </Row> | ||
| ); | ||
| })} | ||
| </TableBody> | ||
| </Table> | ||
| ); | ||
| } |
192 changes: 192 additions & 0 deletions
192
packages/compass-global-writes/src/components/states/shard-key-correct.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| import React, { useMemo } from 'react'; | ||
| import { | ||
| Banner, | ||
| BannerVariant, | ||
| Body, | ||
| css, | ||
| Link, | ||
| spacing, | ||
| Code, | ||
| Subtitle, | ||
| Label, | ||
| SpinLoader, | ||
| Button, | ||
| } from '@mongodb-js/compass-components'; | ||
| import { connect } from 'react-redux'; | ||
| import { | ||
| ShardingStatuses, | ||
| unmanageNamespace, | ||
| type RootState, | ||
| type ShardKey, | ||
| type ShardZoneData, | ||
| } from '../../store/reducer'; | ||
| import toNS from 'mongodb-ns'; | ||
| import { ShardZonesTable } from '../shard-zones-table'; | ||
|
|
||
| const nbsp = '\u00a0'; | ||
|
|
||
| const containerStyles = css({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: spacing[400], | ||
| }); | ||
|
|
||
| const codeBlockContainerStyles = css({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: spacing[100], | ||
| maxWidth: '700px', | ||
| }); | ||
|
|
||
| const paragraphStyles = css({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: spacing[100], | ||
| }); | ||
|
|
||
| type ShardKeyCorrectProps = { | ||
| namespace: string; | ||
| shardKey: ShardKey; | ||
| shardZones: ShardZoneData[]; | ||
| isUnmanagingNamespace: boolean; | ||
| onUnmanageNamespace: () => void; | ||
| }; | ||
|
|
||
| export function ShardKeyCorrect({ | ||
paula-stacho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| namespace, | ||
| shardKey, | ||
| shardZones, | ||
| isUnmanagingNamespace, | ||
| onUnmanageNamespace, | ||
| }: ShardKeyCorrectProps) { | ||
| const customShardKeyField = useMemo(() => { | ||
| return shardKey.fields[1].name; | ||
| }, [shardKey]); | ||
|
|
||
| const sampleCodes = useMemo(() => { | ||
| const { collection } = toNS(namespace); | ||
| return { | ||
| findingDocuments: `use ${collection}\ndb.${collection}.find({"location": "US-NY", "${customShardKeyField}": "<id_value>"})`, | ||
| insertingDocuments: `use ${collection}\ndb.${collection}.insertOne({"location": "US-NY", "${customShardKeyField}": "<id_value>",...<other fields>})`, | ||
| }; | ||
| }, [namespace, customShardKeyField]); | ||
|
|
||
| return ( | ||
| <div className={containerStyles}> | ||
| <Banner variant={BannerVariant.Info}> | ||
| <strong> | ||
| All documents in your collection should contain both the ‘location’ | ||
| field (with a ISO country or subdivision code) and your{' '} | ||
| {customShardKeyField} field at insert time. | ||
| </strong> | ||
| {nbsp}We have included a table for reference below. | ||
| </Banner> | ||
|
|
||
| <div className={codeBlockContainerStyles}> | ||
| <Body> | ||
| <strong>{namespace}</strong> is configured with the following shard | ||
| key: | ||
| </Body> | ||
| <Code language="js">{namespace}</Code> | ||
| </div> | ||
|
|
||
| <Subtitle>Example commands</Subtitle> | ||
| <div className={paragraphStyles}> | ||
| <Body> | ||
| Start querying your database with some of the most{' '} | ||
| <Link | ||
| href="https://www.mongodb.com/docs/atlas/global-clusters" | ||
| hideExternalIcon | ||
| > | ||
| common commands | ||
| </Link>{' '} | ||
| for Global Writes. | ||
| </Body> | ||
| <Body> | ||
| Replace the text to perform operations on different documents. US-NY | ||
| is an ISO 3166 location code referring to New York, United States. You | ||
| can look up other ISO 3166 location codes below. | ||
| </Body> | ||
| </div> | ||
|
|
||
| <div className={codeBlockContainerStyles}> | ||
| <Label htmlFor="finding-documents">Finding documents</Label> | ||
paula-stacho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Code language="js">{sampleCodes.findingDocuments}</Code> | ||
| </div> | ||
|
|
||
| <div className={codeBlockContainerStyles}> | ||
| <Label htmlFor="inserting-documents">Inserting documents</Label> | ||
| <Code language="js">{sampleCodes.insertingDocuments}</Code> | ||
| </div> | ||
|
|
||
| <Subtitle>Location Codes</Subtitle> | ||
| <div className={paragraphStyles}> | ||
| <Body> | ||
| Each document’s first field should include an ISO 3166-1 Alpha-2 code | ||
| for the location it belongs to. | ||
| </Body> | ||
| <Body> | ||
| We also support ISO 3166-2 subdivision codes for countries containing | ||
| a cloud provider data center (both ISO 3166-1 and ISO 3166-2 codes may | ||
| be used for these countries). All valid country codes and the zones to | ||
| which they map are listed in the table below. Additionally, you can | ||
| view a list of all location codes{' '} | ||
| <Link | ||
| href="https://cloud-dev.mongodb.com/static/atlas/country_iso_codes.txt" | ||
| hideExternalIcon | ||
| > | ||
| here | ||
| </Link> | ||
| . | ||
| </Body> | ||
| <Body> | ||
| Locations’ zone mapping can be changed by navigating to this clusters{' '} | ||
| <Link | ||
| hideExternalIcon | ||
| href="https://cloud-dev.mongodb.com/v2/66bb81dafe547055785904a3#/clusters/edit/Cluster0" | ||
| > | ||
| Edit Configuration | ||
| </Link>{' '} | ||
| page and clicking the Configure Location Mappings’ link above the map. | ||
| </Body> | ||
| </div> | ||
|
|
||
| <ShardZonesTable shardZones={shardZones} /> | ||
|
|
||
| <Subtitle>Unmanage this collection</Subtitle> | ||
| <Body> | ||
| Documents belonging to this collection will no longer be distributed | ||
| across the shards of your global clusters. | ||
| </Body> | ||
| <div> | ||
| <Button | ||
| data-testid="shard-collection-button" | ||
| onClick={onUnmanageNamespace} | ||
| disabled={isUnmanagingNamespace} | ||
| variant="primary" | ||
| leftGlyph={ | ||
| isUnmanagingNamespace ? ( | ||
| <SpinLoader title="Unmanaging collection" /> | ||
paula-stacho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) : undefined | ||
| } | ||
| > | ||
| Unmanage collection | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default connect( | ||
| (state: RootState) => ({ | ||
| namespace: state.namespace, | ||
| // For this view, sharKey is always defined | ||
| shardKey: state.shardKey as ShardKey, | ||
paula-stacho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| shardZones: state.shardZones, | ||
| isUnmanagingNamespace: | ||
| state.status === ShardingStatuses.UNMANAGING_NAMESPACE, | ||
| }), | ||
| { | ||
| onUnmanageNamespace: unmanageNamespace, | ||
| } | ||
| )(ShardKeyCorrect); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.