]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_zone_utils.cc
712bb97c9ba3ff0680055dd58efe5a3b743b8f2d
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include "svc_zone_utils.h"
12 int RGWSI_ZoneUtils::do_start(optional_yield
, const DoutPrefixProvider
*dpp
)
14 init_unique_trans_id_deps();
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
);
28 string
RGWSI_ZoneUtils::unique_id(uint64_t unique_num
)
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
;
36 void RGWSI_ZoneUtils::init_unique_trans_id_deps() {
37 char buf
[16 + 2 + 1]; /* uint64_t needs 16, 2 hyphens add further 2 */
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
);
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]
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
);
58 snprintf(buf
, sizeof(buf
), "tx%021llx-%010llx",
59 (unsigned long long)unique_num
,
60 (unsigned long long)timestamp
);
62 return string(buf
) + trans_id_suffix
;