]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/status.cc
5b3dcf8e92e425f84eca90b6286004559770a1d7
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"
16 #include "port/port.h"
20 const char* Status::CopyState(const char* state
) {
22 const size_t cch
= std::strlen(state
) + 1; // +1 for the null terminator
23 char* result
= new char[cch
];
25 ret
= strncpy_s(result
, cch
, state
, cch
- 1);
26 result
[cch
- 1] = '\0';
30 const size_t cch
= std::strlen(state
) + 1; // +1 for the null terminator
31 return std::strncpy(new char[cch
], state
, cch
);
35 static const char* msgs
[static_cast<int>(Status::kMaxSubCode
)] = {
37 "Timeout Acquiring Mutex", // kMutexTimeout
38 "Timeout waiting to lock key", // kLockTimeout
39 "Failed to acquire lock due to max_num_locks limit", // kLockLimit
40 "No space left on device", // kNoSpace
41 "Deadlock", // kDeadlock
42 "Stale file handle", // kStaleFile
43 "Memory limit reached", // kMemoryLimit
44 "Space limit reached" // kSpaceLimit
47 Status::Status(Code _code
, SubCode _subcode
, const Slice
& msg
,
49 : code_(_code
), subcode_(_subcode
), sev_(kNoError
) {
51 assert(subcode_
!= kMaxSubCode
);
52 const size_t len1
= msg
.size();
53 const size_t len2
= msg2
.size();
54 const size_t size
= len1
+ (len2
? (2 + len2
) : 0);
55 char* const result
= new char[size
+ 1]; // +1 for null terminator
56 memcpy(result
, msg
.data(), len1
);
59 result
[len1
+ 1] = ' ';
60 memcpy(result
+ len1
+ 2, msg2
.data(), len2
);
62 result
[size
] = '\0'; // null terminator for C style string
66 std::string
Status::ToString() const {
76 type
= "Corruption: ";
79 type
= "Not implemented: ";
81 case kInvalidArgument
:
82 type
= "Invalid argument: ";
87 case kMergeInProgress
:
88 type
= "Merge in progress: ";
91 type
= "Result incomplete: ";
93 case kShutdownInProgress
:
94 type
= "Shutdown in progress: ";
97 type
= "Operation timed out: ";
100 type
= "Operation aborted: ";
103 type
= "Resource busy: ";
106 type
= "Operation expired: ";
109 type
= "Operation failed. Try again.: ";
112 snprintf(tmp
, sizeof(tmp
), "Unknown code(%d): ",
113 static_cast<int>(code()));
117 std::string
result(type
);
118 if (subcode_
!= kNone
) {
119 uint32_t index
= static_cast<int32_t>(subcode_
);
120 assert(sizeof(msgs
) > index
);
121 result
.append(msgs
[index
]);
124 if (state_
!= nullptr) {
125 result
.append(state_
);
130 } // namespace rocksdb