File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed
Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -62,10 +62,13 @@ inline int rgw_shards_max()
6262// only called by rgw_shard_id and rgw_bucket_shard_index
6363static inline int rgw_shards_mod (unsigned hval, int max_shards)
6464{
65- if (max_shards <= RGW_SHARDS_PRIME_0) {
65+ if (max_shards <= 0 ) {
66+ return -1 ;
67+ } else if (max_shards <= RGW_SHARDS_PRIME_0) {
6668 return hval % RGW_SHARDS_PRIME_0 % max_shards;
69+ } else {
70+ return hval % RGW_SHARDS_PRIME_1 % max_shards;
6771 }
68- return hval % RGW_SHARDS_PRIME_1 % max_shards;
6972}
7073
7174// used for logging and tagging
Original file line number Diff line number Diff line change @@ -7695,8 +7695,13 @@ int main(int argc, const char **argv)
76957695 cerr << " ERROR: num-shards and object must be specified."
76967696 << std::endl;
76977697 return EINVAL;
7698+ } else if (num_shards <= 0 ) {
7699+ cerr << " ERROR: non-positive value supplied for num-shards: " <<
7700+ num_shards << std::endl;
7701+ return EINVAL;
76987702 }
7699- auto shard = RGWSI_BucketIndex_RADOS::bucket_shard_index (object, num_shards);
7703+ auto shard =
7704+ RGWSI_BucketIndex_RADOS::bucket_shard_index (object, num_shards);
77007705 formatter->open_object_section (" obj_shard" );
77017706 encode_json (" shard" , shard, formatter.get ());
77027707 formatter->close_section ();
Original file line number Diff line number Diff line change @@ -100,15 +100,15 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
100100 return rgw_shard_id (key, max_shards);
101101 }
102102
103- static uint32_t bucket_shard_index (const std::string& key,
104- int num_shards) {
103+ static int32_t bucket_shard_index (const std::string& key,
104+ int num_shards) {
105105 uint32_t sid = ceph_str_hash_linux (key.c_str (), key.size ());
106106 uint32_t sid2 = sid ^ ((sid & 0xFF ) << 24 );
107107 return rgw_shards_mod (sid2, num_shards);
108108 }
109109
110- static uint32_t bucket_shard_index (const rgw_obj_key& obj_key,
111- int num_shards)
110+ static int32_t bucket_shard_index (const rgw_obj_key& obj_key,
111+ int num_shards)
112112 {
113113 std::string sharding_key;
114114 if (obj_key.ns == RGW_OBJ_NS_MULTIPART) {
You can’t perform that action at this time.
0 commit comments