Skip to content
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

chore(compas-indexes): store real indexes and in-progress indexes as separate lists #6300

Merged
merged 9 commits into from
Oct 1, 2024

Conversation

lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Sep 30, 2024

Extracted out of #6290

The basic idea is to not merge real indexes and in-progress indexes in the store. That's error prone because you can't really merge them together. All we have to go on is index name and if you override either the in progress details or the real index details it leads to bugs either way. We poll the real details now anyway, so it is eventually consistent as it is. With rolling indexes this just gets worse.

Furthermore, the types aren't really very compatible. We have an index name and little more for in-progress indexes at the moment and for rolling indexes we'll have a name and a type. If we want type and properties for a regular in-progress index we have to infer that based on the input ourselves and in future if we want properties for rolling indexes we have to map those from atlas' response type ourselves. Similar for any other field we might display in the table. Things like size and usage count can only be zero in those cases too. So I decided to have three types (two in this PR) and corresponding lists, then we concatenate them together in the table.

This happens to fit redux's recommendation to not store derived state in the store.

The rest of the changes are caused by that basic decision or just drive-by fixes of bugs I spotted while working on it. Partially caught by having narrower types for regular and in progress indexes.

if (serverSupportsHideIndex(serverVersion)) {
actions.unshift(
if (
index.compassIndexType === 'regular-index' &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bug - we showed the hide button for in-progress indexes.

@@ -58,6 +74,19 @@ const IndexActions: React.FunctionComponent<IndexActionsProps> = ({
);
}

// you can only drop regular indexes or failed inprogress indexes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was also a bug - you could drop an in progress index that was really still in progress and that just wouldn't work because the index creation isn't failed and it isn't a real index yet either.


// TODO: this should be its own function, not part of dropIndex
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was actually momentarily a bug here. Because I'm not merging the in-progress indexes into indexes, the code:

const index = indexes.find((x) => x.name === indexName);

    if (!index) {
      return;
    }

which ran first meant that you could never get to the check to see if the thing is an in-progress index. Which wasn't as obvious to find and I think if the two things weren't both rolled into dropIndex() then it would have been easier to spot, more likely to be tested, etc.

type: React.ReactNode;
size: React.ReactNode;
usage: React.ReactNode;
usageCount: React.ReactNode;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were changing usageCount into usage back into usageCount..

@@ -95,7 +95,9 @@ describe('Indexes Component', function () {
},
});
expect(screen.getByTestId('indexes-toolbar')).to.exist;
// TODO: actually check for the error
expect(screen.getByTestId('indexes-error').textContent).to.equal(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by: I spotted the TODO when I audited the new TODOs I'm adding in this PR.

@lerouxb lerouxb marked this pull request as ready for review September 30, 2024 12:58
@@ -32,7 +32,7 @@ export type IndexDefinition = {
| 'columnstore';
cardinality: 'single' | 'compound';
properties: ('unique' | 'sparse' | 'partial' | 'ttl' | 'collation')[];
extra: Record<string, string | number | Record<string, any>>;
extra: Record<string, string | number | boolean | Record<string, any>>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just wrong. index.extra.hidden is true if it is set.

Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

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

Nice cleanup! A few small nits, but they are super optional, great work!

@lerouxb lerouxb merged commit 7d5c91a into main Oct 1, 2024
27 checks passed
@lerouxb lerouxb deleted the keep-indexes-separate branch October 1, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants