Skip to content

Commit

Permalink
fix(tianmu):The instance occasionally crashes when the memory leak. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
konghaiya authored and mergify[bot] committed Apr 23, 2023
1 parent ba8cead commit 0b1c15a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions storage/tianmu/core/tianmu_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ int TianmuTable::AsyncParseUpdateRecords(system::IOParameters *iop,
current_txn_, update_cols_buf[att]));
}
}
res.get_all_with_except();
res.get_all();
}

clock_gettime(CLOCK_REALTIME, &t2);
Expand All @@ -1726,7 +1726,7 @@ int TianmuTable::AsyncParseDeleteRecords(std::vector<uint64_t> &delete_records)
res.insert(eng->delete_or_update_thread_pool.add_task(&TianmuAttr::DeleteBatchData, m_attrs[att].get(),
current_txn_, delete_records));
}
res.get_all_with_except();
res.get_all();
}

return delete_records.size();
Expand Down
2 changes: 2 additions & 0 deletions storage/tianmu/data/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Pack::Pack(DPN *dpn, PackCoordinate pc, ColumnShare *col_share) : col_share_(col
bitmap_size_ = (1 << col_share->pss) / 8;
nulls_ptr_ = std::make_unique<uint32_t[]>(bitmap_size_ / sizeof(uint32_t));
deletes_ptr_ = std::make_unique<uint32_t[]>(bitmap_size_ / sizeof(uint32_t));
std::memset(nulls_ptr_.get(), 0, bitmap_size_);
std::memset(deletes_ptr_.get(), 0, bitmap_size_);
// nulls MUST be initialized in the constructor, there are 3 cases in total:
// 1. All values are nullptr. It is initialized here by InitNull();
// 2. All values are uniform. Then it would be all zeros already.
Expand Down
17 changes: 9 additions & 8 deletions storage/tianmu/data/pack_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ void PackStr::LoadDataFromFile(system::Stream *f) {
}

void PackStr::Destroy() {
if (pack_str_state_ == PackStrtate::kPackArray) {
for (auto &it : data_.v) {
dealloc(it.ptr);
}
} else {
marisa_trie_.clear();
compressed_data_.reset(nullptr);
for (auto &it : data_.v) {
dealloc(it.ptr);
}
data_.v.clear();

marisa_trie_.clear();
compressed_data_.reset(nullptr);

dealloc(data_.index);
data_.index = nullptr;
dealloc(data_.lens);
Expand Down Expand Up @@ -489,6 +489,7 @@ void PackStr::CompressTrie() {
dpn_->dataLength = bufsz;
std::ostringstream oss;
oss << marisa_trie_;
compressed_data_.reset(nullptr);
compressed_data_ = alloc_ptr(bufsz, mm::BLOCK_TYPE::BLOCK_TEMPORARY);
char *buf_ptr = static_cast<char *>(compressed_data_.get());
std::memcpy(buf_ptr, oss.str().data(), oss.str().length());
Expand Down Expand Up @@ -707,7 +708,7 @@ void PackStr::LoadCompressed(system::Stream *f) {

void PackStr::LoadCompressedTrie(system::Stream *f) {
ASSERT(IsModeCompressionApplied());

compressed_data_.reset(nullptr);
compressed_data_ = alloc_ptr(dpn_->dataLength + 1, mm::BLOCK_TYPE::BLOCK_COMPRESSED);
f->ReadExact(compressed_data_.get(), dpn_->dataLength);
auto trie_length = dpn_->dataLength - (dpn_->numOfRecords * sizeof(unsigned short)) - 8;
Expand Down
4 changes: 3 additions & 1 deletion storage/tianmu/vc/tianmu_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ bool TianmuAttr::SaveVersion() {

get_pack(i)->Save();
get_pack(i)->Unlock(); // now it can be released by MM
ha_tianmu_engine_->cache.DropObject(get_pc(i));
dpn.SetPackPtr(0);
}
}
Expand Down Expand Up @@ -947,6 +948,7 @@ void TianmuAttr::LoadData(loader::ValueCache *nvs, Transaction *conn_info) {
assert(eng);

eng->cache.DropObject(get_pc(pi));
dpn.SetLocal(false);
dpn.SetPackPtr(0);
}

Expand Down Expand Up @@ -1283,7 +1285,7 @@ void TianmuAttr::ResetMaxMin(DPN &dpn) {
}

void TianmuAttr::CopyPackForWrite(common::PACK_INDEX pi) {
if (get_dpn(pi).IsLocal())
if (get_dpn(pi).IsLocal() && get_pack(pi))
return;

auto &old_dpn(get_dpn(pi)); // save a ref to the old dpn
Expand Down

0 comments on commit 0b1c15a

Please sign in to comment.