]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
11fdf7f2 TL |
4 | #include "svc_zone_utils.h" |
5 | #include "svc_rados.h" | |
6 | #include "svc_zone.h" | |
7 | ||
1e59de90 | 8 | #include "rgw_zone.h" |
11fdf7f2 | 9 | |
20effc67 TL |
10 | using namespace std; |
11 | ||
b3b6e05e | 12 | int RGWSI_ZoneUtils::do_start(optional_yield, const DoutPrefixProvider *dpp) |
11fdf7f2 TL |
13 | { |
14 | init_unique_trans_id_deps(); | |
15 | ||
16 | return 0; | |
17 | } | |
18 | ||
19 | string RGWSI_ZoneUtils::gen_host_id() { | |
20 | /* uint64_t needs 16, two '-' separators and a trailing null */ | |
21 | const string& zone_name = zone_svc->get_zone().name; | |
22 | const string& zonegroup_name = zone_svc->get_zonegroup().get_name(); | |
23 | char charbuf[16 + zone_name.size() + zonegroup_name.size() + 2 + 1]; | |
24 | snprintf(charbuf, sizeof(charbuf), "%llx-%s-%s", (unsigned long long)rados_svc->instance_id(), zone_name.c_str(), zonegroup_name.c_str()); | |
25 | return string(charbuf); | |
26 | } | |
27 | ||
28 | string RGWSI_ZoneUtils::unique_id(uint64_t unique_num) | |
29 | { | |
30 | char buf[32]; | |
31 | snprintf(buf, sizeof(buf), ".%llu.%llu", (unsigned long long)rados_svc->instance_id(), (unsigned long long)unique_num); | |
32 | string s = zone_svc->get_zone_params().get_id() + buf; | |
33 | return s; | |
34 | } | |
35 | ||
36 | void RGWSI_ZoneUtils::init_unique_trans_id_deps() { | |
37 | char buf[16 + 2 + 1]; /* uint64_t needs 16, 2 hyphens add further 2 */ | |
38 | ||
39 | snprintf(buf, sizeof(buf), "-%llx-", (unsigned long long)rados_svc->instance_id()); | |
40 | url_encode(string(buf) + zone_svc->get_zone().name, trans_id_suffix); | |
41 | } | |
42 | ||
43 | /* In order to preserve compatibility with Swift API, transaction ID | |
44 | * should contain at least 32 characters satisfying following spec: | |
45 | * - first 21 chars must be in range [0-9a-f]. Swift uses this | |
46 | * space for storing fragment of UUID obtained through a call to | |
47 | * uuid4() function of Python's uuid module; | |
48 | * - char no. 22 must be a hyphen; | |
49 | * - at least 10 next characters constitute hex-formatted timestamp | |
50 | * padded with zeroes if necessary. All bytes must be in [0-9a-f] | |
51 | * range; | |
52 | * - last, optional part of transaction ID is any url-encoded string | |
53 | * without restriction on length. */ | |
54 | string RGWSI_ZoneUtils::unique_trans_id(const uint64_t unique_num) { | |
55 | char buf[41]; /* 2 + 21 + 1 + 16 (timestamp can consume up to 16) + 1 */ | |
56 | time_t timestamp = time(NULL); | |
57 | ||
58 | snprintf(buf, sizeof(buf), "tx%021llx-%010llx", | |
59 | (unsigned long long)unique_num, | |
60 | (unsigned long long)timestamp); | |
61 | ||
62 | return string(buf) + trans_id_suffix; | |
63 | } | |
64 |