mirror of
https://gitee.com/he3db/he3pg.git
synced 2024-12-03 12:47:34 +08:00
Merge branch 'dev_performance' of gitee.com:he3db/he3pg into dev_performance
This commit is contained in:
commit
55df57f91e
@ -47,10 +47,15 @@ static LogIndexMemTBL *GetNextFreeMemTbl(void)
|
||||
log_index_mem_list->active_table_index = (log_index_mem_list->active_table_index + 1)%(log_index_mem_list->table_cap);
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
// if all mem table is full, waiting for recycle
|
||||
if(log_index_mem_list->active_table_index == log_index_mem_list->table_start_index)
|
||||
{
|
||||
elog(LOG, "Mem table is full, waiting for cleanup. Total size: %ld", logindex_mem_tbl_size);
|
||||
}
|
||||
while(log_index_mem_list->active_table_index == log_index_mem_list->table_start_index)
|
||||
{
|
||||
pg_usleep(10); /* 10 us */
|
||||
}
|
||||
elog(DEBUG5, "Find next free mem table");
|
||||
// if it finds free mem table will return directly.
|
||||
return &(log_index_mem_list->mem_table[log_index_mem_list->active_table_index]);
|
||||
}
|
||||
@ -437,40 +442,7 @@ LsnNode *GetLogIndexByPage(const BufferTag *page, XLogRecPtr start_lsn, XLogRecP
|
||||
// Prevent metadata changes during discovery.
|
||||
// TODO change to Lightweight Lock
|
||||
head_node = InitLsnNode();
|
||||
LWLockAcquire(LogIndexMemListLock,LW_SHARED);
|
||||
// just one mem table
|
||||
if(log_index_mem_list->table_start_index == log_index_mem_list->active_table_index)
|
||||
{
|
||||
LogIndexMemTBL *mem_tbl = &(log_index_mem_list->mem_table[log_index_mem_list->active_table_index]);
|
||||
// get index of current table's seg
|
||||
uint16 seg_index = FindFirstLsnSegInMemTblByPageTag(mem_tbl, page, start_lsn, end_lsn);
|
||||
while (seg_index != LOG_INDEX_TBL_INVALID_SEG)
|
||||
{
|
||||
LogIndexMemItemSeg *item_seg = &(mem_tbl->seg_item[seg_index - 1]);
|
||||
// loop for lsn list
|
||||
for(int i=0; i < item_seg->number; i++){
|
||||
XLogRecPtr lsn = LOG_INDEX_COMBINE_LSN(mem_tbl, item_seg->suffix_lsn[i]);
|
||||
if(lsn >= start_lsn)
|
||||
{
|
||||
if(lsn < end_lsn)
|
||||
{
|
||||
InsertLsnNodeByHead(head_node, lsn);
|
||||
}else{
|
||||
ReverseLsnNode(head_node);
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
return head_node;
|
||||
}
|
||||
}else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
seg_index = item_seg->next_seg;
|
||||
}
|
||||
ReverseLsnNode(head_node);
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
return head_node;
|
||||
}
|
||||
LWLockAcquire(LogIndexMemListLock,LW_SHARED);
|
||||
tbl_index = log_index_mem_list->table_start_index;
|
||||
while(tbl_index != log_index_mem_list->active_table_index)
|
||||
{
|
||||
@ -513,6 +485,39 @@ LsnNode *GetLogIndexByPage(const BufferTag *page, XLogRecPtr start_lsn, XLogRecP
|
||||
}
|
||||
}
|
||||
}
|
||||
// loop for active table
|
||||
if(tbl_index == log_index_mem_list->active_table_index)
|
||||
{
|
||||
LogIndexMemTBL *mem_tbl = &(log_index_mem_list->mem_table[log_index_mem_list->active_table_index]);
|
||||
// get index of current table's seg
|
||||
uint16 seg_index = FindFirstLsnSegInMemTblByPageTag(mem_tbl, page, start_lsn, end_lsn);
|
||||
while (seg_index != LOG_INDEX_TBL_INVALID_SEG)
|
||||
{
|
||||
LogIndexMemItemSeg *item_seg = &(mem_tbl->seg_item[seg_index - 1]);
|
||||
// loop for lsn list
|
||||
for(int i=0; i < item_seg->number; i++){
|
||||
XLogRecPtr lsn = LOG_INDEX_COMBINE_LSN(mem_tbl, item_seg->suffix_lsn[i]);
|
||||
if(lsn >= start_lsn)
|
||||
{
|
||||
if(lsn < end_lsn)
|
||||
{
|
||||
InsertLsnNodeByHead(head_node, lsn);
|
||||
}else{
|
||||
ReverseLsnNode(head_node);
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
return head_node;
|
||||
}
|
||||
}else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
seg_index = item_seg->next_seg;
|
||||
}
|
||||
ReverseLsnNode(head_node);
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
return head_node;
|
||||
}
|
||||
ReverseLsnNode(head_node);
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
return head_node;
|
||||
@ -534,6 +539,7 @@ void CleanLogIndexByPage(XLogRecPtr consist_lsn)
|
||||
{
|
||||
break;
|
||||
}
|
||||
elog(DEBUG5, "Reset Mem table id=%ld by consist_lsn=%ld ", mem_tbl->meta.id, consist_lsn);
|
||||
RestMemTable(mem_tbl);
|
||||
log_index_mem_list->table_start_index = (log_index_mem_list->table_start_index + 1)%(log_index_mem_list->table_cap);
|
||||
}
|
||||
@ -546,7 +552,9 @@ Size He3dbLogIndexShmemSize(void)
|
||||
if (he3db_logindex_mem_size <= 0)
|
||||
return size;
|
||||
size = LogIndexMemListSize(he3db_logindex_mem_size);
|
||||
return CACHELINEALIGN(size);
|
||||
size = CACHELINEALIGN(size);
|
||||
elog(DEBUG5, "Mem table size=%ld in share memory", size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void FreeLsnNode(LsnNode *head)
|
||||
|
Loading…
Reference in New Issue
Block a user