Bladeren bron

updated PR #279 - Merge branch 'fadvise' into merge

Thomas Waldmann 10 jaren geleden
bovenliggende
commit
a6f8d51b37
1 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  1. 4 4
      attic/repository.py

+ 4 - 4
attic/repository.py

@@ -555,10 +555,6 @@ class LoggedIO:
         header = self.header_no_crc_fmt.pack(size, TAG_PUT)
         header = self.header_no_crc_fmt.pack(size, TAG_PUT)
         crc = self.crc_fmt.pack(crc32(data, crc32(id, crc32(header))) & 0xffffffff)
         crc = self.crc_fmt.pack(crc32(data, crc32(id, crc32(header))) & 0xffffffff)
         fd.write(b''.join((crc, header, id, data)))
         fd.write(b''.join((crc, header, id, data)))
-        if hasattr(os, 'posix_fadvise'):  # python >= 3.3, only on UNIX
-            # tell the OS that it does not need to cache what we just wrote,
-            # avoids spoiling the cache for the OS and other processes.
-            os.posix_fadvise(fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
         self.offset += size
         self.offset += size
         return self.segment, offset
         return self.segment, offset
 
 
@@ -583,5 +579,9 @@ class LoggedIO:
             self.offset = 0
             self.offset = 0
             self._write_fd.flush()
             self._write_fd.flush()
             os.fsync(self._write_fd.fileno())
             os.fsync(self._write_fd.fileno())
+            if hasattr(os, 'posix_fadvise'):  # python >= 3.3, only on UNIX
+                # tell the OS that it does not need to cache what we just wrote,
+                # avoids spoiling the cache for the OS and other processes.
+                os.posix_fadvise(self._write_fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
             self._write_fd.close()
             self._write_fd.close()
             self._write_fd = None
             self._write_fd = None