static string gc_index_lock_name = "gc_process";
-#define HASH_PRIME 7877
-
void RGWGC::initialize(CephContext *_cct, RGWRados *_store) {
cct = _cct;
store = _store;
- max_objs = cct->_conf->rgw_gc_max_objs;
- if (max_objs > HASH_PRIME)
- max_objs = HASH_PRIME;
+ max_objs = min(cct->_conf->rgw_gc_max_objs, rgw_shards_max());
obj_names = new string[max_objs];
int RGWGC::tag_index(const string& tag)
{
- return ceph_str_hash_linux(tag.c_str(), tag.size()) % HASH_PRIME % max_objs;
+ return rgw_shards_hash(tag, max_objs);
}
void RGWGC::add_chain(ObjectWriteOperation& op, cls_rgw_obj_chain& chain, const string& tag)
bucket_index_max_shards = (cct->_conf->rgw_override_bucket_index_max_shards ? cct->_conf->rgw_override_bucket_index_max_shards :
get_zone().bucket_index_max_shards);
- if (bucket_index_max_shards > MAX_BUCKET_INDEX_SHARDS_PRIME) {
- bucket_index_max_shards = MAX_BUCKET_INDEX_SHARDS_PRIME;
+ if (bucket_index_max_shards > get_max_bucket_shards()) {
+ bucket_index_max_shards = get_max_bucket_shards();
ldout(cct, 1) << __func__ << " bucket index max shards is too large, reset to value: "
- << MAX_BUCKET_INDEX_SHARDS_PRIME << dendl;
+ << get_max_bucket_shards() << dendl;
}
ldout(cct, 20) << __func__ << " bucket index max shards: " << bucket_index_max_shards << dendl;
return 0;
}
-#define MAX_SHARDS_PRIME 7877
-
int RGWRados::key_to_shard_id(const string& key, int max_shards)
{
- uint32_t val = ceph_str_hash_linux(key.c_str(), key.size()) % MAX_SHARDS_PRIME;
- return val % max_shards;
+ return rgw_shards_hash(key, max_shards);
}
void RGWRados::shard_name(const string& prefix, unsigned max_shards, const string& key, string& name, int *shard_id)
return objname + buf;
}
-#define MAX_OBJEXP_SHARDS_PRIME 7877
-
int RGWRados::objexp_key_shard(const rgw_obj_index_key& key)
{
string obj_key = key.name + key.instance;
int num_shards = cct->_conf->rgw_objexp_hints_num_shards;
uint32_t sid = ceph_str_hash_linux(obj_key.c_str(), obj_key.size());
uint32_t sid2 = sid ^ ((sid & 0xFF) << 24);
- sid = sid2 % MAX_OBJEXP_SHARDS_PRIME % num_shards;
- return sid % num_shards;
+ sid = rgw_shards_mod(sid2, num_shards);
+ return sid;
}
static string objexp_hint_get_keyext(const string& tenant_name,
} else {
uint32_t sid = ceph_str_hash_linux(obj_key.c_str(), obj_key.size());
uint32_t sid2 = sid ^ ((sid & 0xFF) << 24);
- sid = sid2 % MAX_BUCKET_INDEX_SHARDS_PRIME % bucket_info.num_shards;
+ sid = rgw_shards_mod(sid2, bucket_info.num_shards);
if (shard_id) {
*shard_id = (int)sid;
}
} else {
uint32_t sid = ceph_str_hash_linux(obj_key.c_str(), obj_key.size());
uint32_t sid2 = sid ^ ((sid & 0xFF) << 24);
- sid = sid2 % MAX_BUCKET_INDEX_SHARDS_PRIME % num_shards;
+ sid = rgw_shards_mod(sid2, num_shards);
char buf[bucket_oid_base.size() + 32];
snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid);
(*bucket_obj) = buf;
#define RGW_NO_SHARD -1
-#define MAX_BUCKET_INDEX_SHARDS_PRIME 7877
+#define RGW_SHARDS_PRIME_0 7877
+#define RGW_SHARDS_PRIME_1 65521
+
+static inline int rgw_shards_mod(unsigned hval, int max_shards)
+{
+ if (max_shards <= RGW_SHARDS_PRIME_0) {
+ return hval % RGW_SHARDS_PRIME_0 % max_shards;
+ }
+ return hval % RGW_SHARDS_PRIME_1 % max_shards;
+}
+
+static inline int rgw_shards_hash(const string& key, int max_shards)
+{
+ return rgw_shards_mod(ceph_str_hash_linux(key.c_str(), key.size()), max_shards);
+}
+
+static inline int rgw_shards_max()
+{
+ return RGW_SHARDS_PRIME_1;
+}
static inline void prepend_bucket_marker(const rgw_bucket& bucket, const string& orig_oid, string& oid)
{
int get_max_chunk_size(const string& placement_rule, const rgw_obj& obj, uint64_t *max_chunk_size);
uint32_t get_max_bucket_shards() {
- return MAX_BUCKET_INDEX_SHARDS_PRIME;
+ return rgw_shards_max();
}
int get_raw_obj_ref(const rgw_raw_obj& obj, rgw_rados_ref *ref, rgw_pool *pool = NULL);