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

Commit7b887fe

Browse files
committed
Merge branch 'PGPROEE9_6_CFS_385' into PGPROEE9_6
2 parentsc59990e +2865e31 commit7b887fe

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
855855
char*file_path= (char*)palloc(suf+1);
856856
char*map_bck_path= (char*)palloc(suf+10);
857857
char*file_bck_path= (char*)palloc(suf+5);
858+
char*state;
858859
intrc;
859860

860861
pg_atomic_fetch_add_u32(&cfs_state->n_active_gc,1);
@@ -876,6 +877,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
876877
{
877878
pg_atomic_fetch_sub_u32(&cfs_state->n_active_gc,1);
878879

880+
pgstat_report_activity(STATE_DISABLED,"GC is disabled");
879881
rc=WaitLatch(MyLatch,
880882
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
881883
CFS_DISABLE_TIMEOUT/* ms */);
@@ -914,6 +916,10 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
914916
strcat(strcpy(map_bck_path,map_path),".bck");
915917
strcat(strcpy(file_bck_path,file_path),".bck");
916918

919+
state=psprintf("Check file %s",file_path);
920+
pgstat_report_activity(STATE_RUNNING,state);
921+
pfree(state);
922+
917923
/* mostly same as for cfs_lock_file */
918924
if (pg_atomic_read_u32(&map->gc_active))/* Check if GC was not normally completed at previous Postgres run */
919925
{
@@ -943,6 +949,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
943949
uint32second_pass_bytes=0;
944950
inode_t**inodes= (inode_t**)palloc(RELSEG_SIZE*sizeof(inode_t*));
945951
boolremove_backups= true;
952+
boolgot_lock= false;
946953
intsecond_pass_whole=0;
947954
intn_pages,n_pages1;
948955
TimestampTzstartTime,secondTime,endTime;
@@ -957,6 +964,10 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
957964

958965
lock=cfs_get_lock(file_path);
959966

967+
state=psprintf("Process file %s",file_path);
968+
pgstat_report_activity(STATE_RUNNING,state);
969+
pfree(state);
970+
960971
fd2=open(file_bck_path,O_CREAT|O_RDWR|PG_BINARY|O_TRUNC,0600);
961972
if (fd2<0)
962973
{
@@ -998,6 +1009,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
9981009
retry:
9991010
/* temporary lock file for fetching map snapshot */
10001011
cfs_gc_lock(lock);
1012+
got_lock= true;
10011013

10021014
/* Reread variables after locking file */
10031015
physSize=pg_atomic_read_u32(&map->hdr.physSize);
@@ -1013,6 +1025,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10131025
}
10141026
/* may unlock until second phase */
10151027
cfs_gc_unlock(lock);
1028+
got_lock= false;
10161029

10171030
if (!cfs_copy_inodes(inodes,n_pages,fd,fd2,&writeback,&newSize,
10181031
file_path,file_bck_path))
@@ -1034,6 +1047,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10341047
secondTime=GetCurrentTimestamp();
10351048

10361049
cfs_gc_lock(lock);
1050+
got_lock= true;
10371051

10381052
/* Reread variables after locking file */
10391053
n_pages1=n_pages;
@@ -1087,6 +1101,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10871101
if (second_pass_whole==1&&physSize<CFS_RETRY_GC_THRESHOLD)
10881102
{
10891103
cfs_gc_unlock(lock);
1104+
got_lock= false;
10901105
/* sleep, cause there is possibly checkpoint is on a way */
10911106
pg_usleep(CFS_LOCK_MAX_TIMEOUT);
10921107
second_pass=0;
@@ -1285,7 +1300,8 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
12851300
else
12861301
remove_backups= true;/* we don't need backups anymore */
12871302

1288-
cfs_gc_unlock(lock);
1303+
if (got_lock)
1304+
cfs_gc_unlock(lock);
12891305

12901306
/* remove map backup file */
12911307
if (remove_backups&&unlink(map_bck_path))
@@ -1340,10 +1356,12 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
13401356

13411357
if (background==CFS_BACKGROUND)
13421358
{
1343-
intrc=WaitLatch(MyLatch,
1344-
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
1345-
performed ?cfs_gc_delay :0/* ms */ );
1346-
if (rc&WL_POSTMASTER_DEATH)
1359+
intrc;
1360+
pgstat_report_activity(STATE_IDLE,"Processing pause");
1361+
rc=WaitLatch(MyLatch,
1362+
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
1363+
performed ?cfs_gc_delay :0/* ms */ );
1364+
if (cfs_gc_stop|| (rc&WL_POSTMASTER_DEATH))
13471365
exit(1);
13481366

13491367
ResetLatch(MyLatch);
@@ -1408,6 +1426,7 @@ static bool cfs_gc_directory(int worker_id, char const* path, int depth)
14081426
staticvoidcfs_gc_cancel(intsig)
14091427
{
14101428
cfs_gc_stop= true;
1429+
SetLatch(MyLatch);
14111430
}
14121431

14131432
staticvoidcfs_sighup(SIGNAL_ARGS)
@@ -1433,12 +1452,19 @@ static void cfs_gc_bgworker_main(Datum arg)
14331452
{
14341453
MemoryContextMemCxt;
14351454
intworker_id=DatumGetInt32(arg);
1455+
char*appname;
14361456

14371457
pqsignal(SIGINT,cfs_gc_cancel);
14381458
pqsignal(SIGQUIT,cfs_gc_cancel);
14391459
pqsignal(SIGTERM,cfs_gc_cancel);
14401460
pqsignal(SIGHUP,cfs_sighup);
14411461

1462+
InitPostgres(NULL,InvalidOid,NULL,InvalidOid,NULL);
1463+
1464+
appname=psprintf("CFS GC worker %d",worker_id);
1465+
pgstat_report_appname(appname);
1466+
pfree(appname);
1467+
14421468
/* We're now ready to receive signals */
14431469
BackgroundWorkerUnblockSignals();
14441470

@@ -1461,10 +1487,11 @@ static void cfs_gc_bgworker_main(Datum arg)
14611487
{
14621488
break;
14631489
}
1490+
pgstat_report_activity(STATE_IDLE,"Pause between GC iterations");
14641491
rc=WaitLatch(MyLatch,
14651492
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
14661493
timeout/* ms */ );
1467-
if (rc&WL_POSTMASTER_DEATH)
1494+
if ((rc&WL_POSTMASTER_DEATH)||cfs_gc_stop)
14681495
exit(1);
14691496

14701497
ResetLatch(MyLatch);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,6 @@ FileWrite(File file, char *buffer, int amount)
20562056
if (CFS_INODE_SIZE(inode)!=BLCKSZ)
20572057
{
20582058
pos=cfs_alloc_page(map,CFS_INODE_SIZE(inode),BLCKSZ);
2059-
inode=CFS_INODE(BLCKSZ,pos);
20602059
}
20612060
else
20622061
{
@@ -2066,6 +2065,8 @@ FileWrite(File file, char *buffer, int amount)
20662065
*/
20672066
pos=CFS_INODE_OFFS(inode);
20682067
}
2068+
/* we need to do it in both cases to clear flag set by gc */
2069+
inode=CFS_INODE(BLCKSZ,pos);
20692070
}
20702071
seekPos=lseek(vfdP->fd,pos,SEEK_SET);
20712072
Assert(seekPos== (off_t)pos);

‎src/test/isolation/specs/atx-deadlock-1.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ teardown
1111
}
1212

1313
session"s1"
14-
setup {begin; }
14+
setup {begin;SETdeadlock_timeout='10s';}
1515
step"s1la" {locktableainaccessexclusivemode; }
1616
step"s1atxb" {beginautonomous; }
1717
step"s1lb" {locktablebinaccessexclusivemode; }
1818
step"s1atxc" {commit; }
1919
step"s1c" {commit; }
2020

2121
session"s2"
22-
setup {begin; }
22+
setup {begin;SETdeadlock_timeout='10s';}
2323
step"s2lb" {locktablebinaccessexclusivemode; }
2424
step"s2la" {locktableainaccessexclusivemode; }
2525
step"s2c" {commit; }

‎src/test/isolation/specs/atx-deadlock-2.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ teardown
1010
}
1111

1212
session"s1"
13-
setup {begin; }
13+
setup {begin;SETdeadlock_timeout='10s';}
1414
step"s1u1" {updatetsetb=11wherea=1; }
1515
step"s1atxb" {beginautonomous; }
1616
step"s1u2" {updatetsetb=21wherea=2; }
1717
step"s1atxc" {commit; }
1818
step"s1c" {commit; }
1919

2020
session"s2"
21-
setup {begin; }
21+
setup {begin;SETdeadlock_timeout='10s';}
2222
step"s2u2" {updatetsetb=22wherea=2; }
2323
step"s2u1" {updatetsetb=11wherea=1; }
2424
step"s2c" {commit; }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp