Skip to content

Refactor VersionMetadata and decouple version logic from IMergeTreeDataPart - #87125

Closed
tuanpach wants to merge 2 commits into
ClickHouse:masterfrom
tuanpach:decouple-version-logic-from-merge-tree-data-part
Closed

tuanpach wants to merge 2 commits into
ClickHouse:masterfrom
tuanpach:decouple-version-logic-from-merge-tree-data-part

Conversation

@tuanpach

@tuanpach tuanpach commented Sep 15, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Decouple version logic from IMergeTreeDataPart. This is the first step in supporting version metadata on Keeper, which enables transactions on SharedMergeTree.

This PR has the following changes:

  • Make VersionMetadata a base class.
  • Create VersionMetadataOnDisk subclass inheriting from VersionMetadata and persisting metadata on a disk along with the data part.
  • Move the logic of the old VersionMetadata to VersionMetadataOnDisk
  • Move version logic from IMergeTreeDataPart to VersionMetadata and VersionMetadataOnDisk

VersionMetadataOnKeeper will be another subclass of VersionMetadata

Refactor changes:

  • Move src/Interpreters/TransactionVersionMetadata.cpp, .h, -> src/Interpreters/MergeTreeTransaction/VersionMetadata.cpp, .h

  • Make VersionMetadata a base class

  • In VersionMetadata:

    • Separate the logic of storing removalTIDLock and removalTID.
      • Previously, removal_tid is set in tryLockRemovalTID, unlockRemovalTID. Then, stored in the metadata file with appendRemovalTIDToVersionMetadata(bool clear).
      • In this PR, lockRemovalTID and unlockRemovalTID only set the removal_tid_lock hash. removal_tid is set and stored in the stored data by storeRemovalTID.
    • Have new methods:
      • storeCreationCSN: set and store creation CSN
      • storeRemovalCSN: set and store removal CSN
      • storeRemovalTID: set and store removal TDI
      • loadAndVerifyMetadata: load and verify metadata stored in storage.
      • wasInvolvedInTransaction: check if the object was involved in a transaction
  • In VersionMetadataOnDisk which inherits from VersionMetadata:

    • Check if the storage supports writing with Append:
      • If yes, store the info in append mode
      • If no, overwrite it with the complete new metadata.
    • If the object is not involved in any transaction, it might delay storing the data into storage. Previously, the check was done in VersionMetadata.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@tuanpach tuanpach added the can be tested Allows running workflows for external contributors label Sep 15, 2025
@tuanpach
tuanpach marked this pull request as draft September 15, 2025 13:12
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [027645a]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan, targeted) failure
01459_manual_write_to_replicas_quorum_detach_attach FAIL cidb, flaky
01459_manual_write_to_replicas_quorum_detach_attach FAIL cidb, flaky
Stateless tests (amd_msan, parallel) failure
00816_long_concurrent_alter_column FAIL cidb, flaky
03096_order_by_system_tables FAIL cidb
Stateless tests (arm_binary, parallel) failure
03300_merge_parts_metric FAIL cidb
Integration tests (amd_tsan, 5/6) failure
test_filesystem_cache/test.py::test_parallel_cache_loading_on_startup[node] FAIL cidb
test_filesystem_cache/test.py::test_caches_with_the_same_configuration[node] FAIL cidb
test_filesystem_cache/test.py::test_force_filesystem_cache_on_merges FAIL cidb
test_filesystem_cache/test.py::test_system_sync_filesystem_cache FAIL cidb
test_filesystem_cache/test.py::test_keep_up_size_ratio FAIL cidb
test_filesystem_cache/test.py::test_filesystem_cache_log FAIL cidb, flaky
test_filesystem_cache/test.py::test_max_size_ratio FAIL cidb
test_filesystem_cache/test.py::test_finished_download_time FAIL cidb
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: FAIL cidb
BuzzHouse (arm_asan) failure
Logical error: 'Cannot fill arrow array bool with LowCardinality(Bool) data'. FAIL cidb
BuzzHouse (amd_msan) failure
Received signal 11 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-improvement Pull request with some product improvements label Sep 15, 2025
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch 3 times, most recently from 65dda1a to ef8ff3b Compare September 16, 2025 01:31
@tuanpach
tuanpach marked this pull request as ready for review September 16, 2025 06:32
@tavplubix tavplubix self-assigned this Sep 16, 2025
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch 3 times, most recently from 236807e to e4b7b3f Compare September 19, 2025 07:04
@tuanpach
tuanpach marked this pull request as draft September 19, 2025 10:26
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch 2 times, most recently from dddb311 to e7a6073 Compare September 20, 2025 13:04
@tuanpach
tuanpach marked this pull request as ready for review September 20, 2025 23:45
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch from 5b8320b to b57bba7 Compare September 25, 2025 02:05
@tuanpach
tuanpach marked this pull request as draft September 29, 2025 02:41
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch 7 times, most recently from 6fa0728 to a32abbb Compare October 3, 2025 10:11
@tuanpach
tuanpach marked this pull request as ready for review October 7, 2025 08:14
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch from a32abbb to 90e7d5a Compare October 13, 2025 04:30
@tuanpach tuanpach changed the title Decouple version logic from IMergeTreeDataPart Refactor VersionMetadata and decouple version logic from IMergeTreeDataPart Oct 13, 2025
@azat

azat commented Oct 17, 2025

Copy link
Copy Markdown
Member

Does this also supersedes #83349?

@tuanpach

Copy link
Copy Markdown
Member Author

Does this also supersedes #83349?

Yes, will close it

@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Dear @tavplubix, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

- Make VersionMetadata a base class.
- Create VersionMetadataOnDisk subclass inheriting from VersionMetadata and persisting metadata on a disk along with the data part.
- Move the logic of the old VersionMetadata to VersionMetadataOnDisk
- Move version logic from IMergeTreeDataPart to VersionMetadata and VersionMetadataOnDisk

Refactor changes:
- Move src/Interpreters/TransactionVersionMetadata.cpp, .h, -> src/Interpreters/MergeTreeTransaction/VersionMetadata.cpp, .h
- Make VersionMetadata a base class
- In VersionMetadata:
    - Separate the logic of storing removalTIDLock and removalTID.
    - Previously, removal_tid is set in tryLockRemovalTID, unlockRemovalTID. Then, stored in the metadata file with appendRemovalTIDToVersionMetadata(bool clear).
    - In this PR, lockRemovalTID and unlockRemovalTID only set the removal_tid_lock hash. removal_tid is set and stored in the stored data by storeRemovalTID.
    - Have new methods:
    - storeCreationCSN: set and store creation CSN
    - storeRemovalCSN: set and store removal CSN
    - storeRemovalTID: set and store removal TDI
    - loadAndVerifyMetadata: load and verify metadata stored in storage.
    - wasInvolvedInTransaction: check if the object was involved in a transaction
- In VersionMetadataOnDisk which inherits from VersionMetadata:
    - Check if the storage supports writing with Append:
    - If yes, store the info in append mode
    - If no, overwrite it with the complete new metadata.
    - If the object is not involved in any transaction, it might delay storing the data into storage. Previously, the check was done in VersionMetadata.
@tuanpach
tuanpach force-pushed the decouple-version-logic-from-merge-tree-data-part branch from 90e7d5a to 027645a Compare November 25, 2025 03:59
@tuanpach

Copy link
Copy Markdown
Member Author

Close this PR as there are too many force pushes. Created a new PR: #92141

@tuanpach tuanpach closed this Dec 15, 2025
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 pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants