]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_bi_rados.h
d59d3606a96ff2d2174509921eadc1403eb4a8c2
[ceph.git] / ceph / src / rgw / services / svc_bi_rados.h
1
2 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 // vim: ts=8 sw=2 smarttab ft=cpp
4
5 /*
6 * Ceph - scalable distributed file system
7 *
8 * Copyright (C) 2019 Red Hat, Inc.
9 *
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
14 *
15 */
16
17
18 #pragma once
19
20 #include "rgw/rgw_service.h"
21 #include "rgw/rgw_tools.h"
22
23 #include "svc_bi.h"
24 #include "svc_rados.h"
25
26 struct rgw_bucket_dir_header;
27
28 class RGWSI_BILog_RADOS;
29 class RGWSI_DataLog_RADOS;
30
31 #define RGW_NO_SHARD -1
32
33 #define RGW_SHARDS_PRIME_0 7877
34 #define RGW_SHARDS_PRIME_1 65521
35
36 class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
37 {
38 friend class RGWSI_BILog_RADOS;
39
40 int open_pool(const rgw_pool& pool,
41 RGWSI_RADOS::Pool *index_pool,
42 bool mostly_omap);
43
44 int open_bucket_index_pool(const RGWBucketInfo& bucket_info,
45 RGWSI_RADOS::Pool *index_pool);
46 int open_bucket_index_base(const RGWBucketInfo& bucket_info,
47 RGWSI_RADOS::Pool *index_pool,
48 string *bucket_oid_base);
49
50 void get_bucket_index_object(const string& bucket_oid_base,
51 uint32_t num_shards,
52 int shard_id,
53 string *bucket_obj);
54 int get_bucket_index_object(const string& bucket_oid_base, const string& obj_key,
55 uint32_t num_shards, RGWBucketInfo::BIShardsHashType hash_type,
56 string *bucket_obj, int *shard_id);
57
58 int cls_bucket_head(const RGWBucketInfo& bucket_info,
59 int shard_id,
60 vector<rgw_bucket_dir_header> *headers,
61 map<int, string> *bucket_instance_ids,
62 optional_yield y);
63
64 public:
65
66 struct Svc {
67 RGWSI_Zone *zone{nullptr};
68 RGWSI_RADOS *rados{nullptr};
69 RGWSI_BILog_RADOS *bilog{nullptr};
70 RGWSI_DataLog_RADOS *datalog_rados{nullptr};
71 } svc;
72
73 RGWSI_BucketIndex_RADOS(CephContext *cct);
74
75 void init(RGWSI_Zone *zone_svc,
76 RGWSI_RADOS *rados_svc,
77 RGWSI_BILog_RADOS *bilog_svc,
78 RGWSI_DataLog_RADOS *datalog_rados_svc);
79
80 static int shards_max() {
81 return RGW_SHARDS_PRIME_1;
82 }
83
84 static int shard_id(const string& key, int max_shards) {
85 return rgw_shard_id(key, max_shards);
86 }
87
88 static uint32_t bucket_shard_index(const std::string& key,
89 int num_shards) {
90 uint32_t sid = ceph_str_hash_linux(key.c_str(), key.size());
91 uint32_t sid2 = sid ^ ((sid & 0xFF) << 24);
92 return rgw_shards_mod(sid2, num_shards);
93 }
94
95 int init_index(RGWBucketInfo& bucket_info);
96 int clean_index(RGWBucketInfo& bucket_info);
97
98
99 /* RADOS specific */
100
101 int read_stats(const RGWBucketInfo& bucket_info,
102 RGWBucketEnt *stats,
103 optional_yield y) override;
104
105 int get_reshard_status(const RGWBucketInfo& bucket_info,
106 std::list<cls_rgw_bucket_instance_entry> *status);
107
108 int handle_overwrite(const RGWBucketInfo& info,
109 const RGWBucketInfo& orig_info) override;
110
111 int open_bucket_index_shard(const RGWBucketInfo& bucket_info,
112 const string& obj_key,
113 RGWSI_RADOS::Obj *bucket_obj,
114 int *shard_id);
115
116 int open_bucket_index_shard(const RGWBucketInfo& bucket_info,
117 int shard_id,
118 RGWSI_RADOS::Obj *bucket_obj);
119
120 int open_bucket_index(const RGWBucketInfo& bucket_info,
121 RGWSI_RADOS::Pool *index_pool,
122 string *bucket_oid);
123
124 int open_bucket_index(const RGWBucketInfo& bucket_info,
125 std::optional<int> shard_id,
126 RGWSI_RADOS::Pool *index_pool,
127 map<int, string> *bucket_objs,
128 map<int, string> *bucket_instance_ids);
129 };
130
131