-- trying to make TFileTransport destructor quicker
authorAditya Agarwal <aditya@apache.org>
Wed, 11 Apr 2007 00:13:09 +0000 (00:13 +0000)
committerAditya Agarwal <aditya@apache.org>
Wed, 11 Apr 2007 00:13:09 +0000 (00:13 +0000)
Summary:
- setFlushMaxTimeUs to a lower value before trying to close the file

Reviewed By: jwang

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665095 13f79535-47bb-0310-9956-ffa450edef68

lib/cpp/src/transport/TFileTransport.cpp

index 5fb9ef3..aafdc21 100644 (file)
@@ -114,6 +114,9 @@ void TFileTransport::resetOutputFile(int fd, string filename, long long offset)
 TFileTransport::~TFileTransport() {
   // flush the buffer if a writer thread is active
   if (writerThreadId_ > 0) {
+    // reduce the flush timeout so that closing is quicker
+    setFlushMaxUs(300*1000);
+
     // flush output buffer
     flush();
 
@@ -296,13 +299,15 @@ void TFileTransport::writerThread() {
 
   while(1) {
     // this will only be true when the destructor is being invoked
-    if(closing_) {
+    if(closing_) {      
       // empty out both the buffers
       if (enqueueBuffer_->isEmpty() && dequeueBuffer_->isEmpty()) {
         if(-1 == ::close(fd_)) {
           perror("TFileTransport: error in close");
           throw TTransportException("TFileTransport: error in file close");
         }
+        // just be safe and sync to disk
+        fsync(fd_);
         fd_ = 0;
         pthread_exit(NULL);
         return;