Skip to content

Commit 37d50ec

Browse files
committed
generate transaction id instead of reusing the queryid
1 parent a736a6c commit 37d50ec

File tree

8 files changed

+88
-57
lines changed

8 files changed

+88
-57
lines changed

src/Functions/generateSnowflakeID.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ uint64_t generateSnowflakeID()
154154
return fromSnowflakeId(snowflake_id);
155155
}
156156

157+
std::string generateSnowflakeIDString()
158+
{
159+
return std::to_string(generateSnowflakeID());
160+
}
161+
157162
class FunctionGenerateSnowflakeID : public IFunction
158163
{
159164
public:

src/Functions/generateSnowflakeID.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ namespace DB
77

88
uint64_t generateSnowflakeID();
99

10+
std::string generateSnowflakeIDString();
11+
1012
}

src/Storages/MergeTree/ExportPartTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Priority ExportPartTask::getPriority() const
289289

290290
String ExportPartTask::getQueryId() const
291291
{
292-
return manifest.query_id;
292+
return manifest.transaction_id;
293293
}
294294

295295
}

src/Storages/MergeTree/MergeTreeData.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#include <Storages/MergeTree/LoadedMergeTreeDataPartInfoForReader.h>
103103
#include <QueryPipeline/QueryPipelineBuilder.h>
104104
#include <Storages/MergeTree/MergeTreeIndexGranularityAdaptive.h>
105+
#include <Functions/generateSnowflakeID.h>
105106

106107
#include <boost/algorithm/string/join.hpp>
107108

@@ -6212,7 +6213,7 @@ void MergeTreeData::exportPartToTable(const PartitionCommand & command, ContextP
62126213

62136214
const auto database_name = query_context->resolveDatabase(command.to_database);
62146215

6215-
exportPartToTable(part_name, StorageID{database_name, command.to_table}, query_context->getCurrentQueryId(), query_context);
6216+
exportPartToTable(part_name, StorageID{database_name, command.to_table}, generateSnowflakeIDString(), query_context);
62166217
}
62176218

62186219
void MergeTreeData::exportPartToTable(
@@ -6275,13 +6276,13 @@ void MergeTreeData::exportPartToTable(
62756276
background_moves_assignee.trigger();
62766277
}
62776278

6278-
void MergeTreeData::killExportPart(const String & query_id)
6279+
void MergeTreeData::killExportPart(const String & transaction_id)
62796280
{
62806281
std::lock_guard lock(export_manifests_mutex);
62816282

62826283
std::erase_if(export_manifests, [&](const auto & manifest)
62836284
{
6284-
if (manifest.query_id == query_id)
6285+
if (manifest.transaction_id == transaction_id)
62856286
{
62866287
if (manifest.task)
62876288
manifest.task->cancel();

src/Storages/MergeTree/MergeTreeData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ class MergeTreeData : public IStorage, public WithMutableContext
991991
ContextPtr query_context,
992992
std::function<void(MergeTreePartExportManifest::CompletionCallbackResult)> completion_callback = {});
993993

994-
void killExportPart(const String & query_id);
994+
void killExportPart(const String & transaction_id);
995995

996996
virtual void exportPartitionToTable(const PartitionCommand &, ContextPtr)
997997
{

src/Storages/MergeTree/MergeTreePartExportManifest.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ struct MergeTreePartExportManifest
4343
MergeTreePartExportManifest(
4444
const StorageID & destination_storage_id_,
4545
const DataPartPtr & data_part_,
46-
const String & query_id_,
46+
const String & transaction_id_,
4747
FileAlreadyExistsPolicy file_already_exists_policy_,
4848
bool parallel_formatting_,
4949
bool parquet_parallel_encoding_,
5050
std::size_t max_threads_,
5151
std::function<void(CompletionCallbackResult)> completion_callback_ = {})
5252
: destination_storage_id(destination_storage_id_),
5353
data_part(data_part_),
54-
query_id(query_id_),
54+
transaction_id(transaction_id_),
5555
file_already_exists_policy(file_already_exists_policy_),
5656
parallel_formatting(parallel_formatting_),
5757
parquet_parallel_encoding(parquet_parallel_encoding_),
@@ -62,7 +62,7 @@ struct MergeTreePartExportManifest
6262
StorageID destination_storage_id;
6363
DataPartPtr data_part;
6464
/// Used for killing the export.
65-
String query_id;
65+
String transaction_id;
6666
FileAlreadyExistsPolicy file_already_exists_policy;
6767
bool parallel_formatting;
6868
/// parquet has a different setting for parallel formatting

src/Storages/StorageReplicatedMergeTree.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
#include <Backups/RestorerFromBackup.h>
119119

120120
#include <Common/scope_guard_safe.h>
121+
#include "Functions/generateSnowflakeID.h"
121122
#include "Interpreters/StorageID.h"
122123
#include "QueryPipeline/QueryPlanResourceHolder.h"
123124
#include "Storages/ExportReplicatedMergeTreePartitionManifest.h"
@@ -8191,7 +8192,7 @@ void StorageReplicatedMergeTree::exportPartitionToTable(const PartitionCommand &
81918192

81928193
ExportReplicatedMergeTreePartitionManifest manifest;
81938194

8194-
manifest.transaction_id = query_context->getCurrentQueryId();
8195+
manifest.transaction_id = generateSnowflakeIDString();
81958196
manifest.partition_id = partition_id;
81968197
manifest.destination_database = dest_database;
81978198
manifest.destination_table = dest_table;

0 commit comments

Comments
 (0)