Skip to content

Commit

Permalink
Catch no database found errors from cache manager (opensearch-project…
Browse files Browse the repository at this point in the history
…#296)

* catch no database errors

Signed-off-by: Shenoy Pratik <[email protected]>

* update relese notes

Signed-off-by: Shenoy Pratik <[email protected]>

---------

Signed-off-by: Shenoy Pratik <[email protected]>
  • Loading branch information
ps48 authored Mar 25, 2024
1 parent d052907 commit 3d2deaf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
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 @@ export const S3Tree = ({ dataSource, updateSQLQueries, refreshTree }: S3TreeProp
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 Down Expand Up @@ -220,6 +236,7 @@ export const S3Tree = ({ dataSource, updateSQLQueries, refreshTree }: S3TreeProp
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' });
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 @@ import {
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 @@ -105,24 +106,36 @@ export const loadTreeItem = (elements: string[], type: TreeItemType, values?: an
};

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();
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 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

0 comments on commit 3d2deaf

Please sign in to comment.