]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/status.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
10 #include "rocksdb/status.h"
18 #include "port/port.h"
20 namespace ROCKSDB_NAMESPACE
{
22 std::unique_ptr
<const char[]> Status::CopyState(const char* s
) {
23 const size_t cch
= std::strlen(s
) + 1; // +1 for the null terminator
24 char* rv
= new char[cch
];
25 std::strncpy(rv
, s
, cch
);
26 return std::unique_ptr
<const char[]>(rv
);
29 static const char* msgs
[static_cast<int>(Status::kMaxSubCode
)] = {
31 "Timeout Acquiring Mutex", // kMutexTimeout
32 "Timeout waiting to lock key", // kLockTimeout
33 "Failed to acquire lock due to max_num_locks limit", // kLockLimit
34 "No space left on device", // kNoSpace
35 "Deadlock", // kDeadlock
36 "Stale file handle", // kStaleFile
37 "Memory limit reached", // kMemoryLimit
38 "Space limit reached", // kSpaceLimit
39 "No such file or directory", // kPathNotFound
40 // KMergeOperandsInsufficientCapacity
41 "Insufficient capacity for merge operands",
42 // kManualCompactionPaused
43 "Manual compaction paused",
44 " (overwritten)", // kOverwritten, subcode of OK
45 "Txn not prepared", // kTxnNotPrepared
46 "IO fenced off", // kIOFenced
49 Status::Status(Code _code
, SubCode _subcode
, const Slice
& msg
,
50 const Slice
& msg2
, Severity sev
)
57 assert(subcode_
!= kMaxSubCode
);
58 const size_t len1
= msg
.size();
59 const size_t len2
= msg2
.size();
60 const size_t size
= len1
+ (len2
? (2 + len2
) : 0);
61 char* const result
= new char[size
+ 1]; // +1 for null terminator
62 memcpy(result
, msg
.data(), len1
);
65 result
[len1
+ 1] = ' ';
66 memcpy(result
+ len1
+ 2, msg2
.data(), len2
);
68 result
[size
] = '\0'; // null terminator for C style string
72 std::string
Status::ToString() const {
73 #ifdef ROCKSDB_ASSERT_STATUS_CHECKED
75 #endif // ROCKSDB_ASSERT_STATUS_CHECKED
76 const char* type
= nullptr;
84 type
= "Corruption: ";
87 type
= "Not implemented: ";
89 case kInvalidArgument
:
90 type
= "Invalid argument: ";
95 case kMergeInProgress
:
96 type
= "Merge in progress: ";
99 type
= "Result incomplete: ";
101 case kShutdownInProgress
:
102 type
= "Shutdown in progress: ";
105 type
= "Operation timed out: ";
108 type
= "Operation aborted: ";
111 type
= "Resource busy: ";
114 type
= "Operation expired: ";
117 type
= "Operation failed. Try again.: ";
119 case kCompactionTooLarge
:
120 type
= "Compaction too large: ";
122 case kColumnFamilyDropped
:
123 type
= "Column family dropped: ";
130 if (type
== nullptr) {
131 // This should not happen since `code_` should be a valid non-`kMaxCode`
132 // member of the `Code` enum. The above switch-statement should have had a
133 // case assigning `type` to a corresponding string.
135 snprintf(tmp
, sizeof(tmp
), "Unknown code(%d): ", static_cast<int>(code()));
138 std::string
result(type
);
139 if (subcode_
!= kNone
) {
140 uint32_t index
= static_cast<int32_t>(subcode_
);
141 assert(sizeof(msgs
) / sizeof(msgs
[0]) > index
);
142 result
.append(msgs
[index
]);
145 if (state_
!= nullptr) {
146 if (subcode_
!= kNone
) {
149 result
.append(state_
.get());
154 } // namespace ROCKSDB_NAMESPACE