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

Commit4aaa7f9

Browse files
committed
Add comments
1 parentc6cd650 commit4aaa7f9

File tree

2 files changed

+27
-15
lines changed
  • src

2 files changed

+27
-15
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,11 +1901,12 @@ FileWrite(File file, char *buffer, int amount)
19011901
inode=CFS_INODE(compressedSize,pos);
19021902
buffer=compressedBuffer;
19031903
amount=compressedSize;
1904+
/* cfs_encrypt will check if encryption is actually needed */
19041905
cfs_encrypt(buffer,VfdCache[file].seekPos,amount);
19051906
}
19061907
else
19071908
{
1908-
if (cfs_encryption)
1909+
if (cfs_encryption)/* we need to use buffer to perform encryption, so check if it is required */
19091910
{
19101911
memcpy(compressedBuffer,buffer,BLCKSZ);
19111912
buffer=compressedBuffer;
@@ -1946,12 +1947,6 @@ FileWrite(File file, char *buffer, int amount)
19461947
{
19471948
if (returnCode==amount)
19481949
{
1949-
/* TODO. Is this comment still actual?
1950-
* Verify that there is no race condition
1951-
bool rc = pg_atomic_compare_exchange_u64((pg_atomic_uint64*)&VfdCache[file].map->inodes[VfdCache[file].seekPos / BLCKSZ],
1952-
&prev_inode, inode);
1953-
Assert(rc);
1954-
*/
19551950
VfdCache[file].map->inodes[VfdCache[file].seekPos /BLCKSZ]=inode;
19561951
VfdCache[file].seekPos+=BLCKSZ;
19571952
cfs_extend(VfdCache[file].map,VfdCache[file].seekPos);

‎src/include/storage/cfs.h

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
#defineCFS_DISABLE_TIMEOUT 1000/* milliseconds */
1515
#defineCFS_ESTIMATE_PROBES 10
1616

17-
/* TODO Add comments */
17+
/* Maximal size of buffer for compressing (size) bytes where (size) is equal to PostgreSQL page size.
18+
* Some compression algorithms requires to provide buffer large enough for worst case and immediately returns error is buffer is not enough.
19+
* Accurate calculation of required buffer size is not needed here and doubling buffer size works for all used compression algorithms. */
1820
#defineCFS_MAX_COMPRESSED_SIZE(size) ((size)*2)
21+
22+
/* Minimal compression ratio when compression is expected to be reasonable.
23+
* Right now it is hardcoded and equal to 2/3 of original size. If compressed image is larger than 2/3 of original image,
24+
* then uncompressed version of the page is stored.
25+
*/
1926
#defineCFS_MIN_COMPRESSED_SIZE(size) ((size)*2/3)
2027

2128
/* Possible options for compression algorithm choice */
@@ -40,7 +47,8 @@
4047
#defineCFS_RC4_DROP_N3072
4148
#defineCFS_CIPHER_KEY_SIZE 256
4249

43-
/* TODO Add comment */
50+
/* Inode type is 64 bit word storing offset and compressed size of the page. Size of Postgres segment is 1Gb, so using 32 bit offset is enough even through
51+
* with compression size of compressed file can become larger than 1Gb if GC id disabled for long time */
4452
typedefuint64inode_t;
4553

4654
#defineCFS_INODE_SIZE(inode) ((uint32)((inode) >> 32))
@@ -65,32 +73,41 @@ typedef struct
6573
uint64processedBytes;
6674
}CfsStatistic;
6775

76+
/* CFS control state (maintained in shared memory) *.
6877
typedef struct
6978
{
70-
/*TODO Add comment */
79+
/*Flag indicating that GC is in progress. It is used to prevent more than one GC. */
7180
pg_atomic_flaggc_started;
7281
/* Number of active garbage collection background workers. */
7382
pg_atomic_uint32n_active_gc;
7483
/* Max number of garbage collection background workers.
7584
* Duplicates 'cfs_gc_workers' global variable. */
7685
intn_workers;
77-
/* TODO Add comment */
86+
/* Maximal number of iterations with GC should perform. Automatically started GC performs infinite number of iterations.
87+
* Manually started GC performs just one iteration. */
7888
intmax_iterations;
89+
/* Flag for temporary didsabling GC */
7990
boolgc_enabled;
91+
/* CFS GC statatistic */
8092
CfsStatisticgc_stat;
93+
/* Encryption key */
8194
uint8cipher_key[CFS_CIPHER_KEY_SIZE];
8295
}CfsState;
8396

97+
98+
/* Map file format (mmap in memory and shared by all backends) */
8499
typedefstruct
85100
{
86-
/*TODO Add comment*/
101+
/*Physical size of the file (size of the file on disk)*/
87102
pg_atomic_uint32physSize;
88-
/*TODO Add comment*/
103+
/* Virtual size of the file (Postgres page size (8k) * number of used pages)*/
89104
pg_atomic_uint32virtSize;
90-
/*TODO Add comment. What isthedifference withphysSize?*/
105+
/*Total size of used pages. File may contain multiple versions ofthesame page, this is whyphysSize can be larger than usedSize*/
91106
pg_atomic_uint32usedSize;
107+
/* Lock used to synchronize access to the file */
92108
pg_atomic_uint32lock;
93-
/* TODO Add comment */
109+
/* PID (process identifier) of postmaster. We check it at open time to revoke lock in case when postgres is restarted.
110+
* TODO: not so reliable because it can happen that occasionally postmaster will be given the same PID */
94111
pid_tpostmasterPid;
95112
/* Each pass of GC updates generation of the map */
96113
uint64generation;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp