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

Commitff42c83

Browse files
committed
cleanup of cfs.c
1 parent2f2ad8a commitff42c83

File tree

1 file changed

+66
-53
lines changed
  • src/backend/storage/file

1 file changed

+66
-53
lines changed

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

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ bool cfs_control_gc(bool enabled)
10531053
/* ----------------------------------------------------------------
10541054
*Section 5: Garbage collection user's functions.
10551055
*
1056-
* TODO adddescription. reorder functions.
1056+
* TODO adddescriptions
10571057
* ----------------------------------------------------------------
10581058
*/
10591059
PG_FUNCTION_INFO_V1(cfs_start_gc);
@@ -1083,7 +1083,8 @@ Datum cfs_start_gc(PG_FUNCTION_ARGS)
10831083
cfs_state->n_workers=PG_GETARG_INT32(0);
10841084
handles= (BackgroundWorkerHandle**)palloc(cfs_state->n_workers*sizeof(BackgroundWorkerHandle*));
10851085

1086-
for (i=0;i<cfs_state->n_workers;i++) {
1086+
for (i=0;i<cfs_state->n_workers;i++)
1087+
{
10871088
BackgroundWorkerworker;
10881089
MemSet(&worker,0,sizeof(worker));
10891090
sprintf(worker.bgw_name,"cfs-worker-%d",i);
@@ -1092,13 +1093,12 @@ Datum cfs_start_gc(PG_FUNCTION_ARGS)
10921093
worker.bgw_restart_time=BGW_NEVER_RESTART;
10931094
worker.bgw_main=cfs_gc_bgworker_main;
10941095
worker.bgw_main_arg=Int32GetDatum(i);
1095-
if (!RegisterDynamicBackgroundWorker(&worker,&handles[i])) {
1096+
if (!RegisterDynamicBackgroundWorker(&worker,&handles[i]))
10961097
break;
1097-
}
10981098
}
1099-
for (j=0;j<i;j++) {
1099+
for (j=0;j<i;j++)
11001100
WaitForBackgroundWorkerShutdown(handles[j]);
1101-
}
1101+
11021102
pfree(handles);
11031103
pg_atomic_clear_flag(&cfs_state->gc_started);
11041104
}
@@ -1122,35 +1122,41 @@ Datum cfs_estimate(PG_FUNCTION_ARGS)
11221122
Relationrel=try_relation_open(oid,AccessShareLock);
11231123
doubleavgRatio=0.0;
11241124

1125-
if (rel!=NULL) {
1125+
if (rel!=NULL)
1126+
{
11261127
char*path=relpathbackend(rel->rd_node,rel->rd_backend,MAIN_FORKNUM);
11271128
intfd=open(path,O_RDONLY|PG_BINARY,0);
1128-
if (fd >=0) {
1129+
1130+
if (fd >=0)
1131+
{
11291132
inti;
11301133
charorigBuffer[BLCKSZ];
11311134
charcompressedBuffer[CFS_MAX_COMPRESSED_SIZE(BLCKSZ)];
11321135
uint32compressedSize;
11331136
off_trc=lseek(fd,0,SEEK_END);
1134-
if (rc >=0) {
1137+
1138+
if (rc >=0)
1139+
{
11351140
off_tstep=rc /BLCKSZ /CFS_ESTIMATE_PROBES*BLCKSZ;
1136-
for (i=0;i<CFS_ESTIMATE_PROBES;i++) {
1141+
for (i=0;i<CFS_ESTIMATE_PROBES;i++)
1142+
{
11371143
rc=lseek(fd,step*i,SEEK_SET);
1138-
if (rc<0) {
1144+
if (rc<0)
11391145
break;
1140-
}
1141-
if (!cfs_read_file(fd,origBuffer,BLCKSZ)) {
1146+
1147+
if (!cfs_read_file(fd,origBuffer,BLCKSZ))
11421148
break;
1143-
}
1144-
compressedSize= (uint32)cfs_compress(compressedBuffer,sizeof(compressedBuffer),origBuffer,BLCKSZ);
1145-
if (compressedSize>0&&compressedSize<CFS_MIN_COMPRESSED_SIZE(BLCKSZ)) {
1149+
1150+
compressedSize= (uint32)cfs_compress(compressedBuffer,
1151+
sizeof(compressedBuffer),origBuffer,BLCKSZ);
1152+
if (compressedSize>0&&compressedSize<CFS_MIN_COMPRESSED_SIZE(BLCKSZ))
11461153
avgRatio+= (double)BLCKSZ/compressedSize;
1147-
}else {
1154+
else
11481155
avgRatio+=1;
1149-
}
11501156
}
1151-
if (i!=0) {
1157+
1158+
if (i!=0)
11521159
avgRatio /=i;
1153-
}
11541160
}
11551161
close(fd);
11561162
}
@@ -1166,39 +1172,43 @@ Datum cfs_compression_ratio(PG_FUNCTION_ARGS)
11661172
uint64virtSize=0;
11671173
uint64physSize=0;
11681174

1169-
if (rel!=NULL) {
1175+
if (rel!=NULL)
1176+
{
11701177
char*path=relpathbackend(rel->rd_node,rel->rd_backend,MAIN_FORKNUM);
11711178
char*map_path= (char*)palloc(strlen(path)+16);
11721179
inti=0;
11731180

1174-
while (true) {
1181+
while (true)
1182+
{
11751183
intmd;
11761184
FileMap*map;
11771185

1178-
if (i==0) {
1179-
sprintf(map_path,"%s.cfm",path);
1180-
}else {
1181-
sprintf(map_path,"%s.%u.cfm",path,i);
1182-
}
1186+
if (i==0)
1187+
sprintf(map_path,"%s.cfm",path);
1188+
else
1189+
sprintf(map_path,"%s.%u.cfm",path,i);
1190+
11831191
md=open(map_path,O_RDWR|PG_BINARY,0);
1184-
if (md<0) {
1192+
1193+
if (md<0)
11851194
break;
1186-
}
1195+
11871196
map=cfs_mmap(md);
1188-
if (map==MAP_FAILED) {
1197+
if (map==MAP_FAILED)
1198+
{
11891199
elog(LOG,"cfs_compression_ration failed to map file %s: %m",map_path);
11901200
close(md);
11911201
break;
11921202
}
1203+
11931204
virtSize+=pg_atomic_read_u32(&map->virtSize);
11941205
physSize+=pg_atomic_read_u32(&map->physSize);
11951206

1196-
if (cfs_munmap(map)<0) {
1207+
if (cfs_munmap(map)<0)
11971208
elog(LOG,"CFS failed to unmap file %s: %m",map_path);
1198-
}
1199-
if (close(md)<0) {
1209+
if (close(md)<0)
12001210
elog(LOG,"CFS failed to close file %s: %m",map_path);
1201-
}
1211+
12021212
i+=1;
12031213
}
12041214
pfree(path);
@@ -1215,39 +1225,41 @@ Datum cfs_fragmentation(PG_FUNCTION_ARGS)
12151225
uint64usedSize=0;
12161226
uint64physSize=0;
12171227

1218-
if (rel!=NULL) {
1228+
if (rel!=NULL)
1229+
{
12191230
char*path=relpathbackend(rel->rd_node,rel->rd_backend,MAIN_FORKNUM);
12201231
char*map_path= (char*)palloc(strlen(path)+16);
12211232
inti=0;
12221233

1223-
while (true) {
1234+
while (true)
1235+
{
12241236
intmd;
12251237
FileMap*map;
12261238

1227-
if (i==0) {
1228-
sprintf(map_path,"%s.cfm",path);
1229-
}else {
1230-
sprintf(map_path,"%s.%u.cfm",path,i);
1231-
}
1239+
if (i==0)
1240+
sprintf(map_path,"%s.cfm",path);
1241+
else
1242+
sprintf(map_path,"%s.%u.cfm",path,i);
1243+
12321244
md=open(map_path,O_RDWR|PG_BINARY,0);
1233-
if (md<0) {
1245+
if (md<0)
12341246
break;
1235-
}
1247+
12361248
map=cfs_mmap(md);
1237-
if (map==MAP_FAILED) {
1249+
if (map==MAP_FAILED)
1250+
{
12381251
elog(LOG,"cfs_compression_ration failed to map file %s: %m",map_path);
12391252
close(md);
12401253
break;
12411254
}
12421255
usedSize+=pg_atomic_read_u32(&map->usedSize);
12431256
physSize+=pg_atomic_read_u32(&map->physSize);
12441257

1245-
if (cfs_munmap(map)<0) {
1258+
if (cfs_munmap(map)<0)
12461259
elog(LOG,"CFS failed to unmap file %s: %m",map_path);
1247-
}
1248-
if (close(md)<0) {
1260+
if (close(md)<0)
12491261
elog(LOG,"CFS failed to close file %s: %m",map_path);
1250-
}
1262+
12511263
i+=1;
12521264
}
12531265
pfree(path);
@@ -1261,21 +1273,22 @@ Datum cfs_gc_relation(PG_FUNCTION_ARGS)
12611273
{
12621274
cfs_gc_processed_segments=0;
12631275

1264-
if (cfs_gc_workers==0&&pg_atomic_test_set_flag(&cfs_state->gc_started))
1276+
if (cfs_gc_workers==0&&pg_atomic_test_set_flag(&cfs_state->gc_started))
12651277
{
12661278
Oidoid=PG_GETARG_OID(0);
12671279
Relationrel=try_relation_open(oid,AccessShareLock);
12681280

1269-
if (rel!=NULL) {
1281+
if (rel!=NULL)
1282+
{
12701283
char*path=relpathbackend(rel->rd_node,rel->rd_backend,MAIN_FORKNUM);
12711284
char*map_path= (char*)palloc(strlen(path)+16);
12721285
inti=0;
12731286
sprintf(map_path,"%s.cfm",path);
12741287

1275-
while (true) {
1276-
if (!cfs_gc_file(map_path)) {
1288+
while (true)
1289+
{
1290+
if (!cfs_gc_file(map_path))
12771291
break;
1278-
}
12791292
sprintf(map_path,"%s.%u.cfm",path,++i);
12801293
}
12811294
pfree(path);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp