Skip to content

An option to place objects in breadth-first order for plain and plain_rewritable metadata engines #65321

Closed

Description

@alexey-milovidov

Problem

The plain and plain_rewritable metadata engines store objects on S3 with names identical to their paths in the virtual filesystem (possibly under some common prefix).

The virtual filesystem abstraction (which is named IDisk) has a method to list files in a subdirectory.

AWS S3 also has a method to list files in a prefix. However, the ordering of objects in S3 is not hierarchical - it is lexicographical by paths. That's why it has customizations, such as "which character to use as a separator, default '/'" and "should we group together objects under common prefixes, so it will look like a subdirectory". It means that it processes all the names in lexicographic order and groups them dynamically. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html

The method of listing objects in AWS S3 is also very slow and inefficient - it can return a maximum of 1000 items and has to be done iteratively for large results.

Table engines, such as MergeTree, can perform list operation recursively. For example, list data parts, then go into each data part and list files there. According to the points above, it looks like a duplicate work, because listing the parent directory will implicitly traverse the subdirectories and ignore them.

Example of the filesystem layout in lexicographic order, which AWS S3 has to iterate: https://pastila.nl/?00062e5b/73b7dfb03f24a8d32c2414340bdd9baa#U+a/E8FW3kHxUUi/waHScA==

Proposal

Implement a configuration option for plain and plain_rewritable metadata engines named breadth_first_layout. If this option is enabled, the object names will be prefixed by the depth. So instead of:

github_events/all_4023_4023_0/updated_at.cmrk2

they will look like:

002/github_events/all_4023_4023_0/updated_at.cmrk2

where 002 is the prefix, determining the depth.

Using this layout, listing of files in a subdirectory will process only immediate children.

Additional info

By the way, we already have the web layout containing special index files, which totally removes the listing directories operation. It is used for static tables on HTTP servers, such as GitHub pages: https://github.com/ClickHouse/web-tables-demo

The method IObjectStorage::iterate is not lazy - it collects the result first and then returns the iterator. That's why a query starts slowly when querying S3 with a large number of files.

It is recommended to do list operations in parallel if the result is large, by predicting object names and making many list operations with offsets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

easy taskperformance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions