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

Catch no database found errors from cache manager #296

Merged
merged 2 commits into from
Mar 25, 2024
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
17 changes: 17 additions & 0 deletions public/components/SQLPage/sql_catalog_tree/s3_tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@
stopLoading: stopLoadingAccelerations,
} = catalogCacheRefs.useLoadAccelerationsToCache();

const refreshDatabasesinTree = () => {
const currentTree = [...treeData];
currentTree.map((db) => {
setTreeData(
produce((draft) => {
const databaseToUpdate = draft.find((database) => database.name === db.name);
if (databaseToUpdate) {
databaseToUpdate.isExpanded = false;
databaseToUpdate.isLoading = false;
databaseToUpdate.values = [];
}
})
);
});
};

const updateDatabaseState = (databaseName: string, isLoading: boolean, values?: TreeItem[]) => {
setTreeData(
produce((draft) => {
Expand All @@ -93,7 +109,7 @@
const constructObjectTree = (
database: string,
tablesData: string[],
accelerationsData: any[]

Check warning on line 112 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
) => {
const tablesTreeItems = tablesData.map((table) => {
const indices = findSkippingAndCoveringIndexNames(accelerationsData, database, table);
Expand Down Expand Up @@ -220,11 +236,12 @@
useEffect(() => {
const status = loadDatabasesStatus.toLowerCase();
if (status === AsyncQueryStatus.Success) {
refreshDatabasesinTree();
setIsTreeLoading({ status: false, message: '' });
} else if (status === AsyncQueryStatus.Failed || status === AsyncQueryStatus.Cancelled) {
setIsTreeLoading({ status: false, message: 'Failed to load databases' });
}
}, [loadDatabasesStatus]);

Check warning on line 244 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'refreshDatabasesinTree'. Either include it or remove the dependency array

useEffect(() => {
const status = loadTablesStatus.toLowerCase();
Expand All @@ -233,7 +250,7 @@
} else if (status === AsyncQueryStatus.Failed || status === AsyncQueryStatus.Cancelled) {
setIsObjectLoading({ ...isObjectLoading, tableStatus: false });
}
}, [loadTablesStatus]);

Check warning on line 253 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'isObjectLoading'. Either include it or remove the dependency array. You can also do a functional update 'setIsObjectLoading(i => ...)' if you only need 'isObjectLoading' in the 'setIsObjectLoading' call

useEffect(() => {
const status = loadAccelerationsStatus.toLowerCase();
Expand All @@ -242,11 +259,11 @@
} else if (status === AsyncQueryStatus.Failed || status === AsyncQueryStatus.Cancelled) {
setIsObjectLoading({ ...isObjectLoading, accelerationsStatus: false });
}
}, [loadAccelerationsStatus]);

Check warning on line 262 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'isObjectLoading'. Either include it or remove the dependency array. You can also do a functional update 'setIsObjectLoading(i => ...)' if you only need 'isObjectLoading' in the 'setIsObjectLoading' call

useEffect(() => {
onLoadS3Tree();
}, [dataSource]);

Check warning on line 266 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'onLoadS3Tree'. Either include it or remove the dependency array

useEffect(() => {
setIsFirstRender(false);
Expand All @@ -258,7 +275,7 @@
}
// This will only execute on changes to refreshTree after the initial render
onRefreshTree();
}, [refreshTree]);

Check warning on line 278 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'isFirstRender' and 'onRefreshTree'. Either include them or remove the dependency array

useEffect(() => {
if (
Expand All @@ -272,7 +289,7 @@
updateDatabaseState(currentSelectedDatabase, false);
setCurrentSelectedDatabase('');
}
}, [isObjectLoading]);

Check warning on line 292 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'constructObjectTree', 'currentSelectedDatabase', and 'dataSource'. Either include them or remove the dependency array

useEffect(() => {
return () => {
Expand All @@ -280,7 +297,7 @@
stopLoadingTables();
stopLoadingAccelerations();
};
}, []);

Check warning on line 300 in public/components/SQLPage/sql_catalog_tree/s3_tree.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'stopDatabasesLoading', 'stopLoadingAccelerations', and 'stopLoadingTables'. Either include them or remove the dependency array

const treeLoadingStateRenderer = (
<EuiFlexGroup alignItems="center" gutterSize="s" direction="column">
Expand Down
43 changes: 28 additions & 15 deletions public/components/SQLPage/sql_catalog_tree/s3_tree_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TREE_ITEM_TABLE_NAME_DEFAULT_NAME,
} from '../../../../common/constants';
import { CachedDataSourceStatus, TreeItem, TreeItemType } from '../../../../common/types';
import { useToast } from '../../../../common/utils/toast_helper';
import { catalogCacheRefs } from '../../../framework/catalog_cache_refs';

export const handleQuery = (
Expand Down Expand Up @@ -84,7 +85,7 @@
}
};

export const loadTreeItem = (elements: string[], type: TreeItemType, values?: any): TreeItem[] => {

Check warning on line 88 in public/components/SQLPage/sql_catalog_tree/s3_tree_helpers.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return elements.map((element) => {
const treeItem: TreeItem = {
name: element,
Expand All @@ -105,24 +106,36 @@
};

export const isEitherObjectCacheEmpty = (dataSourceName: string, databaseName: string) => {
const dbCache = catalogCacheRefs.CatalogCacheManager!.getDatabase(dataSourceName, databaseName);
const dsCache = catalogCacheRefs.CatalogCacheManager!.getOrCreateAccelerationsByDataSource(
dataSourceName
);
return (
dbCache.status === CachedDataSourceStatus.Empty ||
dsCache.status === CachedDataSourceStatus.Empty ||
dbCache.status === CachedDataSourceStatus.Failed ||
dsCache.status === CachedDataSourceStatus.Failed
);
try {
const dbCache = catalogCacheRefs.CatalogCacheManager!.getDatabase(dataSourceName, databaseName);
const dsCache = catalogCacheRefs.CatalogCacheManager!.getOrCreateAccelerationsByDataSource(
dataSourceName
);
return (
dbCache.status === CachedDataSourceStatus.Empty ||
dsCache.status === CachedDataSourceStatus.Empty ||
dbCache.status === CachedDataSourceStatus.Failed ||
dsCache.status === CachedDataSourceStatus.Failed
);
} catch (error) {
console.error(error);
return false;
}
};

export const getTablesFromCache = (dataSourceName: string, databaseName: string) => {
const dbCache = catalogCacheRefs.CatalogCacheManager!.getDatabase(dataSourceName, databaseName);
if (dbCache.status === CachedDataSourceStatus.Updated) {
const tables = dbCache.tables.map((tb) => tb.name);
return tables;
} else {
const { setToast } = useToast();

Check failure on line 127 in public/components/SQLPage/sql_catalog_tree/s3_tree_helpers.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook "useToast" is called in function "getTablesFromCache" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"
try {
const dbCache = catalogCacheRefs.CatalogCacheManager!.getDatabase(dataSourceName, databaseName);
if (dbCache.status === CachedDataSourceStatus.Updated) {
const tables = dbCache.tables.map((tb) => tb.name);
return tables;
} else {
return [];
}
} catch (error) {
console.error(error);
setToast('Your cache is outdated, refresh databases and tables', 'warning');
return [];
}
};
Expand All @@ -139,7 +152,7 @@
}
};

export const findSkippingAndCoveringIndexNames = (data: any[], database: string, table: string) => {

Check warning on line 155 in public/components/SQLPage/sql_catalog_tree/s3_tree_helpers.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const filteredIndexes = _.filter(data, (obj) => {
return (
obj.database === database &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Compatible with OpenSearch and OpenSearch Dashboards 2.13.0

- Refactor async calls and minor bug fixes ([#274](https://github.com/opensearch-project/dashboards-query-workbench/pull/274))
- Add empty tree state for SQL sidebar ([#292](https://github.com/opensearch-project/dashboards-query-workbench/pull/292))
- Catch no database found errors from cache manager ([#296](https://github.com/opensearch-project/dashboards-query-workbench/pull/296))

### Infrastructure

Expand Down
Loading