mirror of
https://gitee.com/he3db/he3pg.git
synced 2024-11-29 18:58:35 +08:00
feat: add pg_stat_he3_logindex view
This commit is contained in:
parent
d0ec1f3a5b
commit
a908e02066
@ -879,8 +879,9 @@ CREATE VIEW pg_stat_he3_logindex AS
|
||||
SELECT
|
||||
s.memtable_total,
|
||||
s.memtable_used,
|
||||
s.memtable_start_index,
|
||||
s.memtable_active_index,
|
||||
s.memtable_start_index
|
||||
s.page_total
|
||||
FROM pg_stat_get_he3_logindex() AS s;
|
||||
|
||||
CREATE VIEW pg_stat_slru AS
|
||||
|
@ -829,12 +829,29 @@ void FreeTagNode(TagNode *head)
|
||||
}
|
||||
}
|
||||
|
||||
void He3DBGetLogindexStats(uint64 *memtable_total, uint64 *memtable_used, uint64 *memtable_active_index, uint64 *memtable_start_index)
|
||||
void He3DBGetLogindexStats(uint64 *memtable_total, uint64 *memtable_used, uint64 *memtable_active_index,
|
||||
uint64 *memtable_start_index, uint64 *page_total)
|
||||
{
|
||||
LWLockAcquire(LogIndexMemListLock,LW_SHARED);
|
||||
*memtable_start_index = log_index_mem_list->table_start_index;
|
||||
*memtable_active_index = log_index_mem_list->active_table_index;
|
||||
*memtable_total = log_index_mem_list->table_cap;
|
||||
*memtable_used = ((*memtable_active_index - *memtable_start_index) + *memtable_total)%*memtable_total + 1;
|
||||
LWLockRelease(LogIndexMemListLock);
|
||||
*memtable_used = ((*memtable_active_index - *memtable_start_index) + *memtable_total)%*memtable_total + 1;
|
||||
uint64 tbl_index = *memtable_start_index;
|
||||
uint64 page_num = 0;
|
||||
while(tbl_index != *memtable_active_index)
|
||||
{
|
||||
LogIndexMemTBL *mem_tbl = &(log_index_mem_list->mem_table[tbl_index]);
|
||||
tbl_index = (tbl_index + 1)%(*memtable_total);
|
||||
page_num = page_num + mem_tbl->meta.page_free_head - 2;
|
||||
}
|
||||
if (tbl_index == *memtable_active_index)
|
||||
{
|
||||
LogIndexMemTBL *mem_tbl = &(log_index_mem_list->mem_table[tbl_index]);
|
||||
if (pg_atomic_read_u32(&mem_tbl->meta.state) != LOG_INDEX_MEM_TBL_STATE_FREE){
|
||||
page_num = page_num + mem_tbl->meta.page_free_head - 2;
|
||||
}
|
||||
}
|
||||
*page_total = page_num;
|
||||
}
|
||||
|
@ -2438,7 +2438,7 @@ pg_stat_get_he3walwrite(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_stat_get_he3_logindex(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define PG_STAT_GET_HE3_LOGINDEX_COLS 4
|
||||
#define PG_STAT_GET_HE3_LOGINDEX_COLS 5
|
||||
TupleDesc tupdesc;
|
||||
Datum values[PG_STAT_GET_HE3_LOGINDEX_COLS];
|
||||
bool nulls[PG_STAT_GET_HE3_LOGINDEX_COLS];
|
||||
@ -2446,31 +2446,35 @@ pg_stat_get_he3_logindex(PG_FUNCTION_ARGS)
|
||||
uint64 memtable_used;
|
||||
uint64 memtable_active_index;
|
||||
uint64 memtable_start_index;
|
||||
uint64 page_total;
|
||||
|
||||
/* Initialise values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* Initialise attributes information in the tuple descriptor */
|
||||
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_HE3WALWRITE_COLS);
|
||||
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_HE3_LOGINDEX_COLS);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "memtable_total",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "memtable_used",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "memtable_active_index",
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "memtable_start_index",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "memtable_start_index",
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "memtable_active_index",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "page_total",
|
||||
INT8OID, -1, 0);
|
||||
|
||||
BlessTupleDesc(tupdesc);
|
||||
|
||||
He3DBGetLogindexStats(&memtable_total, &memtable_used, &memtable_active_index, &memtable_start_index);
|
||||
He3DBGetLogindexStats(&memtable_total, &memtable_used, &memtable_active_index, &memtable_start_index, &page_total);
|
||||
|
||||
/* Fill values and NULLs */
|
||||
values[0] = UInt64GetDatum(memtable_total);
|
||||
values[1] = UInt64GetDatum(memtable_used);
|
||||
values[2] = UInt64GetDatum(memtable_active_index);
|
||||
values[3] = UInt64GetDatum(memtable_start_index);
|
||||
values[2] = UInt64GetDatum(memtable_start_index);
|
||||
values[3] = UInt64GetDatum(memtable_active_index);
|
||||
values[4] = UInt64GetDatum(page_total);
|
||||
|
||||
/* Returns the record as Datum */
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
|
||||
|
@ -5593,9 +5593,9 @@
|
||||
{ oid => '6207', descr => 'statistics: information about He3DB LogIndex',
|
||||
proname => 'pg_stat_get_he3_logindex', proisstrict => 'f', provolatile => 's',
|
||||
proparallel => 'r', prorettype => 'record', proargtypes => '',
|
||||
proallargtypes => '{int8,int8,int8,int8}',
|
||||
proargmodes => '{o,o,o,o}',
|
||||
proargnames => '{memtable_total,memtable_used,memtable_active_index,memtable_start_index}',
|
||||
proallargtypes => '{int8,int8,int8,int8,int8}',
|
||||
proargmodes => '{o,o,o,o,o}',
|
||||
proargnames => '{memtable_total,memtable_used,memtable_start_index,memtable_active_index,page_total}',
|
||||
prosrc => 'pg_stat_get_he3_logindex' },
|
||||
|
||||
{ oid => '2306', descr => 'statistics: information about SLRU caches',
|
||||
|
@ -117,5 +117,6 @@ extern void FreeLsnNode(LsnNode *head);
|
||||
extern TagNode *GetBufTagByLsnRange(XLogRecPtr start_lsn, XLogRecPtr end_lsn);
|
||||
extern void FreeTagNode(TagNode *head);
|
||||
extern bool CheckBufTagExistByLsnRange(const BufferTag *page, XLogRecPtr start_lsn, XLogRecPtr end_lsn);
|
||||
extern void He3DBGetLogindexStats(uint64 *memtable_total, uint64 *memtable_used, uint64 *memtable_active_index, uint64 *memtable_start_index);
|
||||
extern void He3DBGetLogindexStats(uint64 *memtable_total, uint64 *memtable_used, uint64 *memtable_active_index,
|
||||
uint64 *memtable_start_index, uint64 *page_total);
|
||||
#endif /* HE3DB_LOGINDEX_H */
|
Loading…
Reference in New Issue
Block a user