Fix truncate to release rows properly

This commit is contained in:
Vinoth Veeraraghavan
2020-09-15 18:31:03 +08:00
parent 6da0072c29
commit 0e1dcf689f
4 changed files with 42 additions and 4 deletions

View File

@ -502,6 +502,7 @@ MOTIndexArr::MOTIndexArr(MOT::Table* table)
{
m_numIndexes = 0;
m_table = table;
m_rowPool = table->GetRowPool();
errno_t erc = memset_s(m_indexArr, MAX_NUM_INDEXES * sizeof(MOT::Index*), 0, MAX_NUM_INDEXES * sizeof(MOT::Index*));
securec_check(erc, "\0", "\0");
erc = memset_s(m_origIx, MAX_NUM_INDEXES * sizeof(uint16_t), 0, MAX_NUM_INDEXES * sizeof(uint16_t));

View File

@ -774,9 +774,20 @@ public:
return m_table;
}
void SetRowPool(MOT::ObjAllocInterface* rowPool)
{
m_rowPool = rowPool;
}
MOT::ObjAllocInterface* GetRowPool()
{
return m_rowPool;
}
private:
MOT::Index* m_indexArr[MAX_NUM_INDEXES];
MOT::Table* m_table;
MOT::ObjAllocInterface* m_rowPool;
uint16_t m_origIx[MAX_NUM_INDEXES];
uint16_t m_numIndexes;
};

View File

@ -64,6 +64,7 @@ class alignas(CL_SIZE) Table : public Serializable {
friend TxnManager;
friend TxnInsertAction;
friend MOT::Index;
friend MOT::MOTIndexArr;
friend RecoveryManager;
friend TxnDDLAccess;
@ -825,6 +826,22 @@ public:
Row* RemoveKeyFromIndex(Row* row, Sentinel* sentinel, uint64_t tid, GcManager* gc);
private:
inline MOT::ObjAllocInterface* GetRowPool()
{
return m_rowPool;
}
inline void ReplaceRowPool(MOT::ObjAllocInterface* rowPool)
{
ObjAllocInterface::FreeObjPool(&m_rowPool);
m_rowPool = rowPool;
}
inline void FreeObjectPool(MOT::ObjAllocInterface* rowPool)
{
ObjAllocInterface::FreeObjPool(&rowPool);
}
/** @var Global atomic table identifier. */
static std::atomic<uint32_t> tableCounter;

View File

@ -516,11 +516,11 @@ void TxnManager::RollbackDDLs()
break;
case DDL_ACCESS_TRUNCATE_TABLE:
indexArr = (MOTIndexArr*)ddl_access->GetEntry();
table = indexArr->GetTable();
table->WrLock();
if (indexArr->GetNumIndexes() > 0) {
MOT_ASSERT(indexArr->GetNumIndexes() == table->GetNumIndexes());
table = indexArr->GetTable();
MOT_LOG_INFO("Rollback of truncate table %s", table->GetLongTableName().c_str());
table->WrLock();
for (int idx = 0; idx < indexArr->GetNumIndexes(); idx++) {
uint16_t oldIx = indexArr->GetIndexIx(idx);
MOT::Index* oldIndex = indexArr->GetIndex(idx);
@ -534,8 +534,9 @@ void TxnManager::RollbackDDLs()
index->Truncate(true);
delete index;
}
table->Unlock();
}
table->ReplaceRowPool(indexArr->GetRowPool());
table->Unlock();
delete indexArr;
break;
case DDL_ACCESS_CREATE_INDEX:
@ -595,14 +596,15 @@ void TxnManager::CleanDDLChanges()
break;
case DDL_ACCESS_TRUNCATE_TABLE:
indexArr = (MOTIndexArr*)ddl_access->GetEntry();
table = indexArr->GetTable();
if (indexArr->GetNumIndexes() > 0) {
table = indexArr->GetTable();
table->m_rowCount = 0;
for (int i = 0; i < indexArr->GetNumIndexes(); i++) {
index = indexArr->GetIndex(i);
table->DeleteIndex(index);
}
}
table->FreeObjectPool(indexArr->GetRowPool());
delete indexArr;
break;
case DDL_ACCESS_CREATE_INDEX:
@ -1124,6 +1126,13 @@ RC TxnManager::TruncateTable(Table* table)
return RC_MEMORY_ALLOCATION_ERROR;
}
if (!table->InitRowPool()) {
table->m_rowPool = indexesArr->GetRowPool();
delete indexesArr;
delete ddl_access;
return RC_MEMORY_ALLOCATION_ERROR;
}
for (uint16_t i = 0; i < table->GetNumIndexes(); i++) {
MOT::Index* index = table->GetIndex(i);
MOT::Index* index_copy = index->CloneEmpty();