-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathaomd.c
More file actions
730 lines (621 loc) · 18.7 KB
/
aomd.c
File metadata and controls
730 lines (621 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*-------------------------------------------------------------------------
*
* aomd.c
* This code manages append only relations that reside on magnetic disk.
* It serves the same general purpose as smgr/md.c however we introduce
* AO specific file access functions mainly because would like to bypass
* md.c's and bgwriter's fsyncing. AO relations also use a non constant
* block number to file segment mapping unlike heap relations.
*
* As of now we still let md.c create and unlink AO relations for us. This
* may need to change if inconsistencies arise.
*
* Portions Copyright (c) 2008, Greenplum Inc.
* Portions Copyright (c) 2012-Present VMware, Inc. or its affiliates.
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/access/appendonly/aomd.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/file.h>
#include "access/aomd.h"
#include "access/aocssegfiles.h"
#include "access/appendonlytid.h"
#include "access/appendonlywriter.h"
#include "access/appendonly_compaction.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/pg_appendonly.h"
#include "catalog/pg_attribute_encoding.h"
#include "cdb/cdbappendonlystorage.h"
#include "cdb/cdbappendonlyxlog.h"
#include "crypto/bufenc.h"
#include "commands/progress.h"
#include "common/relpath.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/sync.h"
#include "utils/faultinjector.h"
#include "utils/guc.h"
#define SEGNO_SUFFIX_LENGTH 12
static void mdunlink_ao_base_relfile(void *ctx);
static bool mdunlink_ao_perFile(const int segno, void *ctx);
static bool copy_append_only_data_perFile(const int segno, void *ctx);
static bool truncate_ao_perFile(const int segno, void *ctx);
static uint64 ao_segfile_get_physical_size(Relation aorel, int segno, FileNumber filenum);
int
AOSegmentFilePathNameLen(Relation rel)
{
char *basepath;
int len;
/* Get base path for this relation file */
basepath = relpathbackend(rel->rd_node, rel->rd_backend, MAIN_FORKNUM);
/*
* The basepath will be the RelFileNode number. Optional part is dot "." plus
* 6 digit segment file number.
*/
len = strlen(basepath) + 8; // Generous.
pfree(basepath);
return len;
}
/*
* Formats an Append Only relation file segment file name.
*
* The filepathname parameter assume sufficient space.
*/
void
FormatAOSegmentFileName(char *basepath,
int segno,
int filenum,
int32 *fileSegNo,
char *filepathname)
{
int pseudoSegNo;
Assert(segno >= 0);
Assert(segno <= AOTupleId_MaxSegmentFileNum);
if (filenum == InvalidFileNumber)
{
/*
* Row oriented Append-Only.
*/
pseudoSegNo = segno;
}
else
{
/*
* Column oriented Append-only.
*/
pseudoSegNo = ((filenum - 1) * AOTupleId_MultiplierSegmentFileNum) + segno;
}
*fileSegNo = pseudoSegNo;
if (pseudoSegNo > 0)
{
sprintf(filepathname, "%s.%u", basepath, pseudoSegNo);
}
else
strcpy(filepathname, basepath);
}
/*
* Make an Append Only relation file segment file name.
*
* The filepathname parameter assume sufficient space.
*/
void
MakeAOSegmentFileName(Relation rel,
int segno,
int filenum,
int32 *fileSegNo,
char *filepathname)
{
char *basepath;
int32 fileSegNoLocal;
/* Get base path for this relation file */
basepath = relpathbackend(rel->rd_node, rel->rd_backend, MAIN_FORKNUM);
FormatAOSegmentFileName(basepath, segno, filenum, &fileSegNoLocal, filepathname);
*fileSegNo = fileSegNoLocal;
pfree(basepath);
}
/*
* Open an Append Only relation file segment
*
* The fd module's PathNameOpenFile() is used to open the file, so the
* the File* routines can be used to read, write, close, etc, the file.
*/
File
OpenAOSegmentFile(Relation rel,
char *filepathname,
int64 logicalEof)
{
int fileFlags = O_RDWR | PG_BINARY;
File fd;
errno = 0;
RelationOpenSmgr(rel);
fd = rel->rd_smgr->smgr_ao->smgr_AORelOpenSegFile(RelationGetRelid(rel), filepathname, fileFlags);
if (fd < 0)
{
if (logicalEof == 0 && errno == ENOENT)
return -1;
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open Append-Only segment file \"%s\": %m",
filepathname),
errdetail("logicalEof for open operation: %ld", logicalEof)));
}
return fd;
}
/*
* Close an Append Only relation file segment
*/
void
CloseAOSegmentFile(File fd, Relation rel)
{
Assert(fd > 0);
RelationOpenSmgr(rel);
rel->rd_smgr->smgr_ao->smgr_FileClose(fd);
}
/*
* Truncate all bytes from offset to end of file.
*/
void
TruncateAOSegmentFile(File fd, Relation rel, int32 segFileNum, int64 offset, AOVacuumRelStats *vacrelstats)
{
char *relname = RelationGetRelationName(rel);
int64 filesize_before;
Assert(fd > 0);
Assert(offset >= 0);
RelationOpenSmgr(rel);
filesize_before = rel->rd_smgr->smgr_ao->smgr_FileSize(fd);
if (filesize_before < offset)
ereport(ERROR,
(errmsg("\"%s\": file size smaller than logical eof: %m",
relname)));
/*
* Call the 'fd' module with a 64-bit length since AO segment files
* can be multi-gigabyte to the terabytes...
*/
if (rel->rd_smgr->smgr_ao->smgr_FileTruncate(fd, offset, WAIT_EVENT_DATA_FILE_TRUNCATE) != 0)
ereport(ERROR,
(errmsg("\"%s\": failed to truncate data after eof: %m",
relname)));
if (vacrelstats)
{
/* report heap-equivalent blocks vacuumed */
vacrelstats->nbytes_truncated += filesize_before - offset;
pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED,
RelationGuessNumberOfBlocksFromSize(vacrelstats->nbytes_truncated));
}
if (XLogIsNeeded() && RelationNeedsWAL(rel))
xlog_ao_truncate(rel->rd_node, segFileNum, offset);
SIMPLE_FAULT_INJECTOR("appendonly_after_truncate_segment_file");
if (file_truncate_hook)
{
RelFileNodeBackend rnode;
rnode.node = rel->rd_node;
rnode.backend = rel->rd_backend;
(*file_truncate_hook)(rnode);
}
}
struct mdunlink_ao_callback_ctx
{
RelFileNode rnode; /* used to register forget request */
char *segPath;
char *segpathSuffixPosition;
bool isRedo;
};
struct truncate_ao_callback_ctx
{
char *segPath;
char *segpathSuffixPosition;
Relation rel;
};
void
mdunlink_ao(RelFileNodeBackend rnode, ForkNumber forkNumber, bool isRedo)
{
const char *path = relpath(rnode, forkNumber);
/*
* Unlogged AO tables have INIT_FORK, in addition to MAIN_FORK. It is
* created once, regardless of the number of segment files (or the number
* of columns for column-oriented tables). Sync requests for INIT_FORKs
* are not remembered, so they need not be forgotten.
*/
if (forkNumber == INIT_FORKNUM)
{
path = relpath(rnode, forkNumber);
if (unlink(path) < 0 && errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m", path)));
}
/* This storage manager is not concerned with forks other than MAIN_FORK */
else if (forkNumber == MAIN_FORKNUM)
{
int pathSize = strlen(path);
char *segPath = (char *) palloc(pathSize + SEGNO_SUFFIX_LENGTH);
char *segPathSuffixPosition = segPath + pathSize;
struct mdunlink_ao_callback_ctx unlinkFiles;
unlinkFiles.isRedo = isRedo;
unlinkFiles.rnode = rnode.node;
strncpy(segPath, path, pathSize);
unlinkFiles.segPath = segPath;
unlinkFiles.segpathSuffixPosition = segPathSuffixPosition;
mdunlink_ao_base_relfile(&unlinkFiles);
ao_foreach_extent_file(mdunlink_ao_perFile, &unlinkFiles);
pfree(segPath);
}
pfree((void *) path);
}
/*
* Delete or truncate segfile 0. Note: There is no <relfilenode>.0 file. The
* segfile 0 is the same as base relfilenode for row-oriented AO. For
* column-oriented AO, the segno 0 for the first column corresponds to base
* relfilenode. See also: ao_foreach_extent_file.
*/
static void
mdunlink_ao_base_relfile(void *ctx)
{
FileTag tag;
struct mdunlink_ao_callback_ctx *unlinkFiles =
(struct mdunlink_ao_callback_ctx *)ctx;
const char *baserel = unlinkFiles->segPath;
*unlinkFiles->segpathSuffixPosition = '\0';
if (unlinkFiles->isRedo)
{
/* First, forget any pending sync requests for the first segment */
INIT_FILETAG(tag, unlinkFiles->rnode, MAIN_FORKNUM, 0,
SYNC_HANDLER_AO);
RegisterSyncRequest(&tag, SYNC_FORGET_REQUEST, true);
if (unlink(baserel) != 0)
{
/* ENOENT is expected after the end of the extensions */
if (errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m",
baserel)));
}
}
else
{
int fd;
int ret;
/* Register request to unlink first segment later */
INIT_FILETAG(tag, unlinkFiles->rnode, MAIN_FORKNUM, 0,
SYNC_HANDLER_AO);
RegisterSyncRequest(&tag, SYNC_UNLINK_REQUEST, true /* retryOnError */ );
fd = OpenTransientFile(baserel, O_RDWR | PG_BINARY);
if (fd >= 0)
{
int save_errno;
ret = ftruncate(fd, 0);
save_errno = errno;
CloseTransientFile(fd);
errno = save_errno;
}
else
ret = -1;
if (ret < 0 && errno != ENOENT)
{
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not truncate file \"%s\": %m", baserel)));
}
}
}
static bool
mdunlink_ao_perFile(const int segno, void *ctx)
{
FileTag tag;
const struct mdunlink_ao_callback_ctx *unlinkFiles = ctx;
char *segPath = unlinkFiles->segPath;
char *segPathSuffixPosition = unlinkFiles->segpathSuffixPosition;
Assert (segno > 0);
sprintf(segPathSuffixPosition, ".%u", segno);
/* First, forget any pending sync requests for the first segment */
INIT_FILETAG(tag, unlinkFiles->rnode, MAIN_FORKNUM, segno,
SYNC_HANDLER_AO);
RegisterSyncRequest(&tag, SYNC_FORGET_REQUEST, true);
/* Next unlink the file */
if (unlink(segPath) != 0)
{
/* ENOENT is expected after the end of the extensions */
if (errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m", segPath)));
else
return false;
}
return true;
}
static void
copy_file(char *srcsegpath, char *dstsegpath,
RelFileNode dst, SMgrRelation srcSMGR, SMgrRelation dstSMGR,
int segfilenum, bool use_wal)
{
File srcFile;
File dstFile;
int64 left;
off_t offset;
char *buffer = palloc(BLCKSZ);
int dstflags;
srcFile = srcSMGR->smgr_ao->smgr_AORelOpenSegFile(InvalidOid, srcsegpath, O_RDONLY | PG_BINARY);
if (srcFile < 0)
ereport(ERROR,
(errcode_for_file_access(),
(errmsg("could not open file %s: %m", srcsegpath))));
dstflags = O_WRONLY | O_EXCL | PG_BINARY;
/*
* .0 relfilenode is expected to exist before calling this
* function. Caller calls RelationCreateStorage() which creates the base
* file for the relation. Hence use different flag for the same.
*/
if (segfilenum)
dstflags |= O_CREAT;
dstFile = dstSMGR->smgr_ao->smgr_AORelOpenSegFile(InvalidOid, dstsegpath, dstflags);
if (dstFile < 0)
ereport(ERROR,
(errcode_for_file_access(),
(errmsg("could not create destination file %s: %m", dstsegpath))));
left = srcSMGR->smgr_ao->smgr_FileDiskSize(srcFile);
if (left < 0)
ereport(ERROR,
(errcode_for_file_access(),
(errmsg("could not seek to end of file %s: %m", srcsegpath))));
offset = 0;
while(left > 0)
{
int len;
CHECK_FOR_INTERRUPTS();
len = Min(left, BLCKSZ);
if (srcSMGR->smgr_ao->smgr_FileRead(srcFile, buffer, len, offset, WAIT_EVENT_DATA_FILE_READ) != len)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read %d bytes from file \"%s\": %m",
len, srcsegpath)));
if (dstSMGR->smgr_ao->smgr_FileWrite(dstFile, buffer, len, offset, WAIT_EVENT_DATA_FILE_WRITE) != len)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write %d bytes to file \"%s\": %m",
len, dstsegpath)));
if (use_wal)
xlog_ao_insert(dst, segfilenum, offset, buffer, len);
offset += len;
left -= len;
}
if (dstSMGR->smgr_ao->smgr_FileSync(dstFile, WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not fsync file \"%s\": %m",
dstsegpath)));
srcSMGR->smgr_ao->smgr_FileClose(srcFile);
dstSMGR->smgr_ao->smgr_FileClose(dstFile);
pfree(buffer);
}
struct copy_append_only_data_callback_ctx {
char *srcPath;
char *dstPath;
SMgrRelation srcSMGR;
SMgrRelation dstSMGR;
RelFileNode src;
RelFileNode dst;
bool useWal;
};
/*
* Like copy_relation_data(), but for AO tables.
*
*/
void
copy_append_only_data(RelFileNode src, RelFileNode dst,
SMgrRelation srcSMGR, SMgrRelation dstSMGR,
BackendId backendid, char relpersistence)
{
char *srcPath;
char *dstPath;
bool useWal;
struct copy_append_only_data_callback_ctx copyFiles = { 0 };
/*
* We need to log the copied data in WAL iff WAL archiving/streaming is
* enabled AND it's a permanent relation.
*/
useWal = XLogIsNeeded() && relpersistence == RELPERSISTENCE_PERMANENT;
srcPath = relpathbackend(src, backendid, MAIN_FORKNUM);
dstPath = relpathbackend(dst, backendid, MAIN_FORKNUM);
copy_file(srcPath, dstPath, dst, srcSMGR, dstSMGR, 0, useWal);
copyFiles.srcPath = srcPath;
copyFiles.dstPath = dstPath;
copyFiles.srcSMGR = srcSMGR;
copyFiles.dstSMGR = dstSMGR;
copyFiles.src = src;
copyFiles.dst = dst;
copyFiles.useWal = useWal;
ao_foreach_extent_file(copy_append_only_data_perFile, ©Files);
if (file_extend_hook)
{
RelFileNodeBackend rnode;
rnode.node = dst;
rnode.backend = backendid;
(*file_extend_hook)(rnode);
}
}
static bool
copy_append_only_data_perFile(const int segno, void *ctx)
{
const struct copy_append_only_data_callback_ctx *copyFiles = ctx;
char srcSegPath[MAXPGPATH + 12];
char dstSegPath[MAXPGPATH + 12];
sprintf(srcSegPath, "%s.%u", copyFiles->srcPath, segno);
if (access(srcSegPath, F_OK) != 0)
{
/* ENOENT is expected after the end of the extensions */
if (errno != ENOENT)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("access failed for file \"%s\": %m", srcSegPath)));
return false;
}
sprintf(dstSegPath, "%s.%u", copyFiles->dstPath, segno);
copy_file(srcSegPath, dstSegPath, copyFiles->dst, copyFiles->srcSMGR, copyFiles->dstSMGR, segno, copyFiles->useWal);
return true;
}
/*
* ao_truncate_one_rel
*
* This routine deletes all data within the specified ao relation.
*/
void
ao_truncate_one_rel(Relation rel)
{
char *basepath;
char *segPath;
char *segPathSuffixPosition;
struct truncate_ao_callback_ctx truncateFiles = { 0 };
int pathSize;
/* Get base path for this relation file */
basepath = relpathbackend(rel->rd_node, rel->rd_backend, MAIN_FORKNUM);
pathSize = strlen(basepath);
segPath = (char *) palloc(pathSize + SEGNO_SUFFIX_LENGTH);
segPathSuffixPosition = segPath + pathSize;
strncpy(segPath, basepath, pathSize);
truncateFiles.segPath = segPath;
truncateFiles.segpathSuffixPosition = segPathSuffixPosition;
truncateFiles.rel = rel;
/*
* Truncate the actual file.
*
* Segfile 0 first, ao_foreach_extent_file() doesn't invoke the
* callback for it.
*/
truncate_ao_perFile(0, &truncateFiles);
ao_foreach_extent_file(truncate_ao_perFile, &truncateFiles);
pfree(segPath);
pfree(basepath);
}
/*
* Truncate a specific segment file of ao relation.
*/
static bool
truncate_ao_perFile(const int segno, void *ctx)
{
File fd;
Relation aorel;
const struct truncate_ao_callback_ctx *truncateFiles = ctx;
char *segPath = truncateFiles->segPath;
char *segPathSuffixPosition = truncateFiles->segpathSuffixPosition;
aorel = truncateFiles->rel;
if (segno > 0)
sprintf(segPathSuffixPosition, ".%u", segno);
else
*segPathSuffixPosition = '\0';
fd = OpenAOSegmentFile(aorel, segPath, 0);
if (fd >= 0)
{
TruncateAOSegmentFile(fd, aorel, segno, 0, NULL);
CloseAOSegmentFile(fd, aorel);
}
else
{
/*
* we traverse possible segment files of AO/AOCS tables and call
* truncate_ao_perFile to truncate them. It is ok that some files do not exist
*/
return false;
}
return true;
}
/*
* Returns the total of segment files' on-disk size for an AO/AOCO relation.
* This is only used by AO vaccum progress reporting.
*/
uint64
ao_rel_get_physical_size(Relation aorel)
{
Relation pg_aoseg_rel;
TupleDesc pg_aoseg_dsc;
SysScanDesc aoscan;
HeapTuple tuple;
Snapshot appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid));
Oid segrelid;
uint64 total_physical_size = 0;
Assert(RelationStorageIsAO(aorel));
GetAppendOnlyEntryAuxOids(aorel,
&segrelid, NULL, NULL);
pg_aoseg_rel = heap_open(segrelid, AccessShareLock);
pg_aoseg_dsc = RelationGetDescr(pg_aoseg_rel);
aoscan = systable_beginscan(pg_aoseg_rel, InvalidOid, false, appendOnlyMetaDataSnapshot, 0, NULL);
while ((tuple = systable_getnext(aoscan)) != NULL)
{
int segno;
bool isNull;
if (RelationStorageIsAoRows(aorel))
{
segno = DatumGetInt32(fastgetattr(tuple,
Anum_pg_aoseg_segno,
pg_aoseg_dsc, &isNull));
total_physical_size += ao_segfile_get_physical_size(aorel, segno, InvalidFileNumber);
}
else
{
Datum d;
AOCSVPInfo *vpinfo;
int col;
Assert(RelationStorageIsAoCols(aorel));
segno = DatumGetInt32(fastgetattr(tuple,
Anum_pg_aocs_segno,
pg_aoseg_dsc, &isNull));
d = fastgetattr(tuple,
Anum_pg_aocs_vpinfo,
pg_aoseg_dsc, &isNull);
vpinfo = (AOCSVPInfo *) PG_DETOAST_DATUM(d);
for (col = 0; col < vpinfo->nEntry; ++col)
{
FileNumber filenum = GetFilenumForAttribute(RelationGetRelid(aorel), col + 1);
total_physical_size += ao_segfile_get_physical_size(aorel, segno, filenum);
}
if (DatumGetPointer(d) != (Pointer) vpinfo)
pfree(vpinfo);
}
}
systable_endscan(aoscan);
heap_close(pg_aoseg_rel, AccessShareLock);
UnregisterSnapshot(appendOnlyMetaDataSnapshot);
return total_physical_size;
}
static uint64
ao_segfile_get_physical_size(Relation aorel, int segno, FileNumber filenum)
{
const char *relname;
File fd;
int32 fileSegNo;
char filenamepath[MAXPGPATH];
uint64 physical_size = 0;
relname = RelationGetRelationName(aorel);
MakeAOSegmentFileName(aorel, segno, filenum, &fileSegNo, filenamepath);
elogif(Debug_appendonly_print_compaction, LOG,
"Opening append-optimized relation \"%s\", relation id %u, relfilenode %u filenum #%d, logical segment #%d (physical segment file #%d)",
relname,
aorel->rd_id,
aorel->rd_node.relNode,
filenum,
segno,
fileSegNo);
fd = PathNameOpenFile(filenamepath, O_RDONLY | PG_BINARY);
if (fd >= 0)
physical_size = FileDiskSize(fd);
else
elogif(Debug_appendonly_print_compaction, LOG,
"No gp_relation_node entry for append-optimized relation \"%s\", relation id %u, relfilenode %u filenum #%d, logical segment #%d (physical segment file #%d)",
relname,
aorel->rd_id,
aorel->rd_node.relNode,
filenum,
segno,
fileSegNo);
return physical_size;
}