fix restore kv cache miss issue

This commit is contained in:
oceanoverflow 2024-10-14 07:43:37 +00:00 committed by ob-robot
parent 26aac467fc
commit e89c7eb011
6 changed files with 43 additions and 20 deletions

View File

@ -272,6 +272,8 @@ STAT_EVENT_ADD_DEF(DATA_BLOCK_CACHE_MISS, "data block cache miss", ObStatClassId
STAT_EVENT_ADD_DEF(INDEX_BLOCK_CACHE_MISS, "index block cache miss", ObStatClassIds::CACHE, 50068, true, true, true)
STAT_EVENT_ADD_DEF(MULTI_VERSION_FUSE_ROW_CACHE_HIT, "multi version fuse row cache hit", ObStatClassIds::CACHE, 50069, true, true, true)
STAT_EVENT_ADD_DEF(MULTI_VERSION_FUSE_ROW_CACHE_MISS, "multi version fuse row cache miss", ObStatClassIds::CACHE, 50070, true, true, true)
STAT_EVENT_ADD_DEF(BACKUP_INDEX_CACHE_HIT, "backup index cache hit", ObStatClassIds::CACHE, 50071, true, true, true)
STAT_EVENT_ADD_DEF(BACKUP_INDEX_CACHE_MISS, "backup index cache miss", ObStatClassIds::CACHE, 50072, true, true, true)
// STORAGE
STAT_EVENT_ADD_DEF(MEMSTORE_LOGICAL_READS, "MEMSTORE_LOGICAL_READS", STORAGE, "MEMSTORE_LOGICAL_READS", true, true, false)

View File

@ -205,6 +205,8 @@ int ObInfoSchemaKvCacheTable::set_diagnose_info(ObKVCacheInst *inst, ObDiagnoseT
inst->status_.total_miss_cnt_ = GLOBAL_EVENT_GET(ObStatEventIds::TABLET_CACHE_MISS);
} else if (0 == strcmp(inst->status_.config_->cache_name_,"storage_meta_cache")) {
inst->status_.total_miss_cnt_ = GLOBAL_EVENT_GET(ObStatEventIds::STORAGE_META_CACHE_MISS);
} else if (0 == strcmp(inst->status_.config_->cache_name_,"BACKUP_INDEX_CACHE")) {
inst->status_.total_miss_cnt_ = GLOBAL_EVENT_GET(ObStatEventIds::BACKUP_INDEX_CACHE_MISS);
}
return ret;

View File

@ -57,6 +57,18 @@ bool ObBackupBlockDesc::operator==(const ObBackupBlockDesc &other) const
file_id_ == other.file_id_ && offset_ == other.offset_ && length_ == other.length_;
}
uint64_t ObBackupBlockDesc::calc_hash(uint64_t seed) const
{
uint64_t hash_code = 0;
hash_code = murmurhash(&turn_id_, sizeof(turn_id_), seed);
hash_code = murmurhash(&retry_id_, sizeof(retry_id_), hash_code);
hash_code = murmurhash(&file_type_, sizeof(file_type_), hash_code);
hash_code = murmurhash(&file_id_, sizeof(file_id_), hash_code);
hash_code = murmurhash(&offset_, sizeof(offset_), hash_code);
hash_code = murmurhash(&length_, sizeof(length_), hash_code);
return hash_code;
}
/* ObBackupIndexCacheKey */
ObBackupIndexCacheKey::ObBackupIndexCacheKey()
@ -111,7 +123,12 @@ uint64_t ObBackupIndexCacheKey::get_tenant_id() const
uint64_t ObBackupIndexCacheKey::hash() const
{
return murmurhash(this, sizeof(ObBackupIndexCacheKey), 0);
uint64_t hash_code = 0;
hash_code = murmurhash(&tenant_id_, sizeof(tenant_id_), hash_code);
hash_code = murmurhash(&backup_set_id_, sizeof(backup_set_id_), hash_code);
hash_code = murmurhash(&ls_id_, sizeof(ls_id_), hash_code);
hash_code = block_desc_.calc_hash(hash_code);
return hash_code;
}
int64_t ObBackupIndexCacheKey::size() const

View File

@ -28,6 +28,7 @@ struct ObBackupBlockDesc {
const int64_t offset, const int64_t length);
bool is_valid() const;
bool operator==(const ObBackupBlockDesc &other) const;
uint64_t calc_hash(uint64_t seed) const;
TO_STRING_KV(K_(turn_id), K_(retry_id), K_(file_type), K_(file_id), K_(offset), K_(length));
int64_t turn_id_;
int64_t retry_id_;

View File

@ -196,13 +196,11 @@ int ObIBackupIndexStore::decode_index_from_block_(const int64_t data_zlength, co
}
int ObIBackupIndexStore::fetch_block_(const ObBackupFileType &backup_file_type, const int64_t offset,
const int64_t length, common::ObIAllocator &allocator, blocksstable::ObBufferReader &buffer_reader)
const int64_t length, common::ObIAllocator &allocator, ObKVCacheHandle &handle, blocksstable::ObBufferReader &buffer_reader)
{
int ret = OB_SUCCESS;
ObBackupIndexCacheKey key;
const ObBackupIndexCacheValue *pvalue = NULL;
ObKVCacheHandle handle;
char *buf = NULL;
if (offset < 0 || length <= 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("get invalid args", K(ret), K(offset), K(length));
@ -213,6 +211,7 @@ int ObIBackupIndexStore::fetch_block_(const ObBackupFileType &backup_file_type,
LOG_WARN("failed to get backup index cache key", K(ret), K(backup_file_type), K(offset), K(length));
} else if (OB_FAIL(index_kv_cache_->get(key, pvalue, handle))) {
if (OB_ENTRY_NOT_EXIST == ret) {
EVENT_INC(ObStatEventIds::BACKUP_INDEX_CACHE_MISS);
ret = OB_SUCCESS;
if (OB_FAIL(do_on_cache_miss_(backup_file_type, offset, length, allocator, buffer_reader))) {
LOG_WARN("failed to do on cache miss", K(ret), K(backup_file_type), K(offset), K(length));
@ -227,13 +226,9 @@ int ObIBackupIndexStore::fetch_block_(const ObBackupFileType &backup_file_type,
} else if (OB_ISNULL(pvalue)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("cache value should not be null", K(ret));
} else if (OB_ISNULL(buf = static_cast<char *>(allocator.alloc(pvalue->len())))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to allocate memory", K(ret), K(*pvalue));
} else {
// TODO(yangyi.yyy): refine this method, remove the need of memory copying in 4.1
MEMCPY(buf, pvalue->buf(), pvalue->len());
buffer_reader.assign(buf, pvalue->len());
buffer_reader.assign(pvalue->buf(), pvalue->len());
EVENT_INC(ObStatEventIds::BACKUP_INDEX_CACHE_HIT);
}
return ret;
}
@ -482,20 +477,23 @@ int ObBackupMetaIndexStore::get_tablet_meta_index_(const ObBackupMetaKey &meta_k
} else if (OB_FAIL(meta_key.get_backup_index_file_type(backup_file_type))) {
LOG_WARN("failed to get backup index file type", K(ret), K(meta_key));
} else {
ObKVCacheHandle handle;
ObBackupMetaIndex index;
ObArray<ObBackupMetaIndex> index_list;
ObBackupMetaIndexIndex index_index;
ObArray<ObBackupMetaIndexIndex> index_index_list;
while (OB_SUCC(ret)) {
buffer_reader.assign(NULL, 0);
handle.reset();
allocator.reuse();
index_index.reset();
index_index_list.reset();
buffer_reader.assign(NULL, 0);
ObBackupCommonHeader common_header;
ObBackupMultiLevelIndexHeader index_header;
int64_t data_length = 0;
int64_t data_zlength = 0;
ObCompressorType compressor_type = ObCompressorType::INVALID_COMPRESSOR;
if (OB_FAIL(fetch_block_(backup_file_type, offset, length, allocator, buffer_reader))) {
if (OB_FAIL(fetch_block_(backup_file_type, offset, length, allocator, handle, buffer_reader))) {
LOG_WARN("failed to get block from cache", K(ret), K(backup_file_type), K(offset), K(length));
} else if (OB_FAIL(decode_headers_(buffer_reader, common_header,
index_header, data_length, data_zlength, compressor_type))) {
@ -520,7 +518,6 @@ int ObBackupMetaIndexStore::get_tablet_meta_index_(const ObBackupMetaKey &meta_k
offset = index_index.offset_;
length = index_index.length_;
LOG_DEBUG("find tablet meta index index", K(meta_key), K(index_index), K(index_index_list));
allocator.reuse();
}
}
}
@ -780,17 +777,20 @@ int ObBackupMacroBlockIndexStore::inner_get_macro_block_range_index_(
ObArray<ObBackupMacroRangeIndex> index_list;
ObBackupMacroRangeIndexIndex index_index;
ObArray<ObBackupMacroRangeIndexIndex> index_index_list;
ObKVCacheHandle handle;
int64_t round = 0;
while (OB_SUCC(ret)) {
buffer_reader.assign(NULL, 0);
handle.reset();
allocator.reuse();
index_index.reset();
index_index_list.reset();
buffer_reader.assign(NULL, 0);
ObBackupCommonHeader common_header;
ObBackupMultiLevelIndexHeader index_header;
int64_t data_length = 0;
int64_t data_zlength = 0;
ObCompressorType compressor_type = ObCompressorType::INVALID_COMPRESSOR;
if (OB_FAIL(fetch_block_(backup_file_type, offset, length, allocator, buffer_reader))) {
if (OB_FAIL(fetch_block_(backup_file_type, offset, length, allocator, handle, buffer_reader))) {
LOG_WARN("failed to fetch block", K(ret), K(offset), K(length));
} else if (OB_FAIL(decode_headers_(buffer_reader, common_header, index_header, data_length, data_zlength, compressor_type))) {
LOG_WARN("failed to decode header", K(ret), K(offset), K(length), K(buffer_reader));
@ -812,7 +812,6 @@ int ObBackupMacroBlockIndexStore::inner_get_macro_block_range_index_(
} else {
offset = index_index.offset_;
length = index_index.length_;
allocator.reuse();
}
}
}
@ -1542,18 +1541,21 @@ int ObBackupOrderedMacroBlockIndexStore::get_macro_block_index(
} else {
ObBackupCommonHeader common_header;
ObBackupMultiLevelIndexHeader index_header;
ObKVCacheHandle handle;
while (OB_SUCC(ret)) {
buffer_reader.assign(NULL, 0);
handle.reset();
allocator.reuse();
index.reset();
index_index.reset();
index_list.reset();
index_index_list.reset();
buffer_reader.assign(NULL, 0);
common_header.reset();
index_header.reset();
int64_t data_length = 0;
int64_t data_zlength = 0;
ObCompressorType compressor_type = ObCompressorType::INVALID_COMPRESSOR;
if (OB_FAIL(fetch_block_(backup_file_type, offset, length, allocator, buffer_reader))) {
if (OB_FAIL(fetch_block_(backup_file_type, offset, length, allocator, handle, buffer_reader))) {
LOG_WARN("failed to fetch block", K(ret), K_(trailer));
} else if (OB_FAIL(decode_headers_(buffer_reader, common_header,
index_header, data_length, data_zlength, compressor_type))) {
@ -1576,7 +1578,6 @@ int ObBackupOrderedMacroBlockIndexStore::get_macro_block_index(
} else {
offset = index_index.offset_;
length = index_index.length_;
allocator.reuse();
}
}
}

View File

@ -70,7 +70,7 @@ protected:
int decode_index_from_block_(const int64_t data_zlength, const int64_t original_size, const ObCompressorType &compressor_type,
blocksstable::ObBufferReader &buffer_reader, common::ObIArray<IndexType> &index_list);
int fetch_block_(const ObBackupFileType &backup_file_type, const int64_t offset, const int64_t length,
common::ObIAllocator &allocator, blocksstable::ObBufferReader &buffer_reader);
common::ObIAllocator &allocator, ObKVCacheHandle &handle, blocksstable::ObBufferReader &buffer_reader);
int do_on_cache_miss_(const ObBackupFileType &backup_file_type, const int64_t offset, const int64_t length,
common::ObIAllocator &allocator, blocksstable::ObBufferReader &buffer_reader);
int put_block_to_cache_(const ObBackupFileType &backup_file_type, const int64_t offset, const int64_t length,