diff --git a/LICENSE.txt b/LICENSE.txt index e224581f63..26536905d3 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -414,22 +414,6 @@ be/src/olap/skiplist.h : BSD-style license -------------------------------------------------------------------------------- -be/src/olap/new_status.h : BSD-style license - - Copyright (c) 2011 The LevelDB Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. See the AUTHORS file for names of contributors. - --------------------------------------------------------------------------------- - -be/src/olap/new_status.cpp : BSD-style license - - Copyright (c) 2011 The LevelDB Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. See the AUTHORS file for names of contributors. - --------------------------------------------------------------------------------- - be/src/util/murmur_hash3.h : licensed under the following terms: MurmurHash3 was written by Austin Appleby, and is placed in the public diff --git a/be/src/common/status.h b/be/src/common/status.h index e095f886cf..4a56682981 100644 --- a/be/src/common/status.h +++ b/be/src/common/status.h @@ -131,6 +131,8 @@ public: bool is_end_of_file() const { return code() == TStatusCode::END_OF_FILE; } bool is_not_found() const { return code() == TStatusCode::NOT_FOUND; } + + bool is_io_error() const {return code() == TStatusCode::IO_ERROR; } // Convert into TStatus. Call this if 'status_container' contains an optional // TStatus field named 'status'. This also sets __isset.status. template diff --git a/be/src/olap/CMakeLists.txt b/be/src/olap/CMakeLists.txt index 4c06b46a6f..17c7ef425e 100644 --- a/be/src/olap/CMakeLists.txt +++ b/be/src/olap/CMakeLists.txt @@ -47,7 +47,6 @@ add_library(Olap STATIC memtable.cpp memtable_flush_executor.cpp merger.cpp - new_status.cpp null_predicate.cpp olap_cond.cpp olap_index.cpp diff --git a/be/src/olap/new_status.cpp b/be/src/olap/new_status.cpp deleted file mode 100644 index 3fcb19544c..0000000000 --- a/be/src/olap/new_status.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 2011 The LevelDB Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. See the AUTHORS file for names of contributors. - -#include "olap/new_status.h" - -#include -#include "common/logging.h" - -namespace doris { - -std::string ErrnoToString(int err) { - char errmsg[128]; - char* ret = strerror_r(err, errmsg, 128); - if (ret != errmsg) { - strncpy(errmsg, ret, 128); - errmsg[127] = '\0'; - } - return std::string(errmsg); -} - -NewStatus IOError(const std::string& context, int err) { - switch (err) { - case ENOENT: - return NewStatus::NotFound(context, ErrnoToString(err), err); - case EEXIST: - return NewStatus::AlreadyExist(context, ErrnoToString(err), err); - case EOPNOTSUPP: - return NewStatus::NotSupported(context, ErrnoToString(err), err); - case EIO: - return NewStatus::DiskFailure(context, ErrnoToString(err), err); - case ENODEV: - return NewStatus::DiskFailure(context, ErrnoToString(err), err); - case ENXIO: - return NewStatus::DiskFailure(context, ErrnoToString(err), err); - case EROFS: - return NewStatus::DiskFailure(context, ErrnoToString(err), err); - } - return NewStatus::IOError(context, ErrnoToString(err), err); -} - -NewStatus::NewStatus(Code code, const Slice& msg, const Slice& msg2, int32_t posix_code) - : _code(code), _posix_code(posix_code) { - DCHECK(code != kOk); - const uint32_t len1 = msg.size; - const uint32_t len2 = msg2.size; - const uint32_t size = len1 + (len2 ? (2 + len2) : 0); - char* result = new char[size + 4]; - memcpy(result, &size, sizeof(size)); - memcpy(result + 4, msg.data, len1); - if (len2) { - result[len1 + 4] = ':'; - result[len1 + 5] = ' '; - memcpy(result + len1 + 6, msg2.data, len2); - } - _state = result; -} - -const char* NewStatus::CopyState(const char* state) { - uint32_t size; - memcpy(&size, state, sizeof(size)); - char* result = new char[size + 4]; - memcpy(result, state, size + 4); - return result; -} - -std::string NewStatus::CodeAsString() const { - const char* type = nullptr; - switch (_code) { - case kOk: - type = "OK"; - break; - case kNotFound: - type = "NotFound"; - break; - case kCorruption: - type = "Corruption"; - break; - case kNotSupported: - type = "Not implemented"; - break; - case kInvalidArgument: - type = "Invalid argument"; - break; - case kAlreadyExist: - type = "Already Exist"; - break; - case kNoSpace: - type = "No Space"; - break; - case kEndOfFile: - type = "End Of File"; - break; - case kDiskFailure: - type = "Disk Failure"; - break; - case kIOError: - type = "IO error"; - break; - case kTimedOut: - type = "Timed Out"; - break; - case kMemoryLimitExceeded: - type = "Memory Limit Exceeded"; - break; - case kDeadLock: - type = "Dead Lock"; - break; - } - - return std::string(type); -} - -std::string NewStatus::ToString() const { - std::string result(CodeAsString()); - if (code() == kOk) { - return result; - } - - result.append(": "); - uint32_t length; - memcpy(&length, _state, sizeof(length)); - result.append(_state + 4, length); - - if (_posix_code != -1) { - char buf[64]; - snprintf(buf, sizeof(buf), ", errno=%d", _posix_code); - result.append(buf); - } - - return result; -} - -} // namespace doris diff --git a/be/src/olap/new_status.h b/be/src/olap/new_status.h deleted file mode 100644 index 73e1cad699..0000000000 --- a/be/src/olap/new_status.h +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (c) 2011 The LevelDB Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. See the AUTHORS file for names of contributors. - -#ifndef DORIS_BE_SRC_OLAP_STATUS_H -#define DORIS_BE_SRC_OLAP_STATUS_H - -#include -#include "util/slice.h" - -namespace doris { - -#define WARN_AND_RETURN(status) do { \ - const NewStatus& s = (status); \ - LOG(WARNING) << s.ToString(); \ - return s; \ -} while (0); - -class NewStatus { -public: - // Create a success status. - NewStatus() : _code(kOk), _posix_code(0), _state(nullptr) {} - ~NewStatus() { delete[] _state; } - - // Copy the specified status. - NewStatus(const NewStatus& s); - void operator=(const NewStatus& s); - - // Return a success status. - static NewStatus OK() { return NewStatus(); } - - // Return error status of an appropriate type. - static NewStatus NotFound(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kNotFound, msg, msg2, posix_code); - } - static NewStatus Corruption(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kCorruption, msg, msg2, posix_code); - } - static NewStatus NotSupported(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kNotSupported, msg, msg2, posix_code); - } - static NewStatus InvalidArgument(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kInvalidArgument, msg, msg2, posix_code); - } - static NewStatus AlreadyExist(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kAlreadyExist, msg, msg2, posix_code); - } - static NewStatus NoSpace(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kNoSpace, msg, msg2, posix_code); - } - static NewStatus EndOfFile(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kEndOfFile, msg, msg2, posix_code); - } - static NewStatus DiskFailure(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kDiskFailure, msg, msg2, posix_code); - } - static NewStatus IOError(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kIOError, msg, msg2, posix_code); - } - static NewStatus TimedOut(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kTimedOut, msg, msg2, posix_code); - } - static NewStatus MemoryLimitExceeded(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kMemoryLimitExceeded, msg, msg2, posix_code); - } - static NewStatus DeadLock(const Slice& msg, const Slice& msg2 = Slice(), - int32_t posix_code = -1) { - return NewStatus(kDeadLock, msg, msg2, posix_code); - } - - // Returns true iff the status indicates success. - bool ok() const { return code() == kOk; } - - // Returns true iff the status indicates a NotFound error. - bool IsNotFound() const { return code() == kNotFound; } - - // Returns true iff the status indicates a Corruption error. - bool IsCorruption() const { return code() == kCorruption; } - - // Returns true iff the status indicates a NotSupportedError. - bool IsNotSupported() const { return code() == kNotSupported; } - - // Returns true iff the status indicates an InvalidArgument. - bool IsInvalidArgument() const { return code() == kInvalidArgument; } - - // Returns true iff the status indicates an AlreadyExist. - bool IsAlreadyExist() const { return code() == kAlreadyExist; } - - // Returns true iff the status indicates an NoSpace Error. - bool IsNoSpace() const { return code() == kNoSpace; } - - // Returns true iff the status indicates an end of file. - bool IsEndOfFile() const { return code() == kEndOfFile; } - - // Returns true iff the status indicates an IOError. - bool IsDiskFailure() const { return code() == kDiskFailure; } - - // Returns true iff the status indicates an IOError. - bool IsIOError() const { return code() == kIOError; } - - // Returns true iff the status indicates timed out. - bool IsTimedOut() const { return code() == kTimedOut; } - - // Returns true iff the status indicates a memory limit error. - bool IsMemoryLimitExceeded() const { return code() == kMemoryLimitExceeded; } - - // Returns true iff the status indicates a DeadLock. - bool IsDeadLock() const { return code() == kDeadLock; } - - // Return a string representation of this status suitable for printing. - // Returns the string "OK" for success. - std::string ToString() const; - - // return A string representation of the status code, without the message - // text or POSIX code information - std::string CodeAsString() const; - - // return The Posix code associated with this Status Object - inline int32_t posix_code() const { return _posix_code; } - -private: - enum Code { - kOk = 0, - kNotFound = 1, - kCorruption = 2, - kNotSupported = 3, - kInvalidArgument = 4, - kAlreadyExist = 5, - kNoSpace = 6, - kEndOfFile = 7, - kIOError = 8, - kDiskFailure = 9, - kTimedOut = 10, - kMemoryLimitExceeded = 11, - kDeadLock = 12 - }; - - Code _code; - Code code() const { return _code; } - - // The POSIX code accociated with the NewStatus object, - // if _posix_code == -1, indicates no posix_code. - int32_t _posix_code; - - // OK status has a nullptr _state. Otherwise, _state is a new[] array - // of the following form: - // _state[0..3] == length of message - // _state[4..] == message - const char* _state; - - NewStatus(Code code, const Slice& msg, const Slice& msg2, int32_t posix_code); - static const char* CopyState(const char* s); -}; - -inline NewStatus::NewStatus(const NewStatus& s) - : _code(s._code), _posix_code(s._posix_code) { - _state = (s._state == nullptr) ? nullptr : CopyState(s._state); -} - -inline void NewStatus::operator=(const NewStatus& s) { - // The following condition catches both aliasing (when this == &s), - // and the common case where both s and *this are ok. - if (_state != s._state) { - _code = s._code; - _posix_code = s._posix_code; - delete[] _state; - _state = (s._state == nullptr) ? nullptr : CopyState(s._state); - } -} - -std::string ErrnoToString(int err); -NewStatus IOError(const std::string& context, int err); - - -} // namespace doris - -#endif // DORIS_BE_SRC_OLAP_STATUS_H diff --git a/be/src/olap/rowset/rowset.h b/be/src/olap/rowset/rowset.h index 9800d6e8cf..944a583b59 100644 --- a/be/src/olap/rowset/rowset.h +++ b/be/src/olap/rowset/rowset.h @@ -23,7 +23,6 @@ #include "gen_cpp/olap_file.pb.h" #include "gutil/macros.h" -#include "olap/new_status.h" #include "olap/rowset/rowset_meta.h" #include "util/once.h" diff --git a/be/src/olap/rowset/rowset_meta.h b/be/src/olap/rowset/rowset_meta.h index d588d75295..dfb80c79c0 100644 --- a/be/src/olap/rowset/rowset_meta.h +++ b/be/src/olap/rowset/rowset_meta.h @@ -24,7 +24,6 @@ #include #include -#include "olap/new_status.h" #include "olap/olap_common.h" #include "json2pb/json_to_pb.h" #include "json2pb/pb_to_json.h" diff --git a/be/src/olap/rowset/rowset_meta_manager.h b/be/src/olap/rowset/rowset_meta_manager.h index 7abc3b8fca..fecf83bfe7 100644 --- a/be/src/olap/rowset/rowset_meta_manager.h +++ b/be/src/olap/rowset/rowset_meta_manager.h @@ -22,7 +22,6 @@ #include "olap/rowset/rowset_meta.h" #include "olap/olap_meta.h" -#include "olap/new_status.h" using std::string; diff --git a/be/src/olap/utils.cpp b/be/src/olap/utils.cpp index 1d2ad5e8b1..75d4e0408f 100644 --- a/be/src/olap/utils.cpp +++ b/be/src/olap/utils.cpp @@ -38,8 +38,9 @@ #include #include "common/logging.h" +#include "common/status.h" +#include "util/errno.h" #include "gutil/strings/substitute.h" -#include "olap/new_status.h" #include "olap/olap_common.h" #include "olap/olap_define.h" @@ -1424,6 +1425,24 @@ int Errno::no() { return errno; } +static Status disk_error(const std::string& context, int16_t err) { + switch (err) { + case ENOENT: + return Status::NotFound(context, err, errno_to_string(err)); + case EEXIST: + return Status::AlreadyExist(context, err, errno_to_string(err)); + case EOPNOTSUPP: + return Status::NotSupported(context, err, errno_to_string(err)); + case EIO: + case ENODEV: + case ENXIO: + case EROFS: + return Status::IOError(context, err, errno_to_string(err)); + default: + return Status::InternalError(context, err, errno_to_string(err)); + } +} + OLAPStatus dir_walk(const string& root, set* dirs, set* files) { @@ -1432,9 +1451,10 @@ OLAPStatus dir_walk(const string& root, struct dirent* direntp = NULL; dirp = opendir(root.c_str()); if (dirp == nullptr) { - NewStatus status = IOError(strings::Substitute("opendir $0 failed", root), errno); - LOG(WARNING) << status.ToString(); - if (status.IsDiskFailure()) { + Status status = disk_error("opendir failed", errno); + + LOG(WARNING) << status.to_string(); + if (status.is_io_error()) { return OLAP_ERR_DISK_FAILURE; } else { return OLAP_ERR_INIT_FAILED; diff --git a/be/test/olap/olap_snapshot_converter_test.cpp b/be/test/olap/olap_snapshot_converter_test.cpp old mode 100755 new mode 100644 index 87447ff1eb..64ed1b0eb1 --- a/be/test/olap/olap_snapshot_converter_test.cpp +++ b/be/test/olap/olap_snapshot_converter_test.cpp @@ -29,7 +29,6 @@ #include "olap/rowset/alpha_rowset.h" #include "olap/rowset/alpha_rowset_meta.h" #include "olap/txn_manager.h" -#include "olap/new_status.h" #include #include "boost/filesystem.hpp" #include "json2pb/json_to_pb.h" diff --git a/be/test/olap/rowset/rowset_meta_manager_test.cpp b/be/test/olap/rowset/rowset_meta_manager_test.cpp index 4502446fbf..55a0fd83fa 100644 --- a/be/test/olap/rowset/rowset_meta_manager_test.cpp +++ b/be/test/olap/rowset/rowset_meta_manager_test.cpp @@ -24,7 +24,6 @@ #include "olap/olap_meta.h" #include "olap/rowset/rowset_meta_manager.h" #include "olap/storage_engine.h" -#include "olap/new_status.h" #include "boost/filesystem.hpp" #include "json2pb/json_to_pb.h" diff --git a/be/test/olap/tablet_mgr_test.cpp b/be/test/olap/tablet_mgr_test.cpp index 6bdd09810e..b5af488d82 100644 --- a/be/test/olap/tablet_mgr_test.cpp +++ b/be/test/olap/tablet_mgr_test.cpp @@ -27,7 +27,6 @@ #include "olap/rowset/alpha_rowset_meta.h" #include "olap/tablet_meta_manager.h" #include "olap/txn_manager.h" -#include "olap/new_status.h" #include "boost/filesystem.hpp" #include "json2pb/json_to_pb.h" diff --git a/be/test/olap/txn_manager_test.cpp b/be/test/olap/txn_manager_test.cpp index e156839dca..ed99d78847 100644 --- a/be/test/olap/txn_manager_test.cpp +++ b/be/test/olap/txn_manager_test.cpp @@ -27,7 +27,6 @@ #include "olap/rowset/rowset_meta_manager.h" #include "olap/rowset/alpha_rowset_meta.h" #include "olap/txn_manager.h" -#include "olap/new_status.h" #include "boost/filesystem.hpp" #include "json2pb/json_to_pb.h"