Skip to content

Commit 4aaa7f9

Browse files
committed
Add comments
1 parent c6cd650 commit 4aaa7f9

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
#define CFS_DISABLE_TIMEOUT 1000 /* milliseconds */
1515
#define CFS_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
#define CFS_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
#define CFS_MIN_COMPRESSED_SIZE(size) ((size)*2/3)
2027

2128
/* Possible options for compression algorithm choice */
@@ -40,7 +47,8 @@
4047
#define CFS_RC4_DROP_N 3072
4148
#define CFS_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
typedef uint64 inode_t;
4553

4654
#define CFS_INODE_SIZE(inode) ((uint32)((inode) >> 32))
@@ -65,32 +73,41 @@ typedef struct
6573
uint64 processedBytes;
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_flag gc_started;
7281
/* Number of active garbage collection background workers. */
7382
pg_atomic_uint32 n_active_gc;
7483
/* Max number of garbage collection background workers.
7584
* Duplicates 'cfs_gc_workers' global variable. */
7685
int n_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
int max_iterations;
89+
/* Flag for temporary didsabling GC */
7990
bool gc_enabled;
91+
/* CFS GC statatistic */
8092
CfsStatistic gc_stat;
93+
/* Encryption key */
8194
uint8 cipher_key[CFS_CIPHER_KEY_SIZE];
8295
} CfsState;
8396

97+
98+
/* Map file format (mmap in memory and shared by all backends) */
8499
typedef struct
85100
{
86-
/* TODO Add comment*/
101+
/* Physical size of the file (size of the file on disk) */
87102
pg_atomic_uint32 physSize;
88-
/* TODO Add comment*/
103+
/* Virtual size of the file (Postgres page size (8k) * number of used pages) */
89104
pg_atomic_uint32 virtSize;
90-
/* TODO Add comment. What is the difference with physSize?*/
105+
/* Total size of used pages. File may contain multiple versions of the same page, this is why physSize can be larger than usedSize */
91106
pg_atomic_uint32 usedSize;
107+
/* Lock used to synchronize access to the file */
92108
pg_atomic_uint32 lock;
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_t postmasterPid;
95112
/* Each pass of GC updates generation of the map */
96113
uint64 generation;

0 commit comments

Comments
 (0)