2 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 // vim: ts=8 sw=2 smarttab ft=cpp
6 * Ceph - scalable distributed file system
8 * Copyright (C) 2019 Red Hat, Inc.
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.
20 #include "rgw/rgw_service.h"
21 #include "rgw/rgw_tools.h"
24 #include "svc_rados.h"
26 struct rgw_bucket_dir_header
;
28 class RGWSI_BILog_RADOS
;
29 class RGWSI_DataLog_RADOS
;
31 #define RGW_NO_SHARD -1
33 #define RGW_SHARDS_PRIME_0 7877
34 #define RGW_SHARDS_PRIME_1 65521
36 class RGWSI_BucketIndex_RADOS
: public RGWSI_BucketIndex
38 friend class RGWSI_BILog_RADOS
;
40 int open_pool(const rgw_pool
& pool
,
41 RGWSI_RADOS::Pool
*index_pool
,
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
);
50 void get_bucket_index_object(const string
& bucket_oid_base
,
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
);
58 int cls_bucket_head(const RGWBucketInfo
& bucket_info
,
60 vector
<rgw_bucket_dir_header
> *headers
,
61 map
<int, string
> *bucket_instance_ids
,
67 RGWSI_Zone
*zone
{nullptr};
68 RGWSI_RADOS
*rados
{nullptr};
69 RGWSI_BILog_RADOS
*bilog
{nullptr};
70 RGWSI_DataLog_RADOS
*datalog_rados
{nullptr};
73 RGWSI_BucketIndex_RADOS(CephContext
*cct
);
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
);
80 static int shards_max() {
81 return RGW_SHARDS_PRIME_1
;
84 static int shard_id(const string
& key
, int max_shards
) {
85 return rgw_shard_id(key
, max_shards
);
88 static uint32_t bucket_shard_index(const std::string
& key
,
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
);
95 int init_index(RGWBucketInfo
& bucket_info
);
96 int clean_index(RGWBucketInfo
& bucket_info
);
101 int read_stats(const RGWBucketInfo
& bucket_info
,
103 optional_yield y
) override
;
105 int get_reshard_status(const RGWBucketInfo
& bucket_info
,
106 std::list
<cls_rgw_bucket_instance_entry
> *status
);
108 int handle_overwrite(const RGWBucketInfo
& info
,
109 const RGWBucketInfo
& orig_info
) override
;
111 int open_bucket_index_shard(const RGWBucketInfo
& bucket_info
,
112 const string
& obj_key
,
113 RGWSI_RADOS::Obj
*bucket_obj
,
116 int open_bucket_index_shard(const RGWBucketInfo
& bucket_info
,
118 RGWSI_RADOS::Obj
*bucket_obj
);
120 int open_bucket_index(const RGWBucketInfo
& bucket_info
,
121 RGWSI_RADOS::Pool
*index_pool
,
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
);