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

Commitc15789e

Browse files
committed
add pg_cfm to pg_visibility. Delete it after debugging
1 parentdb39866 commitc15789e

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

‎contrib/pg_visibility/pg_visibility--1.1.sql‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ AS 'MODULE_PATHNAME', 'pg_truncate_visibility_map'
6464
LANGUAGE C STRICT
6565
PARALLEL UNSAFE;-- let's not make this any more dangerous
6666

67+
-- Show visibility map and page-level visibility information.
68+
CREATEFUNCTIONpg_cfm(regclass, segnoint,
69+
physSize OUTint, virtSize OUTint,
70+
usedSize OUTint, generation OUTbigint)
71+
RETURNS record
72+
AS'MODULE_PATHNAME','pg_cfm'
73+
LANGUAGE C STRICT;
74+
6775
-- Don't want these to be available to public.
6876
REVOKE ALLON FUNCTION pg_visibility_map(regclass,bigint)FROM PUBLIC;
6977
REVOKE ALLON FUNCTION pg_visibility(regclass,bigint)FROM PUBLIC;

‎contrib/pg_visibility/pg_visibility.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
#include"storage/procarray.h"
2121
#include"storage/smgr.h"
2222
#include"utils/rel.h"
23+
#include"storage/cfs.h"
24+
#ifndefWIN32
25+
#include<sys/mman.h>
26+
#endif
27+
#include<sys/file.h>
28+
#include<sys/param.h>
29+
#include<sys/stat.h>
30+
#include<limits.h>
31+
#include<unistd.h>
32+
#include<fcntl.h>
2333

2434
PG_MODULE_MAGIC;
2535

@@ -747,3 +757,53 @@ tuple_all_visible(HeapTuple tup, TransactionId OldestXmin, Buffer buffer)
747757

748758
return true;
749759
}
760+
761+
PG_FUNCTION_INFO_V1(pg_cfm);
762+
763+
Datum
764+
pg_cfm(PG_FUNCTION_ARGS)
765+
{
766+
Oidrelid=PG_GETARG_OID(0);
767+
int32segno=PG_GETARG_INT32(1);
768+
Relationrel=relation_open(relid,AccessShareLock);
769+
char*path=relpathbackend(rel->rd_node,rel->rd_backend,MAIN_FORKNUM);
770+
char*map_path= (char*)palloc(strlen(path)+16);
771+
intmd;
772+
FileMap*map;
773+
TupleDesctupdesc;
774+
Datumvalues[4];
775+
boolnulls[4];
776+
777+
if (segno==0)
778+
sprintf(map_path,"%s.cfm",path);
779+
else
780+
sprintf(map_path,"%s.%u.cfm",path,segno);
781+
782+
md=open(map_path,O_RDWR|PG_BINARY,0);
783+
784+
map=cfs_mmap(md);
785+
if (map==MAP_FAILED)
786+
elog(ERROR,"pg_cfm failed to read map file %s: %m",map_path);
787+
788+
tupdesc=CreateTemplateTupleDesc(4, false);
789+
TupleDescInitEntry(tupdesc, (AttrNumber)1,"physSize",INT4OID,-1,0);
790+
TupleDescInitEntry(tupdesc, (AttrNumber)2,"virtSize",INT4OID,-1,0);
791+
TupleDescInitEntry(tupdesc, (AttrNumber)3,"usedSize",INT4OID,-1,0);
792+
TupleDescInitEntry(tupdesc, (AttrNumber)4,"generation",INT8OID,-1,0);
793+
tupdesc=BlessTupleDesc(tupdesc);
794+
795+
MemSet(nulls,0,sizeof(nulls));
796+
values[0]=UInt32GetDatum(pg_atomic_read_u32(&map->physSize));
797+
values[1]=UInt32GetDatum(pg_atomic_read_u32(&map->virtSize));
798+
values[2]=UInt32GetDatum(pg_atomic_read_u32(&map->usedSize));
799+
values[3]=UInt64GetDatum(map->generation);
800+
801+
802+
if (cfs_munmap(map)<0)
803+
elog(ERROR,"pg_cfm failed to unmap file %s: %m",map_path);
804+
if (close(md)<0)
805+
elog(ERROR,"pg_cfm failed to close file %s: %m",map_path);
806+
relation_close(rel,AccessShareLock);
807+
808+
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc,values,nulls)));
809+
}

‎src/backend/storage/file/cfs.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ static bool cfs_gc_file(char* map_path)
842842
pg_atomic_write_u32(&map->usedSize,newSize);
843843
pg_atomic_write_u32(&map->physSize,newSize);
844844
map->generation+=1;/* force all backends to reopen the file */
845-
845+
846846
/* Before removing backup files and releasing locks
847847
* we need to flush updated map file */
848848
if (cfs_msync(map)<0)
@@ -906,7 +906,7 @@ static bool cfs_gc_file(char* map_path)
906906
elseif (cfs_state->max_iterations==1)
907907
elog(LOG,"%d: file %.*s: physical size %d, logical size %d, used %d, compression ratio %f",
908908
MyProcPid,suf,map_path,physSize,virtSize,usedSize, (double)virtSize/physSize);
909-
909+
910910
if (cfs_munmap(map)<0)
911911
{
912912
elog(LOG,"CFS failed to unmap file %s: %m",map_path);
@@ -1204,7 +1204,7 @@ Datum cfs_compression_ratio(PG_FUNCTION_ARGS)
12041204

12051205
virtSize+=pg_atomic_read_u32(&map->virtSize);
12061206
physSize+=pg_atomic_read_u32(&map->physSize);
1207-
1207+
12081208
if (cfs_munmap(map)<0)
12091209
elog(LOG,"CFS failed to unmap file %s: %m",map_path);
12101210
if (close(md)<0)
@@ -1255,7 +1255,7 @@ Datum cfs_fragmentation(PG_FUNCTION_ARGS)
12551255
}
12561256
usedSize+=pg_atomic_read_u32(&map->usedSize);
12571257
physSize+=pg_atomic_read_u32(&map->physSize);
1258-
1258+
12591259
if (cfs_munmap(map)<0)
12601260
elog(LOG,"CFS failed to unmap file %s: %m",map_path);
12611261
if (close(md)<0)

‎src/backend/storage/file/fd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ FileLock(File file)
16651665

16661666
cfs_lock_file(vfdP->map,vfdP->fileName);/* protect file from GC */
16671667

1668+
/* Reopen file, because it was rewritten by gc */
16681669
if (vfdP->generation!=vfdP->map->generation)
16691670
{
16701671
close(vfdP->fd);

‎src/include/storage/cfs.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#defineCFS_COMPRESSOR ZLIB_COMPRESSOR
3636
#endif
3737

38-
/* Encryption related variables*/
38+
/* Encryption related variables.
39+
* TODO We're going to change this algorithm till PGPROEE2_0
40+
*/
3941
#defineCFS_RC4_DROP_N 3072
4042
#defineCFS_CIPHER_KEY_SIZE 256
4143

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp