GetValueForWrite函数写入多阶Hash表操作可能有误
wayland-chen opened this issue · comments
问题在如下注释:
`int MultiHashBase<Key, Value>::GetValueForWrite(const KeyType &input_key,
ValueType *&value) {
int ret = enMultiHashBucketFull;
ValueType * read_value_ptr;
ret = GetValueForRead(input_key, read_value_ptr);
if (ret == enMultiHashOK) {
value = read_value_ptr;
AfterFindWriteItem(*value);
return ret;
}
size_t offset = 0;
unsigned int find_level = 0;
ret = enMultiHashBucketFull;
size_t hash_key = HashKey(input_key);
for (find_level = 0; find_level < max_level_; find_level++) {
size_t index = hash_key % size_meta_[find_level];
KeyType* key_in_mem =
reinterpret_cast<KeyType >(shm_mem_base_ + offset + (item_size_ * index));
ValueType value_in_mem = reinterpret_cast<ValueType *>(
reinterpret_cast<char *>(key_in_mem) + sizeof(KeyType));
uint32_t timestamp = 0;
if (IsEmpty(*key_in_mem, *value_in_mem) == true) {
if (EmptyOccupy(input_key, *key_in_mem) == true) {
memset(reinterpret_cast<void *>(value_in_mem), 0 , sizeof(ValueType));
ret = enMultiHashOK;
value = value_in_mem;
break;
}
continue;
//不能占据位置时,continue会跳到下一层的level, 但offset没有更新计算, 这个continue会不会有问题?
} else if (IsExpired(*key_in_mem, *value_in_mem, ×tamp) == true) {
if (ExpiredOccupy(input_key, *key_in_mem, *value_in_mem, ×tamp) == true) {
memset(reinterpret_cast<void *>(value_in_mem), 0 , sizeof(ValueType));
ret = enMultiHashOK;
value = value_in_mem;
break;
}
continue;
//不能占据位置时,continue会跳到下一层的level, 但offset没有更新计算, 这个continue会不会有问题?
}
offset += size_meta_[find_level] * item_size_;
}
if (ret == enMultiHashOK) {
gLog("[%s][%d]: level %d hash %llu\n", FILE, LINE,
find_level, hash_key);
} else {
gLog("[%s][%d]: not found hash %llu\n", FILE, LINE, hash_key);
}
return ret;
}`
谢谢!问题确实存在。
感谢wayland-chen