Skip to content

Commit

Permalink
Revert "[core] Compatibile function for file descriptor" (ray-project…
Browse files Browse the repository at this point in the history
  • Loading branch information
aslonnie authored and xsuler committed Mar 4, 2025
1 parent 0850323 commit 3886cdb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 187 deletions.
5 changes: 0 additions & 5 deletions src/ray/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ ray_cc_library(
ray_cc_library(
name = "compat",
hdrs = ["compat.h"],
srcs = ["compat.cc"],
deps = [
":logging",
"//src/ray/common:status",
],
)

ray_cc_library(
Expand Down
84 changes: 0 additions & 84 deletions src/ray/util/compat.cc

This file was deleted.

30 changes: 0 additions & 30 deletions src/ray/util/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#pragma once

#include "ray/common/status.h"

// Workaround for multithreading on XCode 9, see
// https://issues.apache.org/jira/browse/ARROW-1622 and
// https://github.com/tensorflow/tensorflow/issues/13220#issuecomment-331579775
Expand All @@ -49,10 +47,6 @@ mach_port_t pthread_mach_thread_np(pthread_t);
#endif /* _MACH_PORT_T */
#endif /* __APPLE__ */

#if defined(__APPLE__) || defined(__linux__)
#include <unistd.h>
#endif

#ifdef _WIN32
#ifndef _WINDOWS_
#ifndef WIN32_LEAN_AND_MEAN // Sorry for the inconvenience. Please include any related
Expand All @@ -78,27 +72,3 @@ mach_port_t pthread_mach_thread_np(pthread_t);
// since fd values can get re-used by the operating system.
#define MEMFD_TYPE std::pair<MEMFD_TYPE_NON_UNIQUE, int64_t>
#define INVALID_UNIQUE_FD_ID 0

namespace ray {
#if defined(__APPLE__) || defined(__linux__)
inline int GetStdoutFd() { return STDOUT_FILENO; }
inline int GetStderrFd() { return STDERR_FILENO; }
inline MEMFD_TYPE_NON_UNIQUE GetStdoutHandle() { return STDOUT_FILENO; }
inline MEMFD_TYPE_NON_UNIQUE GetStderrHandle() { return STDERR_FILENO; }
#elif defined(_WIN32)
inline int GetStdoutFd() { return _fileno(stdout); }
inline int GetStderrFd() { return _fileno(stderr); }
inline MEMFD_TYPE_NON_UNIQUE GetStdoutHandle() { return GetStdHandle(STD_OUTPUT_HANDLE); }
inline MEMFD_TYPE_NON_UNIQUE GetStderrHandle() { return GetStdHandle(STD_ERROR_HANDLE); }
#endif

// Write the whole content into file descriptor, if any error happens, or actual written
// content is less than expected, IO error status will be returned.
Status CompleteWrite(MEMFD_TYPE_NON_UNIQUE fd, const char *data, size_t len);
// Flush the given file descriptor, if EIO happens, error message is logged and process
// exits directly. Reference to fsyncgate: https://wiki.postgresql.org/wiki/Fsync_Errors
Status Flush(MEMFD_TYPE_NON_UNIQUE fd);
// Close the given file descriptor, if any error happens, IO error status will be
// returned.
Status Close(MEMFD_TYPE_NON_UNIQUE fd);
} // namespace ray
16 changes: 12 additions & 4 deletions src/ray/util/stream_redirection_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ namespace ray {

namespace {

#if defined(__APPLE__) || defined(__linux__)
int GetStdoutHandle() { return STDOUT_FILENO; }
int GetStderrHandle() { return STDERR_FILENO; }
#elif defined(_WIN32)
int GetStdoutHandle() { return _fileno(stdout); }
int GetStderrHandle() { return _fileno(stderr); }
#endif

// TODO(hjiang): Revisit later, should be able to save some heap allocation with
// absl::InlinedVector.
//
Expand Down Expand Up @@ -81,12 +89,12 @@ void FlushOnRedirectedStream(int stream_fd) {
} // namespace

void RedirectStdout(const StreamRedirectionOption &opt) {
RedirectStream(GetStdoutFd(), opt);
RedirectStream(GetStdoutHandle(), opt);
}
void RedirectStderr(const StreamRedirectionOption &opt) {
RedirectStream(GetStderrFd(), opt);
RedirectStream(GetStderrHandle(), opt);
}
void FlushOnRedirectedStdout() { FlushOnRedirectedStream(GetStdoutFd()); }
void FlushOnRedirectedStderr() { FlushOnRedirectedStream(GetStderrFd()); }
void FlushOnRedirectedStdout() { FlushOnRedirectedStream(GetStdoutHandle()); }
void FlushOnRedirectedStderr() { FlushOnRedirectedStream(GetStderrHandle()); }

} // namespace ray
12 changes: 0 additions & 12 deletions src/ray/util/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,3 @@ ray_cc_test(
size = "small",
tags = ["team:core"],
)

ray_cc_test(
name = "compat_test",
srcs = ["compat_test.cc"],
deps = [
"//src/ray/util:compat",
"//src/ray/util:filesystem",
"@com_google_googletest//:gtest_main",
],
size = "small",
tags = ["team:core"],
)
52 changes: 0 additions & 52 deletions src/ray/util/tests/compat_test.cc

This file was deleted.

0 comments on commit 3886cdb

Please sign in to comment.