Skip to content

Support move and tag action for S3/Azure Queue table engines - #86907

Merged
kssenii merged 31 commits into
ClickHouse:masterfrom
mxwell:storage_queue_move_tag
Nov 24, 2025
Merged

kssenii merged 31 commits into
ClickHouse:masterfrom
mxwell:storage_queue_move_tag

Conversation

@mxwell

@mxwell mxwell commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Users can now configure S3/Azure Queue tables to move or tag processed files, in addition to the previous options to keep or remove files. Resolves #72944

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Details

If post processing action is set to move, processed objects can be moved to a different path prefix or another bucket/container. Move requires additional table settings such as:

  • new path prefix
  • or bucket URL and credentials in case of S3
  • or connection string and container name in case of Azure

Tagging requires additional settings to pass tag key and value.

Resolves #72944

@kssenii kssenii self-assigned this Sep 9, 2025
@kssenii kssenii added the can be tested Allows running workflows for external contributors label Sep 9, 2025
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [544263f]

Summary: ❌

job_name test_name status info comment
Build (amd_compat) failure
Cmake configuration failure cidb
Stateless tests (amd_ubsan, parallel) failure
02177_issue_31009 FAIL cidb, flaky
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: FAIL cidb
BuzzHouse (arm_asan) failure
Logical error: 'Bad cast from type DB::ColumnString to DB::ColumnVector'. FAIL cidb
BuzzHouse (amd_ubsan) failure
/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/src/IO/VarInt.h:32:5: runtime error: store to null pointer of type 'char' FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Sep 9, 2025
@mxwell
mxwell force-pushed the storage_queue_move_tag branch 2 times, most recently from 2216fe6 to ecefa93 Compare September 14, 2025 14:29
@mxwell
mxwell force-pushed the storage_queue_move_tag branch from 9f45a31 to c50be46 Compare September 25, 2025 12:01
@mxwell
mxwell force-pushed the storage_queue_move_tag branch from c50be46 to 33dc38d Compare October 5, 2025 16:18
auto az_context = Azure::Core::Context();
return static_credential_a->get()->GetToken(tokenRequestContext, az_context).Token == static_credential_b->get()->GetToken(tokenRequestContext, az_context).Token;
}
return compareAzureAuthMethod(auth_method_a, auth_method_b);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the method body as compareAzureAuthMethod() to common place, to be reachable by src/Storages/ObjectStorageQueue/ObjectStorageQueuePostProcessor.cpp

@@ -138,6 +138,13 @@ class CachedObjectStorage final : public IObjectStorage
}
#endif

#if USE_AZURE_BLOB_STORAGE || USE_AWS_S3
void tagObjects(const StoredObjects & objects, const std::string & tag_key, const std::string & tag_value) override

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cached object storage seems to be working on top of some other storage, so it makes sense to support tagObjects() for the case of Azure/S3 underlying storage.

@@ -11,4 +11,13 @@ size_t getTotalSize(const StoredObjects & objects)
return size;
}

Strings collectRemotePaths(const StoredObjects & objects)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Put this into a common place as it's used by both Azure/S3 storage implementations

extern const int LOGICAL_ERROR;
}

ObjectStorageQueuePostProcessor::ObjectStorageQueuePostProcessor(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The after-processing logic was duplicated in src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp and src/Storages/ObjectStorageQueue/ObjectStorageQueueSource.cpp. It was fine as it only took few lines of code.

This PR extends the logic with more actions, so I extracted it into a class, ObjectStorageQueuePostProcessor, to be used in the commit() methods.

@@ -4789,6 +4789,25 @@ def grep_in_log(
logging.debug("grep result %s", result)
return result

def count_log_lines(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is an attempt to fix the failing (but unrelated) test test_streaming_to_many_views. It reads a fixed size tail of the log to check something. But depending on log verbosity, needed lines can slip from the tail. I saw an attempt to fix it by increasing tail size (100k -> 200k). However, I think this approach with calculating the exact reading position is more reliable.

I can extract this idea into a separate PR. It might be off-topic here.

@@ -1659,7 +1659,10 @@ def ignore_exceptions(f, *args):
)
long_select.start()

sleep_start_time = time.time()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is an attempt to investigate the failing (unrelated) test. My guess is that duration check can be flaky as it includes time.sleep() that doesn't guarantee upper bound.

I can scrap these changes as the fail hasn't repeated.

total_values = generate_random_files(
started_cluster, files_path, files_num, row_num=row_num, storage=storage
)
create_table(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Main steps in tag/move tests are mostly copy/pasted from test_delete_after_processing

if engine_name == "S3Queue":
recreate_minio_bucket(started_cluster, processed_bucket)
else:
recreate_azurite_container(started_cluster, processed_bucket)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The move test is different from other tests here: it creates a new bucket in case of a move across buckets.

@@ -507,6 +726,8 @@ def get_rows_count():
create_dst_table_first=False
)

log_line_offset = node.count_log_lines()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Attempt to fix failing (unrelated) test

@mxwell

mxwell commented Oct 10, 2025

Copy link
Copy Markdown
Contributor Author

CI failures seem unrelated to my changes.

Also, I've added some explanatory comments to the code.

mxwell added 11 commits October 11, 2025 03:11
If action is set to move, objects can be moved to a different path prefix or another bucket/container.
Move requires additional table settings such as new path prefix, or bucket URL and credentials in case of S3, or connection string and container name in case of Azure.

Tag requires addtional settings to pass tag key and value.

@kssenii kssenii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Huge thanks for adding this feature!

@kssenii

kssenii commented Nov 20, 2025

Copy link
Copy Markdown
Member

@mxwell could you please adjust test test_storage_s3_queue/test_4.py::test_alter_settings?

File: test_storage_s3_queue/test_4.py:301 - in test_alter_settings
    assert '"after_processing":"keep"' in node1.query(
E   assert '"after_processing":"keep"' in 'failed\t\t/clickhouse/test_test_alter_settings_defcdbc4\nprocessing\t\t/clickhouse/test_test_alter_settings_defcdbc4\npersistent_processing\t\t/clickhouse/test_test_alter_settings_defcdbc4\nregistry\t1\\ninstance\\n22fb41b7-a7a7-40bd-9cf7-114a42e09bfb\\n6feaced6-6efc-47c5-be2b-f5ea2a1a9cc4\\n,1\\ninstance2\\n22fb41b7-a7a7-40bd-9cf7-114a42e09bfb\\n9dc3b004-83fc-4c75-88a2-745828f468af\\n\t/clickhouse/test_test_alter_settings_defcdbc4\nprocessed\t\t/clickhouse/test_test_alter_settings_defcdbc4\nmetadata\t{"buckets":0,"columns":"columns format version: 1\\\\n3 columns:\\\\n`column1` UInt32\\\\n`column2` UInt32\\\\n`column3` UInt32\\\\n","format_name":"CSV","last_processed_file":"","loading_retries":20,"mode":"unordered","processing_threads_num":10,"tracked_files_limit":2000,"tracked_files_ttl_sec":0}\t/clickhouse/test_test_alter_settings_defcdbc4\n'
E    +  where 'failed\t\t/clickhouse/test_test_alter_settings_defcdbc4\nprocessing\t\t/clickhouse/test_test_alter_settings_defcdbc4\npersistent_processing\t\t/clickhouse/test_test_alter_settings_defcdbc4\nregistry\t1\\ninstance\\n22fb41b7-a7a7-40bd-9cf7-114a42e09bfb\\n6feaced6-6efc-47c5-be2b-f5ea2a1a9cc4\\n,1\\ninstance2\\n22fb41b7-a7a7-40bd-9cf7-114a42e09bfb\\n9dc3b004-83fc-4c75-88a2-745828f468af\\n\t/clickhouse/test_test_alter_settings_defcdbc4\nprocessed\t\t/clickhouse/test_test_alter_settings_defcdbc4\nmetadata\t{"buckets":0,"columns":"columns format version: 1\\\\n3 columns:\\\\n`column1` UInt32\\\\n`column2` UInt32\\\\n`column3` UInt32\\\\n","format_name":"CSV","last_processed_file":"","loading_retries":20,"mode":"unordered","processing_threads_num":10,"tracked_files_limit":2000,"tracked_files_ttl_sec":0}\t/clickhouse/test_test_alter_settings_defcdbc4\n' = query("SELECT * FROM system.zookeeper WHERE path = '/clickhouse/test_test_alter_settings_defcdbc4'")
E    +    where query = <helpers.cluster.ClickHouseInstance object at 0x7f37f53ef280>.query

@mxwell

mxwell commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

@mxwell could you please adjust test test_storage_s3_queue/test_4.py::test_alter_settings?

Sure. And just to reiterate: after my updates, no after_processing* settings are stored to ZK. Previously, after_processing was stored there. But, as you indicated above, it is not necessary.

@kssenii

kssenii commented Nov 20, 2025 •

Copy link
Copy Markdown
Member

Yes, ok to remove. Though it could cause an issue if there are servers with different versions on the cluster with DatabaseReplicated - one of which on a version without this PR and if s3queue table is created on a server with version containing this PR. (then a replica on older version could fail to create a table with error about s3queue metadata failing to parse because of a missing field), so I makes sense to leave just after_processing in keeper to avoid such issues.

@mxwell

mxwell commented Nov 21, 2025

Copy link
Copy Markdown
Contributor Author

failing to parse because of a missing field

This PR also introduces new possible values. I haven't checked, but it looks like an old server might not work if the keeper has after_processing=tag (or move). Old code:

ObjectStorageQueueAction ObjectStorageQueueTableMetadata::actionFromString(const std::string & action)
{
    if (action == "keep")
        return ObjectStorageQueueAction::KEEP;
    if (action == "delete")
        return ObjectStorageQueueAction::DELETE;
    throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected ObjectStorageQueue action: {}", action);
}

Should the new version stick to these 2 values only? So that tag and move are stored to Keeper as keep. Also, the new version should ignore values from Keeper, otherwise it can get conflicting after_processing values from different sources.

Can you please confirm a preferable option?

@kssenii

kssenii commented Nov 22, 2025

Copy link
Copy Markdown
Member

Let's just keep only after processing action in keeper, it is less likely that a new feature is used before upgrade of all replicas is finished.

@kssenii
kssenii enabled auto-merge November 24, 2025 09:13
@kssenii
kssenii added this pull request to the merge queue Nov 24, 2025
Merged via the queue into ClickHouse:master with commit 03d53e0 Nov 24, 2025
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 24, 2025
@alexey-milovidov alexey-milovidov added the 🎅 🎁 gift🎄 To make people wonder label Dec 7, 2025
@kolesnikov-av

Copy link
Copy Markdown

@mxwell

mxwell commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

how to move processed files to another folder while preserving the lower-level directory structure

Not possible right now. Only file name is preserved during the move:

const String file_name = fileName(src.remote_path);
const String remote_path = fs::path(move_prefix) / file_name;

Possible direction for development

I wonder what are good examples from other tools or languages that express the desired behavior.

I see that rsync has --relative that preserves the full path. But here you need to preserve the path skipping the first folder.

Maybe after_processing_move_relative_from_level=2? Where 0 preserves only file name, 1 preserves the full path, 2 skips the first folder, etc.

This is only my thoughts. It would be interesting to hear someone from the team.

@kolesnikov-av

Copy link
Copy Markdown

how to move processed files to another folder while preserving the lower-level directory structure

Not possible right now. Only file name is preserved during the move:

Thanks!

You can specify two prefixes in the settings — a source prefix and a target prefix — and perform a string replacement during the transfer.

In practice, for example, this is similar to copying a folder with nested subfolders and files into another directory within a file system.

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

Labels

can be tested Allows running workflows for external contributors 🎅 🎁 gift🎄 To make people wonder pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More options for [S3/Azure]Queue table engines

6 participants