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

Method read

gpcontrib/gpcloud/src/s3key_reader.cpp:55–98  ·  view source on GitHub ↗

ret < len means EMPTY that's why it checks if leftLen is larger than *or equal to* len below[1], provides a chance ret is 0, which is smaller than len. Otherwise, other functions won't know when to read next buffer.

Source from the content-addressed store, hash-verified

53// that's why it checks if leftLen is larger than *or equal to* len below[1], provides a chance ret
54// is 0, which is smaller than len. Otherwise, other functions won't know when to read next buffer.
55uint64_t ChunkBuffer::read(char* buf, uint64_t len) {
56 // GPDB abort signal stops s3_import(), this check is not needed if s3_import() every time calls
57 // ChunkBuffer->Read() only once, otherwise(as we did in downstreamReader->read() for
58 // decompression feature before), first call sets buffer to ReadyToFill, second call hangs.
59 S3_CHECK_OR_DIE(!S3QueryIsAbortInProgress(), S3QueryAbort, "");
60
61 UniqueLock statusLock(&this->statusMutex);
62 while (this->status != ReadyToRead) {
63 pthread_cond_wait(&this->statusCondVar, &this->statusMutex);
64 }
65
66 // Error is shared between all chunks.
67 if (this->isError()) {
68 return 0;
69 }
70
71 uint64_t leftLen = this->chunkDataSize - this->curChunkOffset;
72 uint64_t lenToRead = std::min(len, leftLen);
73
74 if (lenToRead != 0) {
75 memcpy(buf, this->chunkData.data() + this->curChunkOffset, lenToRead);
76 }
77
78 if (len <= leftLen) { // [1]
79 this->curChunkOffset += lenToRead; // not empty
80 } else { // empty, reset everything
81 this->curChunkOffset = 0;
82
83 if (!this->isEOF()) {
84 // Release chunkData memory to reduce consumption.
85 this->chunkData.release();
86
87 this->status = ReadyToFill;
88
89 Range range = this->offsetMgr.getNextOffset();
90 this->curFileOffset = range.offset;
91 this->chunkDataSize = range.length;
92
93 pthread_cond_signal(&this->statusCondVar);
94 }
95 }
96
97 return lenToRead;
98}
99
100// returning uint64_t(-1) means error
101uint64_t ChunkBuffer::fill() {

Callers

nothing calls this directly

Calls 8

isErrorMethod · 0.95
isEOFMethod · 0.95
isSharedErrorMethod · 0.95
S3RuntimeErrorClass · 0.85
getNextOffsetMethod · 0.80
S3QueryIsAbortInProgressFunction · 0.70
releaseMethod · 0.45
getKeySizeMethod · 0.45

Tested by

no test coverage detected