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

feat: support system.parquet_files table #25002

Closed
wants to merge 26 commits into from

Conversation

hiltontj
Copy link
Contributor

@hiltontj hiltontj commented May 14, 2024

This PR is intended to follow #25000.

Extend system table support to allow queries against system.parquet_files, a new system table that allows queries for parquet files associated with a given database and table.

Currently, the query will only look back on 1,000 segments to get associated parquet files, we may want to adjust that, or make it more flexible.

Two unit tests were added to query_executor for this, instead of E2E integration tests, as more control was needed over file persistence than what the E2E test harness provides.

Example

The system.parquet_files table can be queried like so:

SELECT * FROM system.parquet_files WHERE table_name = 'cpu'

And responds accordingly:

+------------+-------------------------------------------------+------------+-----------+---------------------+---------------------+
| table_name | path                                            | size_bytes | row_count | min_time            | max_time            |
+------------+-------------------------------------------------+------------+-----------+---------------------+---------------------+
| cpu        | dbs/foo/cpu/2024-05-14T20-53/4294967294.parquet | 1775       | 18        | 1715720025774406000 | 1715720035952490000 |
+------------+-------------------------------------------------+------------+-----------+---------------------+---------------------+

Other Changes

Another change in this PR was to go back to using dynamic dispatch for passing around the Persister. The associated types and generics made using the Persister a pain in the ParquetFilesTable implementation, so I removed those in favour of using Arc<dyn Persister>, as we had been doing previously (see 42d36d5).

Closes #24988

hiltontj added 15 commits May 9, 2024 15:56
A shell for the `system` table provider was added to the QueryExecutorImpl
which currently does not do anything, but will enable us to tie the
different system table providers into it.

The QueryLog was elevated from the `Database`, i.e., namespace provider,
to the QueryExecutorImpl, so that it lives accross queries.
The system.queries table is now accessible, when queries are initiated
in debug mode, which is not currently enabled via the HTTP API, therefore
this is not yet accessible unless via the gRPC interface.

The system.queries table lists all queries in the QueryLog on the
QueryExecutorImpl.
@hiltontj hiltontj added the v3 label May 14, 2024
@hiltontj hiltontj self-assigned this May 14, 2024
influxdb3_write/src/lib.rs Outdated Show resolved Hide resolved
@hiltontj hiltontj force-pushed the hiltontj/sys-tbl-parquet-files branch from 8bcfeec to 457e7d1 Compare May 15, 2024 18:25
@hiltontj hiltontj force-pushed the hiltontj/sys-tbl-parquet-files branch from 457e7d1 to f85fa78 Compare May 15, 2024 18:41
@hiltontj hiltontj marked this pull request as ready for review May 16, 2024 13:29
Copy link
Member

@pauldix pauldix left a comment

Choose a reason for hiding this comment

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

The SegmentState in the write buffer actually has the information for the last 1,000 persisted segments and their parquet files: https://github.com/influxdata/influxdb/blob/main/influxdb3_write/src/write_buffer/segment_state.rs#L45. This is populated on startup.

It may be a good idea to pull the parquet files information from there, rather than the persister/object store. When the buffer gets the ability to persist some table data ahead of the segment rolling over, that state will be kept there in memory and won't show up in a segment info file until after the segment rolls over.

I think I'll be refactoring the structure of SegmentState when doing that. So maybe wait until after that to change this?

@hiltontj
Copy link
Contributor Author

It may be a good idea to pull the parquet files information from [the SegmentState]

That makes sense and seems simpler. Giving the system table provider read access to the SegmentState shouldn't be too hard and reading the PersistedSegments off of that should be much cheaper than how I'm doing it here. In fact, with making this API public, I should be able to get them directly:

pub(crate) fn get_parquet_files(
&self,
database_name: &str,
table_name: &str,
) -> Vec<ParquetFile> {
let mut parquet_files = vec![];
for segment in self.persisted_segments.values() {
segment.databases.get(database_name).map(|db| {
db.tables.get(table_name).map(|table| {
parquet_files.extend(table.parquet_files.clone());
})
});
}
parquet_files
}

I can at least try that out and flag if there is an issue with doing so.

@hiltontj
Copy link
Contributor Author

@pauldix - after taking a quick look at using the SegmentState directly, I found it gets a bit messy with the generics on SegmentState. Its (truncated) definition is:

// T -> TimeProvider
// W -> Wal
struct SegmentState<T, W> {
    /* ... */
}

The reason it gets messy is because I need to get access via the Bufferer trait to whatever I need from the write buffer. So returning a thing with generics from the Bufferer trait becomes a nuisance. Getting the persister was easy because I could just put the persister method on Bufferer:

trait Bufferer {
    /* ... */
    fn persister(&self) -> Arc<dyn Persister>;
}

If you are re-thinking the segment state, it may be helpful to have a trait, e.g.,

trait SegmentStateProvider {
    fn get_parquet_files(&self) -> Vec<ParquetFile>;

    /* Other methods you are considering for this API */
}

Then that would be more easily extracted via the Bufferer trait and passed to the SystemTableProvider as Arc<dyn SegmentStateProvider>.

I can leave this for now, since you're planning to refactor, don't want to make doing so more difficult with changes here.

Base automatically changed from hiltontj/system-tables-no-debug to main May 17, 2024 16:39
Copy link
Contributor

@mgattozzi mgattozzi left a comment

Choose a reason for hiding this comment

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

This LGTM code wise. I'll defer to @pauldix though if there's anything else we need to get into this PR, but from a code perspective it looks great.

@hiltontj
Copy link
Contributor Author

Planning to wait on #25144 and any related refactoring to the influxdb3_write crate before revisiting this.

@hiltontj
Copy link
Contributor Author

hiltontj commented Aug 7, 2024

Closing in favour of #25225

@hiltontj hiltontj closed this Aug 7, 2024
@hiltontj hiltontj deleted the hiltontj/sys-tbl-parquet-files branch August 7, 2024 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create the system.parquet_files provider
3 participants