From c11c24b79dce4e125e6c1292152bdef39e5a6b67 Mon Sep 17 00:00:00 2001 From: Evan Tschannen Date: Fri, 28 Feb 2020 14:56:10 -0800 Subject: [PATCH] removed the fdbrpc version of platform.h --- fdbbackup/backup.actor.cpp | 2 +- fdbcli/fdbcli.actor.cpp | 2 +- fdbclient/BackupContainer.actor.cpp | 2 +- fdbclient/MonitorLeader.actor.cpp | 2 +- fdbrpc/CMakeLists.txt | 1 - fdbrpc/Platform.cpp | 130 ---------------------------- fdbrpc/Platform.h | 37 -------- fdbrpc/fdbrpc.vcxproj | 2 - fdbrpc/fdbrpc.vcxproj.filters | 2 - fdbrpc/sim2.actor.cpp | 4 - fdbserver/fdbserver.actor.cpp | 1 - flow/Platform.cpp | 49 +++++++++++ flow/Platform.h | 5 ++ flow/crc32c.cpp | 2 +- 14 files changed, 59 insertions(+), 182 deletions(-) delete mode 100644 fdbrpc/Platform.cpp delete mode 100644 fdbrpc/Platform.h diff --git a/fdbbackup/backup.actor.cpp b/fdbbackup/backup.actor.cpp index a43ce79578..c6ec3fbd34 100644 --- a/fdbbackup/backup.actor.cpp +++ b/fdbbackup/backup.actor.cpp @@ -36,7 +36,7 @@ #include "fdbclient/BlobStore.h" #include "fdbclient/json_spirit/json_spirit_writer_template.h" -#include "fdbrpc/Platform.h" +#include "flow/Platform.h" #include #include diff --git a/fdbcli/fdbcli.actor.cpp b/fdbcli/fdbcli.actor.cpp index e1420f1cab..14425124ff 100644 --- a/fdbcli/fdbcli.actor.cpp +++ b/fdbcli/fdbcli.actor.cpp @@ -32,7 +32,7 @@ #include "fdbclient/FDBOptions.g.h" #include "flow/DeterministicRandom.h" -#include "fdbrpc/Platform.h" +#include "flow/Platform.h" #include "flow/SimpleOpt.h" diff --git a/fdbclient/BackupContainer.actor.cpp b/fdbclient/BackupContainer.actor.cpp index acc2a85a69..53ddf397df 100644 --- a/fdbclient/BackupContainer.actor.cpp +++ b/fdbclient/BackupContainer.actor.cpp @@ -25,7 +25,7 @@ #include "flow/UnitTest.h" #include "flow/Hash3.h" #include "fdbrpc/AsyncFileReadAhead.actor.h" -#include "fdbrpc/Platform.h" +#include "flow/Platform.h" #include "fdbclient/AsyncFileBlobStore.actor.h" #include "fdbclient/Status.h" #include "fdbclient/SystemData.h" diff --git a/fdbclient/MonitorLeader.actor.cpp b/fdbclient/MonitorLeader.actor.cpp index 90b569941f..9fa873adc5 100644 --- a/fdbclient/MonitorLeader.actor.cpp +++ b/fdbclient/MonitorLeader.actor.cpp @@ -23,7 +23,7 @@ #include "flow/ActorCollection.h" #include "flow/UnitTest.h" #include "fdbrpc/genericactors.actor.h" -#include "fdbrpc/Platform.h" +#include "flow/Platform.h" #include "flow/actorcompiler.h" // has to be last include std::pair< std::string, bool > ClusterConnectionFile::lookupClusterFileName( std::string const& filename ) { diff --git a/fdbrpc/CMakeLists.txt b/fdbrpc/CMakeLists.txt index 89afe57df7..49ff93e554 100644 --- a/fdbrpc/CMakeLists.txt +++ b/fdbrpc/CMakeLists.txt @@ -18,7 +18,6 @@ set(FDBRPC_SRCS Locality.cpp Net2FileSystem.cpp networksender.actor.h - Platform.cpp QueueModel.cpp ReplicationPolicy.cpp ReplicationTypes.cpp diff --git a/fdbrpc/Platform.cpp b/fdbrpc/Platform.cpp deleted file mode 100644 index 12af7491d0..0000000000 --- a/fdbrpc/Platform.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Platform.cpp - * - * This source file is part of the FoundationDB open source project - * - * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "fdbrpc/Platform.h" -#include -#include "flow/ActorCollection.h" -#include "flow/FaultInjection.h" - - -#ifdef _WIN32 -#include -#undef max -#undef min -#include -#include -#include -#include -#include -#include -#pragma comment(lib, "pdh.lib") - -// for SHGetFolderPath -#include -#pragma comment(lib, "Shell32.lib") - -#define CANONICAL_PATH_SEPARATOR '\\' -#endif - -#ifdef __unixish__ -#define CANONICAL_PATH_SEPARATOR '/' - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#endif - -#endif - -extern bool onlyBeforeSimulatorInit(); - -namespace platform { - -// Because the lambda used with nftw below cannot capture -int __eraseDirectoryRecurseiveCount; - -int eraseDirectoryRecursive(std::string const& dir) { - __eraseDirectoryRecurseiveCount = 0; -#ifdef _WIN32 - system( ("rd /s /q \"" + dir + "\"").c_str() ); -#elif defined(__linux__) || defined(__APPLE__) - int error = - nftw(dir.c_str(), - [](const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) -> int { - int r = remove(fpath); - if(r == 0) - ++__eraseDirectoryRecurseiveCount; - return r; - }, - 64, FTW_DEPTH | FTW_PHYS); - /* Looks like calling code expects this to continue silently if - the directory we're deleting doesn't exist in the first - place */ - if (error && errno != ENOENT) { - Error e = systemErrorCodeToError(); - TraceEvent(SevError, "EraseDirectoryRecursiveError").detail("Directory", dir).GetLastError().error(e); - throw e; - } -#else -#error Port me! -#endif - //INJECT_FAULT( platform_error, "eraseDirectoryRecursive" ); - return __eraseDirectoryRecurseiveCount; -} - -bool isSse42Supported() -{ -#if defined(_WIN32) - int info[4]; - __cpuid(info, 1); - return (info[2] & (1 << 20)) != 0; -#elif defined(__unixish__) - uint32_t eax, ebx, ecx, edx, level = 1, count = 0; - __cpuid_count(level, count, eax, ebx, ecx, edx); - return ((ecx >> 20) & 1) != 0; -#else - #error Port me! -#endif -} - -} // namespace platform diff --git a/fdbrpc/Platform.h b/fdbrpc/Platform.h deleted file mode 100644 index 8051057fd4..0000000000 --- a/fdbrpc/Platform.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Platform.h - * - * This source file is part of the FoundationDB open source project - * - * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FDBRPC_UTILS_H -#define FDBRPC_UTILS_H -#pragma once - -#include "flow/Platform.h" -#include - -namespace platform { - -// Avoid in production code: not atomic, not fast, not reliable in all environments -int eraseDirectoryRecursive(std::string const& directory); - -bool isSse42Supported(); - -} // namespace platform - -#endif diff --git a/fdbrpc/fdbrpc.vcxproj b/fdbrpc/fdbrpc.vcxproj index e0f60937d1..e579ab001c 100644 --- a/fdbrpc/fdbrpc.vcxproj +++ b/fdbrpc/fdbrpc.vcxproj @@ -20,7 +20,6 @@ - @@ -84,7 +83,6 @@ - diff --git a/fdbrpc/fdbrpc.vcxproj.filters b/fdbrpc/fdbrpc.vcxproj.filters index ca28e644e9..0c84599d09 100644 --- a/fdbrpc/fdbrpc.vcxproj.filters +++ b/fdbrpc/fdbrpc.vcxproj.filters @@ -70,7 +70,6 @@ zlib - @@ -131,7 +130,6 @@ - diff --git a/fdbrpc/sim2.actor.cpp b/fdbrpc/sim2.actor.cpp index 01411f3c88..2ff9d45531 100644 --- a/fdbrpc/sim2.actor.cpp +++ b/fdbrpc/sim2.actor.cpp @@ -95,10 +95,6 @@ public: }; } -bool onlyBeforeSimulatorInit() { - return g_network->isSimulated() && g_simulator.getAllProcesses().empty(); -} - const UID TOKEN_ENDPOINT_NOT_FOUND(-1, -1); ISimulator* g_pSimulator = 0; diff --git a/fdbserver/fdbserver.actor.cpp b/fdbserver/fdbserver.actor.cpp index 53989f0210..5b7f4959b2 100644 --- a/fdbserver/fdbserver.actor.cpp +++ b/fdbserver/fdbserver.actor.cpp @@ -52,7 +52,6 @@ #include #include "fdbserver/Status.h" #include "fdbrpc/Net2FileSystem.h" -#include "fdbrpc/Platform.h" #include "fdbrpc/AsyncFileCached.actor.h" #include "fdbserver/CoroFlow.h" #include "flow/TLSPolicy.h" diff --git a/flow/Platform.cpp b/flow/Platform.cpp index e803612f23..55e617f273 100644 --- a/flow/Platform.cpp +++ b/flow/Platform.cpp @@ -77,6 +77,7 @@ #include #include #include +#include /* Needed for disk capacity */ #include @@ -2502,6 +2503,54 @@ void outOfMemory() { criticalError(FDB_EXIT_NO_MEM, "OutOfMemory", "Out of memory"); } + +// Because the lambda used with nftw below cannot capture +int __eraseDirectoryRecurseiveCount; + +int eraseDirectoryRecursive(std::string const& dir) { + __eraseDirectoryRecurseiveCount = 0; +#ifdef _WIN32 + system( ("rd /s /q \"" + dir + "\"").c_str() ); +#elif defined(__linux__) || defined(__APPLE__) + int error = + nftw(dir.c_str(), + [](const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) -> int { + int r = remove(fpath); + if(r == 0) + ++__eraseDirectoryRecurseiveCount; + return r; + }, + 64, FTW_DEPTH | FTW_PHYS); + /* Looks like calling code expects this to continue silently if + the directory we're deleting doesn't exist in the first + place */ + if (error && errno != ENOENT) { + Error e = systemErrorCodeToError(); + TraceEvent(SevError, "EraseDirectoryRecursiveError").detail("Directory", dir).GetLastError().error(e); + throw e; + } +#else +#error Port me! +#endif + //INJECT_FAULT( platform_error, "eraseDirectoryRecursive" ); + return __eraseDirectoryRecurseiveCount; +} + +bool isSse42Supported() +{ +#if defined(_WIN32) + int info[4]; + __cpuid(info, 1); + return (info[2] & (1 << 20)) != 0; +#elif defined(__unixish__) + uint32_t eax, ebx, ecx, edx, level = 1, count = 0; + __cpuid_count(level, count, eax, ebx, ecx, edx); + return ((ecx >> 20) & 1) != 0; +#else + #error Port me! +#endif +} + } // namespace platform extern "C" void criticalError(int exitCode, const char *type, const char *message) { diff --git a/flow/Platform.h b/flow/Platform.h index 282f465df6..4d2d5ed357 100644 --- a/flow/Platform.h +++ b/flow/Platform.h @@ -388,6 +388,11 @@ size_t raw_backtrace(void** addresses, int maxStackDepth); std::string get_backtrace(); std::string format_backtrace(void **addresses, int numAddresses); +// Avoid in production code: not atomic, not fast, not reliable in all environments +int eraseDirectoryRecursive(std::string const& directory); + +bool isSse42Supported(); + } // namespace platform #ifdef __linux__ diff --git a/flow/crc32c.cpp b/flow/crc32c.cpp index 150808fd7e..12f308a3a5 100644 --- a/flow/crc32c.cpp +++ b/flow/crc32c.cpp @@ -34,7 +34,7 @@ #include #include #include -#include "fdbrpc/Platform.h" +#include "flow/Platform.h" #include "crc32c-generated-constants.cpp" static uint32_t append_trivial(uint32_t crc, const uint8_t * input, size_t length)