aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/direct_io.h
diff options
context:
space:
mode:
authoriddqd <iddqd@yandex-team.ru>2022-02-10 16:49:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:46 +0300
commitff241e1daf76d79ed38015cdb76d55eb3a33ac27 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /util/system/direct_io.h
parent07fce9c5f7771600d0b3d70e1f88fd8a7e164d85 (diff)
downloadydb-ff241e1daf76d79ed38015cdb76d55eb3a33ac27.tar.gz
Restoring authorship annotation for <iddqd@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/direct_io.h')
-rw-r--r--util/system/direct_io.h96
1 files changed, 48 insertions, 48 deletions
diff --git a/util/system/direct_io.h b/util/system/direct_io.h
index 351b647501..6a3325a960 100644
--- a/util/system/direct_io.h
+++ b/util/system/direct_io.h
@@ -1,42 +1,42 @@
-#pragma once
-
+#pragma once
+
#include "align.h"
#include "file.h"
-#include <util/generic/buffer.h>
-
-// Supports Linux Direct-IO:
-// - Simple buffering logic.
-// - Default buffer size of 128KB matches VM page writeback granularity, to maximize IO throughput.
-// - Supports writing odd sized files by turning off direct IO for the last chunk.
-class TDirectIOBufferedFile {
-public:
+#include <util/generic/buffer.h>
+
+// Supports Linux Direct-IO:
+// - Simple buffering logic.
+// - Default buffer size of 128KB matches VM page writeback granularity, to maximize IO throughput.
+// - Supports writing odd sized files by turning off direct IO for the last chunk.
+class TDirectIOBufferedFile {
+public:
TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen = 1 << 17);
- ~TDirectIOBufferedFile();
+ ~TDirectIOBufferedFile();
- void FlushData();
- void Finish();
+ void FlushData();
+ void Finish();
size_t Read(void* buffer, size_t byteCount);
void Write(const void* buffer, size_t byteCount);
size_t Pread(void* buffer, size_t byteCount, ui64 offset);
void Pwrite(const void* buffer, size_t byteCount, ui64 offset);
-
- inline bool IsOpen() const {
+
+ inline bool IsOpen() const {
return true;
- }
-
- inline ui64 GetWritePosition() const {
- return WritePosition;
- }
-
- inline ui64 GetLength() const {
- return FlushedBytes + DataLen;
- }
-
+ }
+
+ inline ui64 GetWritePosition() const {
+ return WritePosition;
+ }
+
+ inline ui64 GetLength() const {
+ return FlushedBytes + DataLen;
+ }
+
inline FHANDLE GetHandle() {
return File.GetHandle();
- }
-
+ }
+
inline void FallocateNoResize(ui64 length) {
File.FallocateNoResize(length);
}
@@ -45,31 +45,31 @@ public:
File.ShrinkToFit();
}
-private:
- inline bool IsAligned(i64 value) {
+private:
+ inline bool IsAligned(i64 value) {
return Alignment ? value == AlignDown<i64>(value, Alignment) : true;
- }
+ }
- inline bool IsAligned(const void* value) {
+ inline bool IsAligned(const void* value) {
return Alignment ? value == AlignDown(value, Alignment) : true;
- }
-
+ }
+
size_t PreadSafe(void* buffer, size_t byteCount, ui64 offset);
size_t ReadFromFile(void* buffer, size_t byteCount, ui64 offset);
- void WriteToFile(const void* buf, size_t len, ui64 position);
- void WriteToBuffer(const void* buf, size_t len, ui64 position);
- void SetDirectIO(bool value);
-
+ void WriteToFile(const void* buf, size_t len, ui64 position);
+ void WriteToBuffer(const void* buf, size_t len, ui64 position);
+ void SetDirectIO(bool value);
+
private:
TFile File;
- size_t Alignment;
- size_t BufLen;
- size_t DataLen;
- void* Buffer;
- TBuffer BufferStorage;
- ui64 ReadPosition;
- ui64 WritePosition;
- ui64 FlushedBytes;
- ui64 FlushedToDisk;
- bool DirectIO;
-};
+ size_t Alignment;
+ size_t BufLen;
+ size_t DataLen;
+ void* Buffer;
+ TBuffer BufferStorage;
+ ui64 ReadPosition;
+ ui64 WritePosition;
+ ui64 FlushedBytes;
+ ui64 FlushedToDisk;
+ bool DirectIO;
+};