Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c132a3

Browse files
committed
Refactor stats API and remove ptrack_get_change_file_stat
1 parentab17447 commit9c132a3

File tree

4 files changed

+25
-41
lines changed

4 files changed

+25
-41
lines changed

‎README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ To disable `ptrack` and clean up all remaining service files set `ptrack.map_siz
6767
* ptrack_init_lsn() — returns LSN of the last ptrack map initialization.
6868
* ptrack_get_pagemapset(start_lsn pg_lsn) — returns a set of changed data files with bitmaps of changed blocks since specified`start_lsn`.
6969
* ptrack_get_change_stat(start_lsn pg_lsn) — returns statistic of changes (number of files, pages and size in MB) since specified`start_lsn`.
70-
* ptrack_get_change_file_stat(start_lsn pg_lsn) — returns per file statistic of changes (number of pages and size in MB) since specified`start_lsn`.
7170

7271
Usage example:
7372

‎ptrack--2.1--2.2.sql

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
-- Complain if script is sourced in psql, rather than via ALTER EXTENSION
44
\echo Use"ALTER EXTENSION ptrack UPDATE;" to load this file.\ quit
55

6+
DROPFUNCTION ptrack_get_pagemapset(start_lsn pg_lsn);
7+
CREATEFUNCTIONptrack_get_pagemapset(start_lsn pg_lsn)
8+
RETURNS TABLE (pathtext,
9+
pagecountbigint,
10+
pagemapbytea)
11+
AS'MODULE_PATHNAME'
12+
LANGUAGE C STRICT VOLATILE;
13+
614
CREATEFUNCTIONptrack_get_change_stat(start_lsn pg_lsn)
715
RETURNS TABLE (
816
filesbigint,
9-
pagesbigint,
17+
pagesnumeric,
1018
"size, MB"numeric
1119
)AS
1220
$func$
@@ -18,37 +26,10 @@ BEGIN
1826
RETURN QUERY
1927
SELECT changed_files,
2028
changed_pages,
21-
block_size*changed_pages/(1024.0*1024)
29+
block_size*changed_pages/(1024.0*1024)
2230
FROM
2331
(SELECTcount(path)AS changed_files,
24-
sum(
25-
length(replace(right((pagemap)::text,-1)::varbit::text,'0',''))
26-
)AS changed_pages
32+
sum(pagecount)AS changed_pages
2733
FROM ptrack_get_pagemapset(start_lsn)) s;
2834
END
2935
$func$ LANGUAGE plpgsql;
30-
31-
CREATEFUNCTIONptrack_get_change_file_stat(start_lsn pg_lsn)
32-
RETURNS TABLE (
33-
file_pathtext,
34-
pagesint,
35-
"size, MB"numeric
36-
)AS
37-
$func$
38-
DECLARE
39-
block_sizebigint;
40-
BEGIN
41-
block_size := (SELECT settingFROM pg_settingsWHERE name='block_size');
42-
43-
RETURN QUERY
44-
SELECTs.path,
45-
changed_pages,
46-
block_size*changed_pages/(1024.0*1024)
47-
FROM
48-
(SELECTpath,
49-
length(replace(right((pagemap)::text,-1)::varbit::text,'0',''))
50-
AS changed_pages
51-
FROM ptrack_get_pagemapset(start_lsn)) s
52-
ORDER BY (changed_pages,s.path)DESC;
53-
END
54-
$func$ LANGUAGE plpgsql;

‎ptrack.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
424424
FuncCallContext*funcctx;
425425
MemoryContextoldcontext;
426426
datapagemap_tpagemap;
427+
int64pagecount=0;
427428
chargather_path[MAXPGPATH];
428429

429430
/* Exit immediately if there is no map */
@@ -444,12 +445,13 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
444445

445446
/* Make tuple descriptor */
446447
#ifPG_VERSION_NUM >=120000
447-
tupdesc=CreateTemplateTupleDesc(2);
448+
tupdesc=CreateTemplateTupleDesc(3);
448449
#else
449-
tupdesc=CreateTemplateTupleDesc(2, false);
450+
tupdesc=CreateTemplateTupleDesc(3, false);
450451
#endif
451452
TupleDescInitEntry(tupdesc, (AttrNumber)1,"path",TEXTOID,-1,0);
452-
TupleDescInitEntry(tupdesc, (AttrNumber)2,"pagemap",BYTEAOID,-1,0);
453+
TupleDescInitEntry(tupdesc, (AttrNumber)2,"pagecount",INT8OID,-1,0);
454+
TupleDescInitEntry(tupdesc, (AttrNumber)3,"pagemap",BYTEAOID,-1,0);
453455
funcctx->tuple_desc=BlessTupleDesc(tupdesc);
454456

455457
funcctx->user_fctx=ctx;
@@ -497,8 +499,8 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
497499
/* We completed a segment and there is a bitmap to return */
498500
if (pagemap.bitmap!=NULL)
499501
{
500-
Datumvalues[2];
501-
boolnulls[2]= {false};
502+
Datumvalues[3];
503+
boolnulls[3]= {false};
502504
charpathname[MAXPGPATH];
503505
bytea*result=NULL;
504506
Sizeresult_sz=pagemap.bitmapsize+VARHDRSZ;
@@ -512,11 +514,13 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
512514
strcpy(pathname,ctx->relpath);
513515

514516
values[0]=CStringGetTextDatum(pathname);
515-
values[1]=PointerGetDatum(result);
517+
values[1]=Int64GetDatum(pagecount);
518+
values[2]=PointerGetDatum(result);
516519

517520
pfree(pagemap.bitmap);
518521
pagemap.bitmap=NULL;
519522
pagemap.bitmapsize=0;
523+
pagecount=0;
520524

521525
htup=heap_form_tuple(funcctx->tuple_desc,values,nulls);
522526
if (htup)
@@ -553,7 +557,10 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
553557

554558
/* Block has been changed since specified LSN. Mark it in the bitmap */
555559
if (update_lsn2 >=ctx->lsn)
560+
{
561+
pagecount+=1;
556562
datapagemap_add(&pagemap,ctx->bid.blocknum % ((BlockNumber)RELSEG_SIZE));
563+
}
557564
}
558565

559566
ctx->bid.blocknum+=1;

‎t/001_basic.pl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use TestLib;
1111
use Test::More;
1212

13-
plantests=>25;
13+
plantests=>24;
1414

1515
my$node;
1616
my$res;
@@ -119,9 +119,6 @@
119119
$res_stdout =$node->safe_psql("postgres","SELECT pages FROM ptrack_get_change_stat('$flush_lsn')");
120120
is($res_stdout > 0, 1,'should be able to get aggregated stats of changes');
121121

122-
$res_stdout =$node->safe_psql("postgres","SELECT count(*) FROM ptrack_get_change_file_stat('$flush_lsn')");
123-
is($res_stdout > 0, 1,'should be able to get per file stats of changes');
124-
125122
# We should be able to change ptrack map size (but loose all changes)
126123
$node->append_conf(
127124
'postgresql.conf',q{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp