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