Commit 18f66e02 authored by unknown's avatar unknown
Browse files

BUG#22301 ndb: File_class::size() is not thread safe


ndb/include/logger/FileLogHandler.hpp:
  use off_t for file offset
ndb/include/util/File.hpp:
  use off_t for returning file offset (size)
ndb/src/common/util/File.cpp:
  make File_class::size(FILE*) safe when having multiple threads writing to
  the file
parent b8244883
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ private:
  bool setMaxFiles(const BaseString &files);
  
  int m_maxNoFiles;
  long m_maxFileSize;
  off_t m_maxFileSize;
  unsigned int m_maxLogEntries;
  File_class* m_pLogFile;
};
+2 −2
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public:
   * @param f a pointer to a FILE descriptor.
   * @return the size of the file.
   */
  static long size(FILE* f);
  static off_t size(FILE* f);

  /**
   * Renames a file.
@@ -182,7 +182,7 @@ public:
   *
   * @return the file size.
   */
  long size() const;
  off_t size() const;

  /**
   * Returns the filename.
+9 −10
Original line number Diff line number Diff line
@@ -45,17 +45,16 @@ File_class::exists(const char* aFileName)
  return (my_stat(aFileName, &stmp, MYF(0))!=NULL);
}

long
off_t
File_class::size(FILE* f)
{
  long cur_pos = 0, length = 0;
  MY_STAT s;

  cur_pos = ::ftell(f);
  ::fseek(f, 0, SEEK_END); 
  length = ::ftell(f); 
  ::fseek(f, cur_pos, SEEK_SET); // restore original position
  // Note that my_fstat behaves *differently* than my_stat. ARGGGHH!
  if(my_fstat(::fileno(f), &s, MYF(0)))
    return 0;

  return length;
  return s.st_size;
}

bool 
@@ -169,7 +168,7 @@ File_class::writeChar(const char* buf)
  return writeChar(buf, 0, ::strlen(buf));
}

long 
off_t
File_class::size() const
{
  return File_class::size(m_file);