MCPcopy Create free account
hub / github.com/apache/thrift / writerThread

Method writerThread

lib/cpp/src/thrift/transport/TFileTransport.cpp:300–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300void TFileTransport::writerThread() {
301 bool hasIOError = false;
302
303 // open file if it is not open
304 if (!fd_) {
305 try {
306 openLogFile();
307 } catch (...) {
308 int errno_copy = THRIFT_ERRNO;
309 TOutput::instance().perror("TFileTransport: writerThread() openLogFile() ", errno_copy);
310 fd_ = 0;
311 hasIOError = true;
312 }
313 }
314
315 // set the offset to the correct value (EOF)
316 if (!hasIOError) {
317 try {
318 seekToEnd();
319 // throw away any partial events
320 offset_ += readState_.lastDispatchPtr_;
321 if (0 == THRIFT_FTRUNCATE(fd_, offset_)) {
322 readState_.resetAllValues();
323 } else {
324 int errno_copy = THRIFT_ERRNO;
325 TOutput::instance().perror("TFileTransport: writerThread() truncate ", errno_copy);
326 hasIOError = true;
327 }
328 } catch (...) {
329 int errno_copy = THRIFT_ERRNO;
330 TOutput::instance().perror("TFileTransport: writerThread() initialization ", errno_copy);
331 hasIOError = true;
332 }
333 }
334
335 // Figure out the next time by which a flush must take place
336 auto ts_next_flush = getNextFlushTime();
337 uint32_t unflushed = 0;
338
339 while (1) {
340 // this will only be true when the destructor is being invoked
341 if (closing_) {
342 if (hasIOError) {
343 return;
344 }
345
346 // Try to empty buffers before exit
347 if (enqueueBuffer_->isEmpty() && dequeueBuffer_->isEmpty()) {
348 ::THRIFT_FSYNC(fd_);
349 if (-1 == ::THRIFT_CLOSE(fd_)) {
350 int errno_copy = THRIFT_ERRNO;
351 TOutput::instance().perror("TFileTransport: writerThread() ::close() ", errno_copy);
352 } else {
353 // fd successfully closed
354 fd_ = 0;
355 }
356 return;
357 }

Callers 1

startWriterThreadMethod · 0.80

Calls 7

nowFunction · 0.85
resetAllValuesMethod · 0.80
isEmptyMethod · 0.80
getNextMethod · 0.80
perrorMethod · 0.45
resetMethod · 0.45
notifyAllMethod · 0.45

Tested by

no test coverage detected