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

Commit55eac74

Browse files
committed
Rewrite check for fiel sizse overflow
1 parente18cea1 commit55eac74

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,16 @@ int cfs_munmap(FileMap* map)
470470
*/
471471
uint32cfs_alloc_page(FileMap*map,uint32oldSize,uint32newSize)
472472
{
473-
pg_atomic_fetch_add_u32(&map->hdr.usedSize,newSize-oldSize);
474-
returnpg_atomic_fetch_add_u32(&map->hdr.physSize,newSize);
475-
}
473+
uint32oldPhysSize=pg_atomic_read_u32(&map->hdr.physSize);
474+
uint32newPhysSize;
476475

477-
voidcfs_undo_alloc_page(FileMap*map,uint32oldSize,uint32newSize)
478-
{
479-
pg_atomic_fetch_sub_u32(&map->hdr.usedSize,newSize-oldSize);
480-
pg_atomic_fetch_sub_u32(&map->hdr.physSize,newSize);
476+
do {
477+
newPhysSize=oldPhysSize+newSize;
478+
if (oldPhysSize>newPhysSize)
479+
elog(ERROR,"CFS: segment file exceed 4Gb limit");
480+
}while (!pg_atomic_compare_exchange_u32(&map->hdr.physSize,&oldPhysSize,newPhysSize));
481+
482+
returnoldPhysSize;
481483
}
482484

483485
/*

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,10 +1980,6 @@ FileWrite(File file, char *buffer, int amount)
19801980
* because we want to write all updated pages sequentially
19811981
*/
19821982
pos=cfs_alloc_page(map,CFS_INODE_SIZE(inode),compressedSize);
1983-
if (pos>CFS_RED_LINE) {
1984-
cfs_undo_alloc_page(map,CFS_INODE_SIZE(inode),compressedSize);
1985-
elog(ERROR,"CFS: segment file exceed 4Gb limit");
1986-
}
19871983

19881984
inode=CFS_INODE(compressedSize,pos);
19891985
buffer=compressedBuffer;
@@ -2110,7 +2106,7 @@ FileWrite(File file, char *buffer, int amount)
21102106
{
21112107
elog(LOG,"CFS: backend %d forced to perform GC on file %s block %u because it's size exceed %u bytes",
21122108
MyProcPid,VfdCache[file].fileName, (uint32)(VfdCache[file].seekPos /BLCKSZ),pos);
2113-
cfs_gc_segment(VfdCache[file].fileName,pos+amount<CFS_YELLOW_LINE);
2109+
cfs_gc_segment(VfdCache[file].fileName,pos+amount<CFS_RED_LINE);
21142110
}
21152111
}
21162112
returnreturnCode;

‎src/include/storage/cfs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include"port/atomics.h"
77
#include"storage/rijndael.h"
88

9-
#defineCFS_VERSION "0.43"
9+
#defineCFS_VERSION "0.45"
1010

1111
#defineCFS_GC_LOCK 0x10000000
1212

@@ -52,8 +52,7 @@ typedef uint64 inode_t;
5252
#defineCFS_INODE(size,offs) (((inode_t)(size) << 32) | (offs))
5353

5454
#defineCFS_IMPLICIT_GC_THRESHOLD 0x80000000U/* 2Gb */
55-
#defineCFS_YELLOW_LINE 0xC0000000U/* 3Gb */
56-
#defineCFS_RED_LINE 0xFFF00000U/* 4Gb - page_size*100 */
55+
#defineCFS_RED_LINE 0xC0000000U/* 3Gb */
5756

5857
size_tcfs_compress(void*dst,size_tdst_size,voidconst*src,size_tsrc_size);
5958
size_tcfs_decompress(void*dst,size_tdst_size,voidconst*src,size_tsrc_size);
@@ -125,7 +124,6 @@ typedef struct
125124
voidcfs_lock_file(FileMap*map,charconst*path);
126125
voidcfs_unlock_file(FileMap*map);
127126
uint32cfs_alloc_page(FileMap*map,uint32oldSize,uint32newSize);
128-
voidcfs_undo_alloc_page(FileMap*map,uint32oldSize,uint32newSize);
129127
voidcfs_extend(FileMap*map,uint32pos);
130128
boolcfs_control_gc(boolenabled);
131129
intcfs_msync(FileMap*map);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp