Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/row-lookup-filesystem-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/app': patch
---

perf: row lookups read from the ClickHouse filesystem cache when the data is
already there, without filling the cache with data nothing else is likely to
read.
17 changes: 16 additions & 1 deletion packages/app/src/components/DBRowDataPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata';
import {
isLogSource,
isTraceSource,
QuerySettings,
SourceKind,
TSource,
} from '@hyperdx/common-utils/dist/types';
Expand Down Expand Up @@ -54,6 +55,15 @@ export enum ROW_DATA_ALIASES {
// looks the same row up again. Those lookups reuse a found row instead of
// running `SELECT *` again. A miss stays stale so the next lookup retries it:
// the row may not have been ingested yet.
// A single-row lookup reads few granules, so it uses whatever is already in the
// filesystem cache without filling it with data nothing else is likely to read.
const ROW_LOOKUP_QUERY_SETTINGS: QuerySettings = [
{
setting: 'read_from_filesystem_cache_if_exists_otherwise_bypass_cache',
value: '1',
},
];

function rowLookupStaleTime(query: Query<ChartQueryResult>) {
return query.state.data?.data.length ? Infinity : 0;
}
Expand Down Expand Up @@ -273,7 +283,12 @@ export function useRowData({
...(aliasWith && aliasWith.length > 0 ? { with: aliasWith } : {}),
};

const additionalQuerySettings = useSelectAllColumnsQuerySettings(source);
const selectAllColumnsQuerySettings =
useSelectAllColumnsQuerySettings(source);
const additionalQuerySettings: QuerySettings = [
...ROW_LOOKUP_QUERY_SETTINGS,
...(selectAllColumnsQuerySettings ?? []),
];

// This key replaces the config-derived one, so it has to carry the column
// check's effect on the select.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ describe('row lookup', () => {
},
);

it('reads from the filesystem cache without filling it', async () => {
renderPanel({ source, rowId: "id='a'" });
await settled();

expect(mockQueryChartConfig.mock.calls[0][0].querySettings).toContainEqual({
setting: 'read_from_filesystem_cache_if_exists_otherwise_bypass_cache',
value: '1',
});
});

it('reuses a found row when the panel opens it again', async () => {
const first = renderPanel({ source, rowId: "id='a'" });
await settled();
Expand Down
19 changes: 13 additions & 6 deletions packages/app/src/components/__tests__/DBRowDataPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function queriedOptions(call = 0) {
return options;
}

const ROW_LOOKUP_SETTING = {
setting: 'read_from_filesystem_cache_if_exists_otherwise_bypass_cache',
value: '1',
};

const showMaterializedAliasColumns = () =>
localStorage.setItem('hdx-row-show-materialized-alias-columns', 'true');

Expand Down Expand Up @@ -321,11 +326,11 @@ describe('DBRowDataPanel', () => {
});
});

it('adds no query settings while the viewer option is off', () => {
it('adds only the filesystem cache setting while the viewer option is off', () => {
renderHook(() => useRowData({ source, rowId: "id='abc123'" }));

for (const options of [queriedOptions(0), queriedOptions(1)]) {
expect(options.additionalQuerySettings).toBeUndefined();
expect(options.additionalQuerySettings).toEqual([ROW_LOOKUP_SETTING]);
expect(options.retry).toBeUndefined();
}
});
Expand All @@ -336,6 +341,7 @@ describe('DBRowDataPanel', () => {

for (const options of [queriedOptions(0), queriedOptions(1)]) {
expect(options.additionalQuerySettings).toEqual([
ROW_LOOKUP_SETTING,
{ setting: 'asterisk_include_materialized_columns', value: '1' },
{ setting: 'asterisk_include_alias_columns', value: '1' },
]);
Expand All @@ -357,11 +363,12 @@ describe('DBRowDataPanel', () => {

const options = queriedOptions();
expect(options.additionalQuerySettings).toEqual([
ROW_LOOKUP_SETTING,
{ setting: 'asterisk_include_materialized_columns', value: '1' },
]);
});

it('adds no query settings when the source sets both itself', () => {
it('adds no column settings when the source sets both itself', () => {
showMaterializedAliasColumns();
const sourceWithSettings: TLogSource = {
...source,
Expand All @@ -376,10 +383,10 @@ describe('DBRowDataPanel', () => {
);

const options = queriedOptions();
expect(options.additionalQuerySettings).toBeUndefined();
expect(options.additionalQuerySettings).toEqual([ROW_LOOKUP_SETTING]);
});

it('adds no query settings when the source has a Known Columns List', () => {
it('adds no column settings when the source has a Known Columns List', () => {
showMaterializedAliasColumns();
const sourceWithKnownColumns: TLogSource = {
...source,
Expand All @@ -391,7 +398,7 @@ describe('DBRowDataPanel', () => {
);

for (const options of [queriedOptions(0), queriedOptions(1)]) {
expect(options.additionalQuerySettings).toBeUndefined();
expect(options.additionalQuerySettings).toEqual([ROW_LOOKUP_SETTING]);
}
});

Expand Down
Loading