Skip to content

Commit 8d46a90

Browse files
authored
Merge pull request ClickHouse#78792 from evillique/fix-assert-s3queue
Fix assert in S3Queue
2 parents c68aaca + b172cb4 commit 8d46a90

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Storages/ObjectStorageQueue/ObjectStorageQueueMetadata.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <Common/randomSeed.h>
2020
#include <Common/DNSResolver.h>
2121
#include <shared_mutex>
22+
#include <Core/ServerUUID.h>
2223

2324

2425
namespace ProfileEvents
@@ -505,17 +506,22 @@ namespace
505506
{
506507
std::string hostname;
507508
std::string table_id;
509+
std::string server_uuid;
510+
511+
size_t version = 1;
508512

509513
bool operator ==(const Info & other) const
510514
{
511-
return hostname == other.hostname && table_id == other.table_id;
515+
return hostname == other.hostname && table_id == other.table_id
516+
&& (version == 0 || other.version == 0 || server_uuid == other.server_uuid);
512517
}
513518

514519
static Info create(const StorageID & storage_id)
515520
{
516521
Info self;
517522
self.hostname = DNSResolver::instance().getHostName();
518523
self.table_id = storage_id.hasUUID() ? toString(storage_id.uuid) : storage_id.getFullTableName();
524+
self.server_uuid = toString(ServerUUID::get());
519525
return self;
520526
}
521527

@@ -524,27 +530,30 @@ namespace
524530
SipHash hash;
525531
hash.update(hostname);
526532
hash.update(table_id);
533+
hash.update(server_uuid);
527534
return hash.get128();
528535
}
529536

530537
std::string serialize() const
531538
{
532539
WriteBufferFromOwnString buf;
533-
size_t version = 0;
534540
buf << version << "\n";
535541
buf << hostname << "\n";
536542
buf << table_id << "\n";
543+
if (version >= 1)
544+
buf << server_uuid << "\n";
537545
return buf.str();
538546
}
539547

540548
static Info deserialize(const std::string & str)
541549
{
542550
ReadBufferFromString buf(str);
543551
Info info;
544-
size_t version;
545-
buf >> version >> "\n";
552+
buf >> info.version >> "\n";
546553
buf >> info.hostname >> "\n";
547554
buf >> info.table_id >> "\n";
555+
if (info.version >= 1)
556+
buf >> info.server_uuid >> "\n";
548557
return info;
549558
}
550559
};

tests/integration/test_storage_s3_queue/test_4.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ def test_registry(started_cluster):
582582
).strip()
583583
assert uuid1 in str(registry)
584584

585-
expected = [f"0\\ninstance\\n{uuid1}\\n", f"0\\ninstance2\\n{uuid1}\\n"]
585+
server_uuid_1 = node1.query("SELECT serverUUID()").strip()
586+
server_uuid_2 = node2.query("SELECT serverUUID()").strip()
587+
588+
expected = [f"1\\ninstance\\n{uuid1}\\n{server_uuid_1}\\n", f"1\\ninstance2\\n{uuid1}\\n{server_uuid_2}\\n"]
586589

587590
for elem in expected:
588591
assert elem in str(registry)
@@ -637,10 +640,10 @@ def get_count():
637640
assert uuid2 in str(registry)
638641

639642
expected = [
640-
f"0\\ninstance\\n{uuid1}\\n",
641-
f"0\\ninstance2\\n{uuid1}\\n",
642-
f"0\\ninstance\\n{uuid2}\\n",
643-
f"0\\ninstance2\\n{uuid2}\\n",
643+
f"1\\ninstance\\n{uuid1}\\n{server_uuid_1}\\n",
644+
f"1\\ninstance2\\n{uuid1}\\n{server_uuid_2}\\n",
645+
f"1\\ninstance\\n{uuid2}\\n{server_uuid_1}\\n",
646+
f"1\\ninstance2\\n{uuid2}\\n{server_uuid_2}\\n",
644647
]
645648

646649
for elem in expected:
@@ -663,8 +666,8 @@ def get_count():
663666
assert uuid2 not in str(registry)
664667

665668
expected = [
666-
f"0\\ninstance\\n{uuid1}\\n",
667-
f"0\\ninstance2\\n{uuid1}\\n",
669+
f"1\\ninstance\\n{uuid1}\\n{server_uuid_1}\\n",
670+
f"1\\ninstance2\\n{uuid1}\\n{server_uuid_2}\\n",
668671
]
669672

670673
for elem in expected:

0 commit comments

Comments
 (0)