// only called by rgw_shard_id and rgw_bucket_shard_index
static inline int rgw_shards_mod(unsigned hval, int max_shards)
{
- if (max_shards <= RGW_SHARDS_PRIME_0) {
+ if (max_shards <= 0) {
+ return -1;
+ } else if (max_shards <= RGW_SHARDS_PRIME_0) {
return hval % RGW_SHARDS_PRIME_0 % max_shards;
+ } else {
+ return hval % RGW_SHARDS_PRIME_1 % max_shards;
}
- return hval % RGW_SHARDS_PRIME_1 % max_shards;
}
// used for logging and tagging
cerr << "ERROR: num-shards and object must be specified."
<< std::endl;
return EINVAL;
+ } else if (num_shards <= 0) {
+ cerr << "ERROR: non-positive value supplied for num-shards: " <<
+ num_shards << std::endl;
+ return EINVAL;
}
- auto shard = RGWSI_BucketIndex_RADOS::bucket_shard_index(object, num_shards);
+ auto shard =
+ RGWSI_BucketIndex_RADOS::bucket_shard_index(object, num_shards);
formatter->open_object_section("obj_shard");
encode_json("shard", shard, formatter.get());
formatter->close_section();
return rgw_shard_id(key, max_shards);
}
- static uint32_t bucket_shard_index(const std::string& key,
- int num_shards) {
+ static int32_t bucket_shard_index(const std::string& key,
+ int num_shards) {
uint32_t sid = ceph_str_hash_linux(key.c_str(), key.size());
uint32_t sid2 = sid ^ ((sid & 0xFF) << 24);
return rgw_shards_mod(sid2, num_shards);
}
- static uint32_t bucket_shard_index(const rgw_obj_key& obj_key,
- int num_shards)
+ static int32_t bucket_shard_index(const rgw_obj_key& obj_key,
+ int num_shards)
{
std::string sharding_key;
if (obj_key.ns == RGW_OBJ_NS_MULTIPART) {