Skip to content

Commit 27e5850

Browse files
authored
[core] Use cross-platform syscall implementation (ray-project#50209)
Signed-off-by: dentiny <[email protected]>
1 parent 9b0e04d commit 27e5850

File tree

2 files changed

+3
-49
lines changed

2 files changed

+3
-49
lines changed

src/ray/util/pipe_logger.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,9 @@
3030
#include "ray/util/util.h"
3131
#include "spdlog/logger.h"
3232

33-
#if defined(__APPLE__) || defined(__linux__)
34-
#include <unistd.h>
35-
#elif defined(_WIN32)
36-
#include <windows.h>
37-
#endif
38-
3933
namespace ray {
4034

41-
// Environmenr variable, which indicates the pipe size of read.
42-
//
43-
// TODO(hjiang): Should document the env variable after end-to-end integration has
44-
// finished.
45-
inline constexpr std::string_view kPipeLogReadBufSizeEnv = "RAY_PIPE_LOG_READ_BUF_SIZE";
46-
4735
// File handle requires active destruction via owner calling [Close].
48-
//
49-
// TODO(hjiang): Wrap fd with spdlog sink to manage stream flush and close.
5036
class RedirectionFileHandle {
5137
public:
5238
RedirectionFileHandle() = default;
@@ -100,17 +86,8 @@ class RedirectionFileHandle {
10086
MEMFD_TYPE_NON_UNIQUE GetWriteHandle() const { return write_handle_; }
10187

10288
// Write the given data into redirection handle; currently only for testing usage.
103-
//
104-
// TODO(hjiang): Use platform compatible API, see
105-
// https://github.com/ray-project/ray/pull/50170
10689
void CompleteWrite(const char *data, size_t len) {
107-
#if defined(__APPLE__) || defined(__linux__)
108-
[[maybe_unused]] auto x = write(write_handle_, data, len);
109-
#elif defined(_WIN32)
110-
DWORD bytes_written;
111-
[[maybe_unused]] auto x =
112-
WriteFile(write_handle_, data, (DWORD)len, &bytes_written, NULL);
113-
#endif
90+
RAY_CHECK_OK(::ray::CompleteWrite(write_handle_, data, len));
11491
}
11592

11693
private:

src/ray/util/spdlog_fd_sink.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
#include "ray/util/compat.h"
2020
#include "ray/util/util.h"
2121

22-
#if defined(__APPLE__) || defined(__linux__)
23-
#include <unistd.h>
24-
#elif defined(_WIN32)
25-
#include <windows.h>
26-
#endif
27-
2822
namespace ray {
2923

3024
// A sink which logs to the file descriptor.
@@ -39,26 +33,9 @@ class non_owned_fd_sink final : public spdlog::sinks::base_sink<Mutex> {
3933
void sink_it_(const spdlog::details::log_msg &msg) override {
4034
spdlog::memory_buf_t formatted;
4135
spdlog::sinks::base_sink<Mutex>::formatter_->format(msg, formatted);
42-
43-
#if defined(__APPLE__) || defined(__linux__)
44-
RAY_CHECK_EQ(write(fd_, formatted.data(), formatted.size()),
45-
static_cast<ssize_t>(formatted.size()))
46-
<< "Fails to write because " << strerror(errno);
47-
#elif defined(_WIN32)
48-
DWORD bytes_written;
49-
BOOL success =
50-
WriteFile(fd_, formatted.data(), (DWORD)formatted.size(), &bytes_written, NULL);
51-
RAY_CHECK(success);
52-
RAY_CHECK_EQ((DWORD)formatted.size(), bytes_written);
53-
#endif
54-
}
55-
void flush_() override {
56-
#if defined(__APPLE__) || defined(__linux__)
57-
RAY_CHECK_EQ(fdatasync(fd_), 0) << "Fails to flush file because " << strerror(errno);
58-
#elif defined(_WIN32)
59-
RAY_CHECK(FlushFileBuffers(fd_));
60-
#endif
36+
RAY_CHECK_OK(CompleteWrite(fd_, formatted.data(), formatted.size()));
6137
}
38+
void flush_() override { RAY_CHECK_OK(Flush(fd_)); }
6239

6340
private:
6441
MEMFD_TYPE_NON_UNIQUE fd_;

0 commit comments

Comments
 (0)