MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / loadServerUUID

Function loadServerUUID

src/Core/ServerUUID.cpp:34–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34UUID loadServerUUID(const fs::path & server_uuid_file, Poco::Logger * log)
35{
36 /// Write a uuid file containing a unique uuid if the file doesn't already exist during server start.
37
38 if (fs::exists(server_uuid_file))
39 {
40 try
41 {
42 UUID uuid;
43 ReadBufferFromFile in(server_uuid_file);
44 readUUIDText(uuid, in);
45 assertEOF(in);
46 return uuid;
47 }
48 catch (...)
49 {
50 /// As for now it's ok to just overwrite it, because persistency in not essential.
51 LOG_ERROR(log, "Cannot read server UUID from file {}: {}. Will overwrite it",
52 server_uuid_file.string(), getCurrentExceptionMessage(true));
53 }
54 }
55
56 try
57 {
58 UUID new_uuid = UUIDHelpers::generateV4();
59 auto uuid_str = toString(new_uuid);
60 WriteBufferFromFile out(server_uuid_file);
61 out.write(uuid_str.data(), uuid_str.size());
62 out.sync();
63 out.finalize();
64 return new_uuid;
65 }
66 catch (ErrnoException &)
67 {
68 throw;
69 }
70 catch (...)
71 {
72 throw Exception(ErrorCodes::CANNOT_CREATE_FILE, "Caught Exception {} while writing the Server UUID file {}",
73 getCurrentExceptionMessage(false), server_uuid_file.string());
74 }
75}
76
77void ServerUUID::set(UUID & uuid)
78{

Callers 1

loadMethod · 0.85

Calls 13

readUUIDTextFunction · 0.85
assertEOFFunction · 0.85
generateV4Function · 0.85
toStringFunction · 0.70
existsFunction · 0.50
ExceptionClass · 0.50
stringMethod · 0.45
writeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected