!100 improve: logindex insert

* improve: logindex insert
This commit is contained in:
wangyao 2023-03-29 09:09:17 +00:00 committed by shipixian
parent ebc7430aa4
commit 38a55cc693

View File

@ -235,6 +235,17 @@ static void InsertLsnNodeByHead(LsnNode *head, XLogRecPtr lsn)
head->next = new_node;
}
// eg: before: head-->node1-->NULL, after: head-->node1-->newNode-->NULL
static LsnNode *InsertLsnNodeByTail(LsnNode *head, int lsn)
{
LsnNode *new_node;
new_node = (LsnNode *)malloc(sizeof(LsnNode));
head->next = new_node;
new_node->lsn = lsn;
new_node->next = NULL;
return new_node;
}
// print nodelist
static void PrintLsnNode(LsnNode *head)
{
@ -437,11 +448,13 @@ void InsertLogIndexByPage(const BufferTag *page, XLogRecPtr lsn)
LsnNode *GetLogIndexByPage(const BufferTag *page, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
{
LsnNode *head_node;
LsnNode *tail;
uint64 tbl_index;
// Prevent metadata changes during discovery.
// TODO change to Lightweight Lock
head_node = InitLsnNode();
tail = 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)
@ -470,9 +483,8 @@ LsnNode *GetLogIndexByPage(const BufferTag *page, XLogRecPtr start_lsn, XLogRecP
{
if(lsn < end_lsn)
{
InsertLsnNodeByHead(head_node, lsn);
tail = InsertLsnNodeByTail(tail, lsn);
}else{
ReverseLsnNode(head_node);
LWLockRelease(LogIndexMemListLock);
return head_node;
}
@ -501,9 +513,8 @@ LsnNode *GetLogIndexByPage(const BufferTag *page, XLogRecPtr start_lsn, XLogRecP
{
if(lsn < end_lsn)
{
InsertLsnNodeByHead(head_node, lsn);
tail = InsertLsnNodeByTail(tail, lsn);
}else{
ReverseLsnNode(head_node);
LWLockRelease(LogIndexMemListLock);
return head_node;
}
@ -514,11 +525,9 @@ LsnNode *GetLogIndexByPage(const BufferTag *page, XLogRecPtr start_lsn, XLogRecP
}
seg_index = item_seg->next_seg;
}
ReverseLsnNode(head_node);
LWLockRelease(LogIndexMemListLock);
return head_node;
}
ReverseLsnNode(head_node);
LWLockRelease(LogIndexMemListLock);
return head_node;
}