MCPcopy Create free account
hub / github.com/apache/cloudberry / BufFileRead

Function BufFileRead

src/backend/storage/file/buffile.c:724–774  ·  view source on GitHub ↗

* BufFileRead * * Like fread() except we assume 1-byte element size and report I/O errors via * ereport(). */

Source from the content-addressed store, hash-verified

722 * ereport().
723 */
724size_t
725BufFileRead(BufFile *file, void *ptr, size_t size)
726{
727 size_t nread = 0;
728 size_t nthistime;
729
730 switch (file->state)
731 {
732 case BFS_RANDOM_ACCESS:
733 case BFS_SEQUENTIAL_READING:
734 break;
735
736 case BFS_SEQUENTIAL_WRITING:
737 case BFS_COMPRESSED_WRITING:
738 elog(ERROR, "cannot read from sequential BufFile before rewinding to start");
739 break;
740
741 case BFS_COMPRESSED_READING:
742 return BufFileLoadCompressedBuffer(file, ptr, size);
743 }
744
745 BufFileFlush(file);
746
747 while (size > 0)
748 {
749 if (file->pos >= file->nbytes)
750 {
751 /* Try to load more data into buffer. */
752 file->curOffset += file->pos;
753 file->pos = 0;
754 file->nbytes = 0;
755 BufFileLoadBuffer(file);
756 if (file->nbytes <= 0)
757 break; /* no more data available */
758 }
759
760 nthistime = file->nbytes - file->pos;
761 if (nthistime > size)
762 nthistime = size;
763 Assert(nthistime > 0);
764
765 memcpy(ptr, file->buffer.data + file->pos, nthistime);
766
767 file->pos += nthistime;
768 ptr = (void *) ((char *) ptr + nthistime);
769 size -= nthistime;
770 nread += nthistime;
771 }
772
773 return nread;
774}
775
776/*
777 * BufFileReadFromBuffer

Callers 13

getlenFunction · 0.85
readtup_heapFunction · 0.85
sts_read_tupleFunction · 0.85
sts_parallel_scan_nextFunction · 0.85
ltsReadBlockFunction · 0.85
SendBackupManifestFunction · 0.85
subxact_info_readFunction · 0.85
ReadTempFileBlockFunction · 0.85

Calls 3

BufFileFlushFunction · 0.85
BufFileLoadBufferFunction · 0.85

Tested by 1

buffile_large_file_testFunction · 0.68