aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authoriddqd <iddqd@yandex-team.ru>2022-02-10 16:49:45 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:45 +0300
commit07fce9c5f7771600d0b3d70e1f88fd8a7e164d85 (patch)
treee4aa4750fbb864d70f8c06cf03d2750e979ea3bf /util
parentaf42068bf6cd93c976b80dd0388fa48cdf65da11 (diff)
downloadydb-07fce9c5f7771600d0b3d70e1f88fd8a7e164d85.tar.gz
Restoring authorship annotation for <iddqd@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/folder/dirut.cpp26
-rw-r--r--util/folder/fts.cpp4
-rw-r--r--util/generic/guid.cpp72
-rw-r--r--util/generic/guid.h24
-rw-r--r--util/generic/guid_ut.cpp50
-rw-r--r--util/stream/buffer.cpp10
-rw-r--r--util/stream/buffer.h2
-rw-r--r--util/stream/buffered.cpp16
-rw-r--r--util/stream/buffered_ut.cpp18
-rw-r--r--util/stream/direct_io.cpp78
-rw-r--r--util/stream/direct_io.h60
-rw-r--r--util/stream/direct_io_ut.cpp14
-rw-r--r--util/stream/ios_ut.cpp100
-rw-r--r--util/stream/mem.cpp2
-rw-r--r--util/stream/mem.h2
-rw-r--r--util/stream/str.cpp10
-rw-r--r--util/stream/str.h2
-rw-r--r--util/stream/walk.cpp4
-rw-r--r--util/stream/walk.h2
-rw-r--r--util/stream/zerocopy.cpp42
-rw-r--r--util/stream/zerocopy.h50
-rw-r--r--util/system/atexit.cpp18
-rw-r--r--util/system/atexit.h4
-rw-r--r--util/system/direct_io.cpp256
-rw-r--r--util/system/direct_io.h96
-rw-r--r--util/system/direct_io_ut.cpp8
-rw-r--r--util/system/error.cpp2
-rw-r--r--util/system/info.cpp16
-rw-r--r--util/system/info.h2
-rw-r--r--util/system/mlock.cpp4
30 files changed, 497 insertions, 497 deletions
diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp
index ffc9b09f96..8922884136 100644
--- a/util/folder/dirut.cpp
+++ b/util/folder/dirut.cpp
@@ -222,22 +222,22 @@ int correctpath(char* cpath, const char* path) {
}
char* ptr = (char*)path;
char* cptr = cpath;
- int counter = 0;
- while (*ptr) {
- char c = *ptr;
- if (c == '/')
- c = '\\';
- if (c == '\\')
+ int counter = 0;
+ while (*ptr) {
+ char c = *ptr;
+ if (c == '/')
+ c = '\\';
+ if (c == '\\')
++counter;
- else
- counter = 0;
- if (counter <= 1) {
- *cptr = c;
+ else
+ counter = 0;
+ if (counter <= 1) {
+ *cptr = c;
++cptr;
- }
+ }
++ptr;
- }
- *cptr = 0;
+ }
+ *cptr = 0;
// replace '/' by '\'
int dk = skip_disk(cpath);
diff --git a/util/folder/fts.cpp b/util/folder/fts.cpp
index 0e6a6f86eb..906f987084 100644
--- a/util/folder/fts.cpp
+++ b/util/folder/fts.cpp
@@ -37,7 +37,7 @@
#include <util/system/compat.h>
#include <util/system/compiler.h>
#include <util/system/defaults.h>
-#include <util/system/error.h>
+#include <util/system/error.h>
#include <stdlib.h>
#ifndef _win_
@@ -465,7 +465,7 @@ yfts_read(FTS* sp) {
char* t;
int saved_errno;
- ClearLastSystemError();
+ ClearLastSystemError();
/* If finished or unrecoverable error, return NULL. */
if (sp->fts_cur == nullptr || ISSET(FTS_STOP)) {
diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp
index 8b907457bc..11434ed80b 100644
--- a/util/generic/guid.cpp
+++ b/util/generic/guid.cpp
@@ -3,44 +3,44 @@
#include "string.h"
#include <util/string/ascii.h>
-#include <util/string/builder.h>
+#include <util/string/builder.h>
#include <util/stream/format.h>
#include <util/system/unaligned_mem.h>
#include <util/random/easy.h>
-namespace {
- inline void LowerCaseHex(TString& s) {
- for (auto&& c : s) {
- c = AsciiToLower(c);
- }
- }
-}
-
-TString TGUID::AsGuidString() const {
- TStringBuilder s;
- s.reserve(50);
- s << Hex(dw[0], 0) << '-' << Hex(dw[1], 0) << '-' << Hex(dw[2], 0) << '-' << Hex(dw[3], 0);
- LowerCaseHex(s);
- return std::move(s);
-}
-
-TString TGUID::AsUuidString() const {
- TStringBuilder s;
- s.reserve(50);
- s << Hex(dw[0], HF_FULL) << '-';
- s << Hex(static_cast<ui16>(dw[1] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[1]), HF_FULL) << '-';
- s << Hex(static_cast<ui16>(dw[2] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[2]), HF_FULL);
- s << Hex(dw[3], HF_FULL);
- LowerCaseHex(s);
- return std::move(s);
-}
-
-TGUID TGUID::Create() {
- TGUID result;
- CreateGuid(&result);
- return result;
-}
-
+namespace {
+ inline void LowerCaseHex(TString& s) {
+ for (auto&& c : s) {
+ c = AsciiToLower(c);
+ }
+ }
+}
+
+TString TGUID::AsGuidString() const {
+ TStringBuilder s;
+ s.reserve(50);
+ s << Hex(dw[0], 0) << '-' << Hex(dw[1], 0) << '-' << Hex(dw[2], 0) << '-' << Hex(dw[3], 0);
+ LowerCaseHex(s);
+ return std::move(s);
+}
+
+TString TGUID::AsUuidString() const {
+ TStringBuilder s;
+ s.reserve(50);
+ s << Hex(dw[0], HF_FULL) << '-';
+ s << Hex(static_cast<ui16>(dw[1] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[1]), HF_FULL) << '-';
+ s << Hex(static_cast<ui16>(dw[2] >> 16), HF_FULL) << '-' << Hex(static_cast<ui16>(dw[2]), HF_FULL);
+ s << Hex(dw[3], HF_FULL);
+ LowerCaseHex(s);
+ return std::move(s);
+}
+
+TGUID TGUID::Create() {
+ TGUID result;
+ CreateGuid(&result);
+ return result;
+}
+
void CreateGuid(TGUID* res) {
ui64* dw = reinterpret_cast<ui64*>(res->dw);
@@ -66,11 +66,11 @@ TGUID TGUID::CreateTimebased() {
}
TString GetGuidAsString(const TGUID& g) {
- return g.AsGuidString();
+ return g.AsGuidString();
}
TString CreateGuidAsString() {
- return TGUID::Create().AsGuidString();
+ return TGUID::Create().AsGuidString();
}
static bool GetDigit(const char c, ui32& digit) {
diff --git a/util/generic/guid.h b/util/generic/guid.h
index 2bf6c8ad99..d6259a8942 100644
--- a/util/generic/guid.h
+++ b/util/generic/guid.h
@@ -24,18 +24,18 @@ struct TGUID {
constexpr explicit operator bool() const noexcept {
return !IsEmpty();
}
-
- // xxxx-xxxx-xxxx-xxxx
- TString AsGuidString() const;
-
- /**
- * RFC4122 GUID, which described in
- * https://en.wikipedia.org/wiki/Universally_unique_identifier
- * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
- **/
- TString AsUuidString() const;
-
- static TGUID Create();
+
+ // xxxx-xxxx-xxxx-xxxx
+ TString AsGuidString() const;
+
+ /**
+ * RFC4122 GUID, which described in
+ * https://en.wikipedia.org/wiki/Universally_unique_identifier
+ * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ **/
+ TString AsUuidString() const;
+
+ static TGUID Create();
/**
* Generate time based UUID version 1 RFC4122 GUID
diff --git a/util/generic/guid_ut.cpp b/util/generic/guid_ut.cpp
index 048354ff39..fdcb723ee8 100644
--- a/util/generic/guid_ut.cpp
+++ b/util/generic/guid_ut.cpp
@@ -94,31 +94,31 @@ Y_UNIT_TEST_SUITE(TGuidTest) {
UNIT_ASSERT_EQUAL(t.G, GetUuid(t.S));
}
}
-
- Y_UNIT_TEST(DoubleConvert) {
- /**
- * test print and parsing RFC4122 GUID, which described in
- * https://en.wikipedia.org/wiki/Universally_unique_identifier
- * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
- **/
- auto guid = TGUID::Create();
- auto printed = guid.AsUuidString();
-
- TGUID read;
- UNIT_ASSERT(GetUuid(printed, read));
-
- UNIT_ASSERT_VALUES_EQUAL(guid.dw[0], read.dw[0]);
- UNIT_ASSERT_VALUES_EQUAL(guid.dw[1], read.dw[1]);
- UNIT_ASSERT_VALUES_EQUAL(guid.dw[2], read.dw[2]);
- UNIT_ASSERT_VALUES_EQUAL(guid.dw[3], read.dw[3]);
- }
-
- Y_UNIT_TEST(OutputFormat) {
- TGUID guid = Construct(0x00005612U, 0x12000000U, 0x00000123U, 0x00000000U);
-
- UNIT_ASSERT_VALUES_EQUAL(guid.AsGuidString(), "5612-12000000-123-0");
- UNIT_ASSERT_VALUES_EQUAL(guid.AsUuidString(), "00005612-1200-0000-0000-012300000000");
- }
+
+ Y_UNIT_TEST(DoubleConvert) {
+ /**
+ * test print and parsing RFC4122 GUID, which described in
+ * https://en.wikipedia.org/wiki/Universally_unique_identifier
+ * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ **/
+ auto guid = TGUID::Create();
+ auto printed = guid.AsUuidString();
+
+ TGUID read;
+ UNIT_ASSERT(GetUuid(printed, read));
+
+ UNIT_ASSERT_VALUES_EQUAL(guid.dw[0], read.dw[0]);
+ UNIT_ASSERT_VALUES_EQUAL(guid.dw[1], read.dw[1]);
+ UNIT_ASSERT_VALUES_EQUAL(guid.dw[2], read.dw[2]);
+ UNIT_ASSERT_VALUES_EQUAL(guid.dw[3], read.dw[3]);
+ }
+
+ Y_UNIT_TEST(OutputFormat) {
+ TGUID guid = Construct(0x00005612U, 0x12000000U, 0x00000123U, 0x00000000U);
+
+ UNIT_ASSERT_VALUES_EQUAL(guid.AsGuidString(), "5612-12000000-123-0");
+ UNIT_ASSERT_VALUES_EQUAL(guid.AsUuidString(), "00005612-1200-0000-0000-012300000000");
+ }
Y_UNIT_TEST(TimeBased) {
TString guid = TGUID::CreateTimebased().AsUuidString();
diff --git a/util/stream/buffer.cpp b/util/stream/buffer.cpp
index 2facece4ea..bc2159dff8 100644
--- a/util/stream/buffer.cpp
+++ b/util/stream/buffer.cpp
@@ -113,8 +113,8 @@ size_t TBufferInput::DoNext(const void** ptr, size_t len) {
Readed_ += len;
return len;
}
-
-void TBufferInput::DoUndo(size_t len) {
- Y_VERIFY(len <= Readed_);
- Readed_ -= len;
-}
+
+void TBufferInput::DoUndo(size_t len) {
+ Y_VERIFY(len <= Readed_);
+ Readed_ -= len;
+}
diff --git a/util/stream/buffer.h b/util/stream/buffer.h
index 9dc99dbe49..c77960bcb6 100644
--- a/util/stream/buffer.h
+++ b/util/stream/buffer.h
@@ -77,7 +77,7 @@ public:
protected:
size_t DoNext(const void** ptr, size_t len) override;
- void DoUndo(size_t len) override;
+ void DoUndo(size_t len) override;
private:
const TBuffer& Buf_;
diff --git a/util/stream/buffered.cpp b/util/stream/buffered.cpp
index a00e592e1c..de4ec8c756 100644
--- a/util/stream/buffered.cpp
+++ b/util/stream/buffered.cpp
@@ -35,7 +35,7 @@ public:
return MemInput_.Read(buf, len);
}
- inline size_t Skip(size_t len) {
+ inline size_t Skip(size_t len) {
size_t totalSkipped = 0;
while (len) {
const size_t skipped = DoSkip(len);
@@ -45,11 +45,11 @@ public:
totalSkipped += skipped;
len -= skipped;
- }
+ }
return totalSkipped;
- }
-
+ }
+
inline size_t DoSkip(size_t len) {
if (MemInput_.Exhausted()) {
if (len > BufLen() / 2) {
@@ -131,10 +131,10 @@ size_t TBufferedInput::DoRead(void* buf, size_t len) {
return Impl_->Read(buf, len);
}
-size_t TBufferedInput::DoSkip(size_t len) {
- return Impl_->Skip(len);
-}
-
+size_t TBufferedInput::DoSkip(size_t len) {
+ return Impl_->Skip(len);
+}
+
size_t TBufferedInput::DoNext(const void** ptr, size_t len) {
return Impl_->Next(ptr, len);
}
diff --git a/util/stream/buffered_ut.cpp b/util/stream/buffered_ut.cpp
index 41d2fc3030..62a32776de 100644
--- a/util/stream/buffered_ut.cpp
+++ b/util/stream/buffered_ut.cpp
@@ -59,7 +59,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) {
UNIT_ASSERT_VALUES_EQUAL(s, "112");
}
-
+
Y_UNIT_TEST(Test4) {
TString s;
@@ -109,24 +109,24 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) {
Y_UNIT_TEST(TestInput) {
TString s("0123456789abcdefghijklmn");
- TBuffered<TStringInput> in(5, s);
- char c;
+ TBuffered<TStringInput> in(5, s);
+ char c;
UNIT_ASSERT_VALUES_EQUAL(in.Read(&c, 1), 1); //1
- UNIT_ASSERT_VALUES_EQUAL(c, '0');
+ UNIT_ASSERT_VALUES_EQUAL(c, '0');
UNIT_ASSERT_VALUES_EQUAL(in.Skip(4), 4); //5 end of buffer
UNIT_ASSERT_VALUES_EQUAL(in.Read(&c, 1), 1); //6
- UNIT_ASSERT_VALUES_EQUAL(c, '5');
+ UNIT_ASSERT_VALUES_EQUAL(c, '5');
UNIT_ASSERT_VALUES_EQUAL(in.Skip(3), 3); //9
UNIT_ASSERT_VALUES_EQUAL(in.Read(&c, 1), 1); //10 end of buffer
- UNIT_ASSERT_VALUES_EQUAL(c, '9');
+ UNIT_ASSERT_VALUES_EQUAL(c, '9');
UNIT_ASSERT_VALUES_EQUAL(in.Skip(3), 3); //13
UNIT_ASSERT_VALUES_EQUAL(in.Read(&c, 1), 1); //14 start new buffer
- UNIT_ASSERT_VALUES_EQUAL(c, 'd');
+ UNIT_ASSERT_VALUES_EQUAL(c, 'd');
UNIT_ASSERT_VALUES_EQUAL(in.Skip(6), 6); //20
UNIT_ASSERT_VALUES_EQUAL(in.Read(&c, 1), 1); //21 start new buffer
- UNIT_ASSERT_VALUES_EQUAL(c, 'k');
+ UNIT_ASSERT_VALUES_EQUAL(c, 'k');
UNIT_ASSERT_VALUES_EQUAL(in.Skip(6), 3); //24 eof
- }
+ }
Y_UNIT_TEST(TestReadTo) {
TString s("0123456789abc");
diff --git a/util/stream/direct_io.cpp b/util/stream/direct_io.cpp
index 649033af34..5aab0830e1 100644
--- a/util/stream/direct_io.cpp
+++ b/util/stream/direct_io.cpp
@@ -1,47 +1,47 @@
-#include "direct_io.h"
-
+#include "direct_io.h"
+
#include <util/generic/utility.h>
-size_t TRandomAccessFileInput::DoRead(void* buf, size_t len) {
- const size_t result = File.Pread(buf, len, Position);
- Position += result;
- return result;
-}
-
-TRandomAccessFileInput::TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position)
- : File(file)
- , Position(position)
-{
-}
-
-size_t TRandomAccessFileInput::DoSkip(size_t len) {
+size_t TRandomAccessFileInput::DoRead(void* buf, size_t len) {
+ const size_t result = File.Pread(buf, len, Position);
+ Position += result;
+ return result;
+}
+
+TRandomAccessFileInput::TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position)
+ : File(file)
+ , Position(position)
+{
+}
+
+size_t TRandomAccessFileInput::DoSkip(size_t len) {
size_t skiped = Min(len, (size_t)Min((ui64)Max<size_t>(), File.GetLength() - Position));
- Position += skiped;
- return skiped;
-}
-
-TRandomAccessFileOutput::TRandomAccessFileOutput(TDirectIOBufferedFile& file)
+ Position += skiped;
+ return skiped;
+}
+
+TRandomAccessFileOutput::TRandomAccessFileOutput(TDirectIOBufferedFile& file)
: File(&file)
-{
-}
-
-void TRandomAccessFileOutput::DoWrite(const void* buf, size_t len) {
+{
+}
+
+void TRandomAccessFileOutput::DoWrite(const void* buf, size_t len) {
File->Write(buf, len);
-}
-
-void TRandomAccessFileOutput::DoFlush() {
+}
+
+void TRandomAccessFileOutput::DoFlush() {
File->FlushData();
-}
-
+}
+
TBufferedFileOutputEx::TBufferedFileOutputEx(const TString& path, EOpenMode oMode, size_t buflen)
- : TRandomAccessFileOutput(*(new TDirectIOBufferedFile(path, oMode, buflen)))
+ : TRandomAccessFileOutput(*(new TDirectIOBufferedFile(path, oMode, buflen)))
, FileHolder(File)
-{
-}
-
-void TBufferedFileOutputEx::DoFinish() {
- FileHolder->Finish();
-}
-
-void TBufferedFileOutputEx::DoFlush() {
-}
+{
+}
+
+void TBufferedFileOutputEx::DoFinish() {
+ FileHolder->Finish();
+}
+
+void TBufferedFileOutputEx::DoFlush() {
+}
diff --git a/util/stream/direct_io.h b/util/stream/direct_io.h
index 2e1f2e07dd..0c55f15a95 100644
--- a/util/stream/direct_io.h
+++ b/util/stream/direct_io.h
@@ -1,43 +1,43 @@
-#pragma once
-
-#include "input.h"
-#include "output.h"
-#include <util/system/direct_io.h>
-
+#pragma once
+
+#include "input.h"
+#include "output.h"
+#include <util/system/direct_io.h>
+
class TRandomAccessFileInput: public IInputStream {
-public:
- TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position);
-
-protected:
+public:
+ TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position);
+
+protected:
size_t DoRead(void* buf, size_t len) override;
size_t DoSkip(size_t len) override;
-
-private:
- TDirectIOBufferedFile& File;
- ui64 Position;
-};
-
+
+private:
+ TDirectIOBufferedFile& File;
+ ui64 Position;
+};
+
class TRandomAccessFileOutput: public IOutputStream {
-public:
- TRandomAccessFileOutput(TDirectIOBufferedFile& file);
-
+public:
+ TRandomAccessFileOutput(TDirectIOBufferedFile& file);
+
TRandomAccessFileOutput(TRandomAccessFileOutput&&) noexcept = default;
TRandomAccessFileOutput& operator=(TRandomAccessFileOutput&&) noexcept = default;
-protected:
+protected:
TDirectIOBufferedFile* File;
-
-private:
+
+private:
void DoWrite(const void* buf, size_t len) override;
void DoFlush() override;
-};
-
-class TBufferedFileOutputEx: public TRandomAccessFileOutput {
-public:
+};
+
+class TBufferedFileOutputEx: public TRandomAccessFileOutput {
+public:
TBufferedFileOutputEx(const TString& path, EOpenMode oMode, size_t buflen = 1 << 17);
-
-private:
+
+private:
void DoFlush() override;
void DoFinish() override;
- THolder<TDirectIOBufferedFile> FileHolder;
-};
+ THolder<TDirectIOBufferedFile> FileHolder;
+};
diff --git a/util/stream/direct_io_ut.cpp b/util/stream/direct_io_ut.cpp
index 01d09db232..0dbc2454f2 100644
--- a/util/stream/direct_io_ut.cpp
+++ b/util/stream/direct_io_ut.cpp
@@ -1,12 +1,12 @@
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/generic/string.h>
#include <util/generic/array_size.h>
#include <util/system/env.h>
-
+
#include "buffered.h"
#include "direct_io.h"
-
+
Y_UNIT_TEST_SUITE(TDirectIOTests) {
// Decrease numBufToWrite further if tests continue to time out
static void Y_NO_INLINE Test(EOpenMode mode, size_t numBufToWrite) {
@@ -55,8 +55,8 @@ Y_UNIT_TEST_SUITE(TDirectIOTests) {
}
UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE);
- }
-
+ }
+
Y_UNIT_TEST(ReadWriteTest) {
Test(0, 100 * 32);
}
@@ -67,5 +67,5 @@ Y_UNIT_TEST_SUITE(TDirectIOTests) {
Y_UNIT_TEST(ReadWriteDirectSeqTest) {
Test(Direct | Seq, 100 * 4);
- }
-}
+ }
+}
diff --git a/util/stream/ios_ut.cpp b/util/stream/ios_ut.cpp
index 139f4296e5..2094295103 100644
--- a/util/stream/ios_ut.cpp
+++ b/util/stream/ios_ut.cpp
@@ -2,7 +2,7 @@
#include "tokenizer.h"
#include "buffer.h"
#include "buffered.h"
-#include "walk.h"
+#include "walk.h"
#include <library/cpp/testing/unittest/registar.h>
@@ -23,8 +23,8 @@ class TStreamsTest: public TTestBase {
UNIT_TEST(TestBufferStream);
UNIT_TEST(TestStringStream);
UNIT_TEST(TestWtrokaInput);
- UNIT_TEST(TestStrokaInput);
- UNIT_TEST(TestReadTo);
+ UNIT_TEST(TestStrokaInput);
+ UNIT_TEST(TestReadTo);
UNIT_TEST(TestWtrokaOutput);
UNIT_TEST(TestIStreamOperators);
UNIT_TEST(TestWchar16Output);
@@ -41,10 +41,10 @@ public:
void TestBufferStream();
void TestStringStream();
void TestWtrokaInput();
- void TestStrokaInput();
+ void TestStrokaInput();
void TestWtrokaOutput();
void TestIStreamOperators();
- void TestReadTo();
+ void TestReadTo();
void TestWchar16Output();
void TestWchar32Output();
void TestUtf16StingOutputByChars();
@@ -280,30 +280,30 @@ void TStreamsTest::TestBufferStream() {
namespace {
class TStringListInput: public IWalkInput {
- public:
+ public:
TStringListInput(const TVector<TString>& data)
- : Data_(data)
- , Index_(0)
- {
- }
-
- protected:
- size_t DoUnboundedNext(const void** ptr) override {
- if (Index_ >= Data_.size()) {
- return 0;
- }
-
+ : Data_(data)
+ , Index_(0)
+ {
+ }
+
+ protected:
+ size_t DoUnboundedNext(const void** ptr) override {
+ if (Index_ >= Data_.size()) {
+ return 0;
+ }
+
const TString& string = Data_[Index_++];
-
- *ptr = string.data();
- return string.size();
- }
-
- private:
+
+ *ptr = string.data();
+ return string.size();
+ }
+
+ private:
const TVector<TString>& Data_;
- size_t Index_;
- };
-
+ size_t Index_;
+ };
+
const char Text[] =
// UTF8 encoded "one \ntwo\r\nthree\n\tfour\nfive\n" in russian and ...
"один \n"
@@ -335,18 +335,18 @@ namespace {
TString tmp;
input.ReadTo(tmp, 'c');
UNIT_ASSERT_VALUES_EQUAL_C(tmp, "111a222b333", comment);
-
+
char tmp2;
input.Read(&tmp2, 1);
UNIT_ASSERT_VALUES_EQUAL_C(tmp2, '4', comment);
-
+
input.ReadTo(tmp, '6');
UNIT_ASSERT_VALUES_EQUAL_C(tmp, "44d555e", comment);
-
+
tmp = input.ReadAll();
UNIT_ASSERT_VALUES_EQUAL_C(tmp, "66f", comment);
}
-
+
void TestStreamReadTo2(IInputStream& input, const char* comment) {
TString s;
size_t i = 0;
@@ -354,30 +354,30 @@ namespace {
UNIT_ASSERT_C(i < Y_ARRAY_SIZE(Expected), comment);
UNIT_ASSERT_VALUES_EQUAL_C(s, Expected[i], comment);
++i;
- }
+ }
}
-
+
void TestStreamReadTo3(IInputStream& input, const char* comment) {
UNIT_ASSERT_VALUES_EQUAL_C(input.ReadLine(), "111a222b333c444d555e666f", comment);
}
-
+
void TestStreamReadTo4(IInputStream& input, const char* comment) {
UNIT_ASSERT_VALUES_EQUAL_C(input.ReadTo('\0'), "one", comment);
UNIT_ASSERT_VALUES_EQUAL_C(input.ReadTo('\0'), "two", comment);
UNIT_ASSERT_VALUES_EQUAL_C(input.ReadTo('\0'), "three", comment);
}
-
+
void TestStrokaInput(IInputStream& input, const char* comment) {
TString line;
ui32 i = 0;
TInstant start = Now();
while (input.ReadLine(line)) {
++i;
- }
+ }
Cout << comment << ":" << (Now() - start).SecondsFloat() << Endl;
UNIT_ASSERT_VALUES_EQUAL(i, 100000);
}
-
+
template <class T>
void TestStreamReadTo(const TString& text, T test) {
TStringInput is(text);
@@ -396,25 +396,25 @@ namespace {
}
}
-void TStreamsTest::TestReadTo() {
- TestStreamReadTo("111a222b333c444d555e666f", TestStreamReadTo1);
- TestStreamReadTo(Text, TestStreamReadTo2);
- TestStreamReadTo("111a222b333c444d555e666f", TestStreamReadTo3);
+void TStreamsTest::TestReadTo() {
+ TestStreamReadTo("111a222b333c444d555e666f", TestStreamReadTo1);
+ TestStreamReadTo(Text, TestStreamReadTo2);
+ TestStreamReadTo("111a222b333c444d555e666f", TestStreamReadTo3);
TString withZero = "one";
- withZero.append('\0').append("two").append('\0').append("three");
- TestStreamReadTo(withZero, TestStreamReadTo4);
-}
-
-void TStreamsTest::TestStrokaInput() {
+ withZero.append('\0').append("two").append('\0').append("three");
+ TestStreamReadTo(withZero, TestStreamReadTo4);
+}
+
+void TStreamsTest::TestStrokaInput() {
TString s;
- for (ui32 i = 0; i < 100000; ++i) {
+ for (ui32 i = 0; i < 100000; ++i) {
TVector<char> d(i % 1000, 'a');
s.append(d.data(), d.size());
- s.append('\n');
- }
+ s.append('\n');
+ }
TestStreamReadTo(s, ::TestStrokaInput);
-}
-
+}
+
void TStreamsTest::TestWtrokaInput() {
const TString s(Text);
TStringInput is(s);
diff --git a/util/stream/mem.cpp b/util/stream/mem.cpp
index 22a3339e27..68778a86f2 100644
--- a/util/stream/mem.cpp
+++ b/util/stream/mem.cpp
@@ -31,7 +31,7 @@ size_t TMemoryInput::DoNext(const void** ptr, size_t len) {
return len;
}
-void TMemoryInput::DoUndo(size_t len) {
+void TMemoryInput::DoUndo(size_t len) {
Len_ += len;
Buf_ -= len;
}
diff --git a/util/stream/mem.h b/util/stream/mem.h
index 18a5d46772..383e49dfd5 100644
--- a/util/stream/mem.h
+++ b/util/stream/mem.h
@@ -98,7 +98,7 @@ public:
private:
size_t DoNext(const void** ptr, size_t len) override;
- void DoUndo(size_t len) override;
+ void DoUndo(size_t len) override;
private:
const char* Buf_;
diff --git a/util/stream/str.cpp b/util/stream/str.cpp
index 13f0e8ef28..e1b6e72d67 100644
--- a/util/stream/str.cpp
+++ b/util/stream/str.cpp
@@ -11,11 +11,11 @@ size_t TStringInput::DoNext(const void** ptr, size_t len) {
return len;
}
-void TStringInput::DoUndo(size_t len) {
- Y_VERIFY(len <= Pos_);
- Pos_ -= len;
-}
-
+void TStringInput::DoUndo(size_t len) {
+ Y_VERIFY(len <= Pos_);
+ Pos_ -= len;
+}
+
TStringOutput::~TStringOutput() = default;
size_t TStringOutput::DoNext(void** ptr) {
diff --git a/util/stream/str.h b/util/stream/str.h
index 028bd572c0..89f42c1fd7 100644
--- a/util/stream/str.h
+++ b/util/stream/str.h
@@ -49,7 +49,7 @@ public:
protected:
size_t DoNext(const void** ptr, size_t len) override;
- void DoUndo(size_t len) override;
+ void DoUndo(size_t len) override;
private:
const TString* S_;
diff --git a/util/stream/walk.cpp b/util/stream/walk.cpp
index 57dc9ab036..47a6cae5f8 100644
--- a/util/stream/walk.cpp
+++ b/util/stream/walk.cpp
@@ -3,8 +3,8 @@
#include <util/generic/string.h>
void IWalkInput::DoUndo(size_t len) {
- Len_ += len;
- Buf_ = static_cast<const char*>(Buf_) - len;
+ Len_ += len;
+ Buf_ = static_cast<const char*>(Buf_) - len;
}
size_t IWalkInput::DoNext(const void** ptr, size_t len) {
diff --git a/util/stream/walk.h b/util/stream/walk.h
index 7e62cb44dc..9683943331 100644
--- a/util/stream/walk.h
+++ b/util/stream/walk.h
@@ -16,7 +16,7 @@ public:
}
protected:
- void DoUndo(size_t len) override;
+ void DoUndo(size_t len) override;
size_t DoNext(const void** ptr, size_t len) override;
/**
diff --git a/util/stream/zerocopy.cpp b/util/stream/zerocopy.cpp
index dc2982ad55..b5f8e58b70 100644
--- a/util/stream/zerocopy.cpp
+++ b/util/stream/zerocopy.cpp
@@ -31,30 +31,30 @@ size_t IZeroCopyInput::DoSkip(size_t len) {
return DoNext(&ptr, len);
}
-
+
IZeroCopyInputFastReadTo::~IZeroCopyInputFastReadTo() = default;
-
+
size_t IZeroCopyInputFastReadTo::DoReadTo(TString& st, char ch) {
- const char* ptr;
- size_t len = Next(&ptr);
- if (!len) {
- return 0;
- }
- size_t result = 0;
- st.clear();
- do {
- if (const char* pos = (const char*)memchr(ptr, ch, len)) {
+ const char* ptr;
+ size_t len = Next(&ptr);
+ if (!len) {
+ return 0;
+ }
+ size_t result = 0;
+ st.clear();
+ do {
+ if (const char* pos = (const char*)memchr(ptr, ch, len)) {
size_t bytesRead = (pos - ptr) + 1;
if (bytesRead > 1) {
- st.append(ptr, pos);
- }
+ st.append(ptr, pos);
+ }
Undo(len - bytesRead);
result += bytesRead;
- return result;
- } else {
- result += len;
- st.append(ptr, len);
- }
- } while (len = Next(&ptr));
- return result;
-}
+ return result;
+ } else {
+ result += len;
+ st.append(ptr, len);
+ }
+ } while (len = Next(&ptr));
+ return result;
+}
diff --git a/util/stream/zerocopy.h b/util/stream/zerocopy.h
index 3315aa3a51..d44d5e0d77 100644
--- a/util/stream/zerocopy.h
+++ b/util/stream/zerocopy.h
@@ -56,36 +56,36 @@ protected:
virtual size_t DoNext(const void** ptr, size_t len) = 0;
};
-/**
-* Input stream with direct access to the input buffer and ability to undo read
-*
-* Derived classes must implement `DoUndo` method.
-*/
+/**
+* Input stream with direct access to the input buffer and ability to undo read
+*
+* Derived classes must implement `DoUndo` method.
+*/
class IZeroCopyInputFastReadTo: public IZeroCopyInput {
-public:
+public:
IZeroCopyInputFastReadTo() noexcept = default;
~IZeroCopyInputFastReadTo() override;
-
+
IZeroCopyInputFastReadTo(IZeroCopyInputFastReadTo&&) noexcept = default;
IZeroCopyInputFastReadTo& operator=(IZeroCopyInputFastReadTo&&) noexcept = default;
-protected:
+protected:
size_t DoReadTo(TString& st, char ch) override;
-
-private:
- /**
- * Undo read.
- *
- * Note that this function not check if you try undo more that read. In fact Undo used for undo read in last chunk.
- *
- * @param len[in] Bytes to undo.
- */
- inline void Undo(size_t len) {
- if (len) {
- DoUndo(len);
- }
- }
- virtual void DoUndo(size_t len) = 0;
-};
-
+
+private:
+ /**
+ * Undo read.
+ *
+ * Note that this function not check if you try undo more that read. In fact Undo used for undo read in last chunk.
+ *
+ * @param len[in] Bytes to undo.
+ */
+ inline void Undo(size_t len) {
+ if (len) {
+ DoUndo(len);
+ }
+ }
+ virtual void DoUndo(size_t len) = 0;
+};
+
/** @} */
diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp
index 74fb10b6b1..c816bc5fe0 100644
--- a/util/system/atexit.cpp
+++ b/util/system/atexit.cpp
@@ -35,7 +35,7 @@ namespace {
}
inline void Finish() noexcept {
- AtomicSet(FinishStarted_, 1);
+ AtomicSet(FinishStarted_, 1);
auto guard = Guard(Lock_);
@@ -65,13 +65,13 @@ namespace {
}
}
- inline bool FinishStarted() const {
- return AtomicGet(FinishStarted_);
- }
+ inline bool FinishStarted() const {
+ return AtomicGet(FinishStarted_);
+ }
private:
TAdaptiveLock Lock_;
- TAtomic FinishStarted_;
+ TAtomic FinishStarted_;
TDeque<TFunc> Store_;
TPriorityQueue<TFunc*, TVector<TFunc*>, TCmp> Items_;
};
@@ -108,13 +108,13 @@ void ManualRunAtExitFinalizers() {
OnExit();
}
-bool ExitStarted() {
+bool ExitStarted() {
if (TAtExit* const atExit = AtomicGet(atExitPtr)) {
return atExit->FinishStarted();
- }
+ }
return false;
-}
-
+}
+
void AtExit(TAtExitFunc func, void* ctx, size_t priority) {
Instance()->Register(func, ctx, priority);
}
diff --git a/util/system/atexit.h b/util/system/atexit.h
index eb3188615c..f70c2fcd8c 100644
--- a/util/system/atexit.h
+++ b/util/system/atexit.h
@@ -10,8 +10,8 @@ void AtExit(TAtExitFunc func, void* ctx, size_t priority);
void AtExit(TTraditionalAtExitFunc func);
void AtExit(TTraditionalAtExitFunc func, size_t priority);
-
-bool ExitStarted();
+
+bool ExitStarted();
/**
* Generally it's a bad idea to call this method except for some rare cases,
diff --git a/util/system/direct_io.cpp b/util/system/direct_io.cpp
index f59c54b0cb..3ace0bfc57 100644
--- a/util/system/direct_io.cpp
+++ b/util/system/direct_io.cpp
@@ -1,36 +1,36 @@
-#include "direct_io.h"
-
-#include <util/generic/singleton.h>
-#include <util/generic/yexception.h>
+#include "direct_io.h"
+
+#include <util/generic/singleton.h>
+#include <util/generic/yexception.h>
#include <util/system/info.h>
#include "align.h"
-
-#ifdef _linux_
+
+#ifdef _linux_
#include <util/string/cast.h>
#include <linux/version.h>
#include <sys/utsname.h>
-#endif
+#endif
-namespace {
+namespace {
struct TAlignmentCalcer {
inline TAlignmentCalcer()
- : Alignment(0)
- {
-#ifdef _linux_
- utsname sysInfo;
+ : Alignment(0)
+ {
+#ifdef _linux_
+ utsname sysInfo;
Y_VERIFY(!uname(&sysInfo), "Error while call uname: %s", LastSystemErrorText());
- TStringBuf release(sysInfo.release);
- release = release.substr(0, release.find_first_not_of(".0123456789"));
+ TStringBuf release(sysInfo.release);
+ release = release.substr(0, release.find_first_not_of(".0123456789"));
- int v1 = FromString<int>(release.NextTok('.'));
- int v2 = FromString<int>(release.NextTok('.'));
- int v3 = FromString<int>(release.NextTok('.'));
- int linuxVersionCode = KERNEL_VERSION(v1, v2, v3);
+ int v1 = FromString<int>(release.NextTok('.'));
+ int v2 = FromString<int>(release.NextTok('.'));
+ int v3 = FromString<int>(release.NextTok('.'));
+ int linuxVersionCode = KERNEL_VERSION(v1, v2, v3);
if (linuxVersionCode < KERNEL_VERSION(2, 4, 10)) {
- Alignment = 0;
+ Alignment = 0;
} else if (linuxVersionCode < KERNEL_VERSION(2, 6, 0)) {
Alignment = NSystemInfo::GetPageSize();
} else {
@@ -39,44 +39,44 @@ namespace {
// See IGNIETFERRO-946.
Alignment = 4096;
}
-#endif
- }
-
- size_t Alignment;
- };
-}
-
+#endif
+ }
+
+ size_t Alignment;
+ };
+}
+
TDirectIOBufferedFile::TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen /*= 1 << 17*/)
- : File(path, oMode)
- , Alignment(0)
- , DataLen(0)
- , ReadPosition(0)
- , WritePosition(0)
- , DirectIO(false)
-{
+ : File(path, oMode)
+ , Alignment(0)
+ , DataLen(0)
+ , ReadPosition(0)
+ , WritePosition(0)
+ , DirectIO(false)
+{
if (buflen == 0) {
ythrow TFileError() << "unbuffered usage is not supported";
- }
-
- if (oMode & Direct) {
+ }
+
+ if (oMode & Direct) {
Alignment = Singleton<TAlignmentCalcer>()->Alignment;
- SetDirectIO(true);
- }
-
- WritePosition = File.GetLength();
- FlushedBytes = WritePosition;
- FlushedToDisk = FlushedBytes;
- BufLen = (!!Alignment) ? AlignUp(buflen, Alignment) : buflen;
- BufferStorage.Resize(BufLen + Alignment);
- Buffer = (!!Alignment) ? AlignUp(BufferStorage.Data(), Alignment) : BufferStorage.Data();
-}
-
-#define DIRECT_IO_FLAGS (O_DIRECT | O_SYNC)
-
-void TDirectIOBufferedFile::SetDirectIO(bool value) {
-#ifdef _linux_
+ SetDirectIO(true);
+ }
+
+ WritePosition = File.GetLength();
+ FlushedBytes = WritePosition;
+ FlushedToDisk = FlushedBytes;
+ BufLen = (!!Alignment) ? AlignUp(buflen, Alignment) : buflen;
+ BufferStorage.Resize(BufLen + Alignment);
+ Buffer = (!!Alignment) ? AlignUp(BufferStorage.Data(), Alignment) : BufferStorage.Data();
+}
+
+#define DIRECT_IO_FLAGS (O_DIRECT | O_SYNC)
+
+void TDirectIOBufferedFile::SetDirectIO(bool value) {
+#ifdef _linux_
if (DirectIO == value) {
- return;
+ return;
}
if (!!Alignment && value) {
@@ -85,73 +85,73 @@ void TDirectIOBufferedFile::SetDirectIO(bool value) {
(void)fcntl(File.GetHandle(), F_SETFL, fcntl(File.GetHandle(), F_GETFL) & ~DIRECT_IO_FLAGS);
}
+ DirectIO = value;
+#else
DirectIO = value;
-#else
- DirectIO = value;
-#endif
-}
-
-TDirectIOBufferedFile::~TDirectIOBufferedFile() {
+#endif
+}
+
+TDirectIOBufferedFile::~TDirectIOBufferedFile() {
try {
Finish();
} catch (...) {
}
-}
-
-void TDirectIOBufferedFile::FlushData() {
+}
+
+void TDirectIOBufferedFile::FlushData() {
WriteToFile(Buffer, DataLen, FlushedBytes);
DataLen = 0;
File.FlushData();
-}
+}
-void TDirectIOBufferedFile::Finish() {
+void TDirectIOBufferedFile::Finish() {
FlushData();
File.Flush();
File.Close();
-}
-
+}
+
void TDirectIOBufferedFile::Write(const void* buffer, size_t byteCount) {
WriteToBuffer(buffer, byteCount, DataLen);
WritePosition += byteCount;
-}
-
-void TDirectIOBufferedFile::WriteToBuffer(const void* buf, size_t len, ui64 position) {
- while (len > 0) {
- size_t writeLen = Min<size_t>(BufLen - position, len);
-
- if (writeLen > 0) {
- memcpy((char*)Buffer + position, buf, writeLen);
- buf = (char*)buf + writeLen;
- len -= writeLen;
+}
+
+void TDirectIOBufferedFile::WriteToBuffer(const void* buf, size_t len, ui64 position) {
+ while (len > 0) {
+ size_t writeLen = Min<size_t>(BufLen - position, len);
+
+ if (writeLen > 0) {
+ memcpy((char*)Buffer + position, buf, writeLen);
+ buf = (char*)buf + writeLen;
+ len -= writeLen;
DataLen = (size_t)Max(position + writeLen, (ui64)DataLen);
- position += writeLen;
- }
-
- if (DataLen == BufLen) {
- WriteToFile(Buffer, DataLen, FlushedBytes);
- DataLen = 0;
- position = 0;
- }
- }
-}
-
-void TDirectIOBufferedFile::WriteToFile(const void* buf, size_t len, ui64 position) {
- if (!!len) {
- SetDirectIO(IsAligned(buf) && IsAligned(len) && IsAligned(position));
+ position += writeLen;
+ }
+
+ if (DataLen == BufLen) {
+ WriteToFile(Buffer, DataLen, FlushedBytes);
+ DataLen = 0;
+ position = 0;
+ }
+ }
+}
+
+void TDirectIOBufferedFile::WriteToFile(const void* buf, size_t len, ui64 position) {
+ if (!!len) {
+ SetDirectIO(IsAligned(buf) && IsAligned(len) && IsAligned(position));
File.Pwrite(buf, len, position);
- FlushedBytes = Max(FlushedBytes, position + len);
- FlushedToDisk = Min(FlushedToDisk, position);
- }
-}
-
+ FlushedBytes = Max(FlushedBytes, position + len);
+ FlushedToDisk = Min(FlushedToDisk, position);
+ }
+}
+
size_t TDirectIOBufferedFile::PreadSafe(void* buffer, size_t byteCount, ui64 offset) {
- if (FlushedToDisk < offset + byteCount) {
- File.FlushData();
- FlushedToDisk = FlushedBytes;
- }
-
+ if (FlushedToDisk < offset + byteCount) {
+ File.FlushData();
+ FlushedToDisk = FlushedBytes;
+ }
+
#ifdef _linux_
ssize_t bytesRead = 0;
do {
@@ -159,15 +159,15 @@ size_t TDirectIOBufferedFile::PreadSafe(void* buffer, size_t byteCount, ui64 off
} while (bytesRead == -1 && errno == EINTR);
if (bytesRead < 0) {
- ythrow yexception() << "error while pread file: " << LastSystemError() << "(" << LastSystemErrorText() << ")";
+ ythrow yexception() << "error while pread file: " << LastSystemError() << "(" << LastSystemErrorText() << ")";
}
return bytesRead;
#else
return File.Pread(buffer, byteCount, offset);
#endif
-}
-
+}
+
size_t TDirectIOBufferedFile::ReadFromFile(void* buffer, size_t byteCount, ui64 offset) {
SetDirectIO(true);
@@ -187,64 +187,64 @@ size_t TDirectIOBufferedFile::ReadFromFile(void* buffer, size_t byteCount, ui64
break;
}
}
-
+
if (!byteCount) {
return bytesRead;
}
- ui64 bufSize = AlignUp(Min<size_t>(BufferStorage.Size(), byteCount + (Alignment << 1)), Alignment);
- TBuffer readBufferStorage(bufSize + Alignment);
- char* readBuffer = AlignUp((char*)readBufferStorage.Data(), Alignment);
+ ui64 bufSize = AlignUp(Min<size_t>(BufferStorage.Size(), byteCount + (Alignment << 1)), Alignment);
+ TBuffer readBufferStorage(bufSize + Alignment);
+ char* readBuffer = AlignUp((char*)readBufferStorage.Data(), Alignment);
- while (byteCount) {
+ while (byteCount) {
ui64 begin = AlignDown(offset, (ui64)Alignment);
ui64 end = AlignUp(offset + byteCount, (ui64)Alignment);
ui64 toRead = Min(end - begin, bufSize);
ui64 fromFile = PreadSafe(readBuffer, toRead, begin);
if (!fromFile) {
- break;
+ break;
}
ui64 delta = offset - begin;
ui64 count = Min<ui64>(fromFile - delta, byteCount);
- memcpy(buffer, readBuffer + delta, count);
- buffer = (char*)buffer + count;
- byteCount -= count;
- offset += count;
+ memcpy(buffer, readBuffer + delta, count);
+ buffer = (char*)buffer + count;
+ byteCount -= count;
+ offset += count;
bytesRead += count;
- }
+ }
return bytesRead;
-}
-
+}
+
size_t TDirectIOBufferedFile::Read(void* buffer, size_t byteCount) {
size_t bytesRead = Pread(buffer, byteCount, ReadPosition);
ReadPosition += bytesRead;
return bytesRead;
-}
-
+}
+
size_t TDirectIOBufferedFile::Pread(void* buffer, size_t byteCount, ui64 offset) {
if (!byteCount) {
- return 0;
+ return 0;
}
size_t readFromFile = 0;
- if (offset < FlushedBytes) {
- readFromFile = Min<ui64>(byteCount, FlushedBytes - offset);
+ if (offset < FlushedBytes) {
+ readFromFile = Min<ui64>(byteCount, FlushedBytes - offset);
size_t bytesRead = ReadFromFile(buffer, readFromFile, offset);
if (bytesRead != readFromFile || readFromFile == byteCount) {
return bytesRead;
}
- }
- ui64 start = offset > FlushedBytes ? offset - FlushedBytes : 0;
+ }
+ ui64 start = offset > FlushedBytes ? offset - FlushedBytes : 0;
ui64 count = Min<ui64>(DataLen - start, byteCount - readFromFile);
if (count) {
- memcpy((char*)buffer + readFromFile, (const char*)Buffer + start, count);
+ memcpy((char*)buffer + readFromFile, (const char*)Buffer + start, count);
}
- return count + readFromFile;
-}
-
+ return count + readFromFile;
+}
+
void TDirectIOBufferedFile::Pwrite(const void* buffer, size_t byteCount, ui64 offset) {
if (offset > WritePosition) {
ythrow yexception() << "cannot frite to position" << offset;
@@ -262,5 +262,5 @@ void TDirectIOBufferedFile::Pwrite(const void* buffer, size_t byteCount, ui64 of
if (writeToBufer > 0) {
ui64 bufferOffset = offset + writeToFile - FlushedBytes;
WriteToBuffer((const char*)buffer + writeToFile, writeToBufer, bufferOffset);
- }
-}
+ }
+}
diff --git a/util/system/direct_io.h b/util/system/direct_io.h
index 6a3325a960..351b647501 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;
+};
diff --git a/util/system/direct_io_ut.cpp b/util/system/direct_io_ut.cpp
index 839c3de7ca..f3872df228 100644
--- a/util/system/direct_io_ut.cpp
+++ b/util/system/direct_io_ut.cpp
@@ -1,12 +1,12 @@
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/generic/yexception.h>
#include <util/system/fs.h>
#include <util/system/tempfile.h>
-#include <util/random/random.h>
+#include <util/random/random.h>
#include "direct_io.h"
-
+
static const char* FileName_("./test.file");
Y_UNIT_TEST_SUITE(TDirectIoTestSuite) {
@@ -86,7 +86,7 @@ Y_UNIT_TEST_SUITE(TDirectIoTestSuite) {
TestHugeFile(5 * 1024 * 1024 * 1024ULL + 1111);
}
}
-}
+}
Y_UNIT_TEST_SUITE(TDirectIoErrorHandling) {
Y_UNIT_TEST(Constructor) {
diff --git a/util/system/error.cpp b/util/system/error.cpp
index f778ec42cb..3396f21d0c 100644
--- a/util/system/error.cpp
+++ b/util/system/error.cpp
@@ -58,7 +58,7 @@ namespace {
const char* LastSystemErrorText(int code) {
#if defined(_win_)
- TErrString& text(*Singleton<TErrString>());
+ TErrString& text(*Singleton<TErrString>());
LastSystemErrorText(text.data, sizeof(text.data), code);
return text.data;
diff --git a/util/system/info.cpp b/util/system/info.cpp
index cf6681e89a..6cb5ac8b9d 100644
--- a/util/system/info.cpp
+++ b/util/system/info.cpp
@@ -187,7 +187,7 @@ size_t NSystemInfo::GetPageSize() noexcept {
#endif
}
-size_t NSystemInfo::TotalMemorySize() {
+size_t NSystemInfo::TotalMemorySize() {
#if defined(_linux_) && defined(_64_)
try {
auto q = FromString<size_t>(StripString(TFileInput("/sys/fs/cgroup/memory/memory.limit_in_bytes").ReadAll()));
@@ -200,9 +200,9 @@ size_t NSystemInfo::TotalMemorySize() {
#endif
#if defined(_linux_) || defined(_cygwin_)
- struct sysinfo info;
- sysinfo(&info);
- return info.totalram;
+ struct sysinfo info;
+ sysinfo(&info);
+ return info.totalram;
#elif defined(_darwin_)
int mib[2];
int64_t memSize;
@@ -223,10 +223,10 @@ size_t NSystemInfo::TotalMemorySize() {
ythrow yexception() << "GlobalMemoryStatusEx failed: " << LastSystemErrorText();
}
return (size_t)memoryStatusEx.ullTotalPhys;
-#else
- return 0;
-#endif
-}
+#else
+ return 0;
+#endif
+}
size_t NSystemInfo::MaxOpenFiles() {
#if defined(ANDROID) || defined(__ANDROID__)
diff --git a/util/system/info.h b/util/system/info.h
index 73ebe48a9a..cdf401cdfb 100644
--- a/util/system/info.h
+++ b/util/system/info.h
@@ -7,6 +7,6 @@ namespace NSystemInfo {
size_t CachedNumberOfCpus();
size_t LoadAverage(double* la, size_t len);
size_t GetPageSize() noexcept;
- size_t TotalMemorySize();
+ size_t TotalMemorySize();
size_t MaxOpenFiles();
}
diff --git a/util/system/mlock.cpp b/util/system/mlock.cpp
index 435338c98f..df69fed797 100644
--- a/util/system/mlock.cpp
+++ b/util/system/mlock.cpp
@@ -26,7 +26,7 @@ void LockMemory(const void* addr, size_t len) {
#elif defined(_win_)
HANDLE hndl = GetCurrentProcess();
SIZE_T min, max;
- if (!GetProcessWorkingSetSize(hndl, &min, &max))
+ if (!GetProcessWorkingSetSize(hndl, &min, &max))
ythrow yexception() << LastSystemErrorText();
if (!SetProcessWorkingSetSize(hndl, min + len, max + len))
ythrow yexception() << LastSystemErrorText();
@@ -43,7 +43,7 @@ void UnlockMemory(const void* addr, size_t len) {
#elif defined(_win_)
HANDLE hndl = GetCurrentProcess();
SIZE_T min, max;
- if (!GetProcessWorkingSetSize(hndl, &min, &max))
+ if (!GetProcessWorkingSetSize(hndl, &min, &max))
ythrow yexception() << LastSystemErrorText();
if (!SetProcessWorkingSetSize(hndl, min - len, max - len))
ythrow yexception() << LastSystemErrorText();