]>
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"
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
45 "No such file or directory", // kPathNotFound
48 Status::Status(Code _code
, SubCode _subcode
, const Slice
& msg
,
50 : code_(_code
), subcode_(_subcode
), sev_(kNoError
) {
52 assert(subcode_
!= kMaxSubCode
);
53 const size_t len1
= msg
.size();
54 const size_t len2
= msg2
.size();
55 const size_t size
= len1
+ (len2
? (2 + len2
) : 0);
56 char* const result
= new char[size
+ 1]; // +1 for null terminator
57 memcpy(result
, msg
.data(), len1
);
60 result
[len1
+ 1] = ' ';
61 memcpy(result
+ len1
+ 2, msg2
.data(), len2
);
63 result
[size
] = '\0'; // null terminator for C style string
67 std::string
Status::ToString() const {
77 type
= "Corruption: ";
80 type
= "Not implemented: ";
82 case kInvalidArgument
:
83 type
= "Invalid argument: ";
88 case kMergeInProgress
:
89 type
= "Merge in progress: ";
92 type
= "Result incomplete: ";
94 case kShutdownInProgress
:
95 type
= "Shutdown in progress: ";
98 type
= "Operation timed out: ";
101 type
= "Operation aborted: ";
104 type
= "Resource busy: ";
107 type
= "Operation expired: ";
110 type
= "Operation failed. Try again.: ";
113 snprintf(tmp
, sizeof(tmp
), "Unknown code(%d): ",
114 static_cast<int>(code()));
118 std::string
result(type
);
119 if (subcode_
!= kNone
) {
120 uint32_t index
= static_cast<int32_t>(subcode_
);
121 assert(sizeof(msgs
) > index
);
122 result
.append(msgs
[index
]);
125 if (state_
!= nullptr) {
126 result
.append(state_
);
131 } // namespace rocksdb