| 32 | } |
| 33 | |
| 34 | UUID 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 | |
| 77 | void ServerUUID::set(UUID & uuid) |
| 78 | { |
no test coverage detected