]>
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 the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same 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"
13 #include "port/port.h"
17 const char* Status::CopyState(const char* state
) {
19 new char[std::strlen(state
) + 1]; // +1 for the null terminator
20 std::strcpy(result
, state
);
24 Status::Status(Code _code
, SubCode _subcode
, const Slice
& msg
, const Slice
& msg2
)
25 : code_(_code
), subcode_(_subcode
) {
27 assert(subcode_
!= kMaxSubCode
);
28 const size_t len1
= msg
.size();
29 const size_t len2
= msg2
.size();
30 const size_t size
= len1
+ (len2
? (2 + len2
) : 0);
31 char* const result
= new char[size
+ 1]; // +1 for null terminator
32 memcpy(result
, msg
.data(), len1
);
35 result
[len1
+ 1] = ' ';
36 memcpy(result
+ len1
+ 2, msg2
.data(), len2
);
38 result
[size
] = '\0'; // null terminator for C style string
42 std::string
Status::ToString() const {
52 type
= "Corruption: ";
55 type
= "Not implemented: ";
57 case kInvalidArgument
:
58 type
= "Invalid argument: ";
63 case kMergeInProgress
:
64 type
= "Merge in progress: ";
67 type
= "Result incomplete: ";
69 case kShutdownInProgress
:
70 type
= "Shutdown in progress: ";
73 type
= "Operation timed out: ";
76 type
= "Operation aborted: ";
79 type
= "Resource busy: ";
82 type
= "Operation expired: ";
85 type
= "Operation failed. Try again.: ";
88 snprintf(tmp
, sizeof(tmp
), "Unknown code(%d): ",
89 static_cast<int>(code()));
93 std::string
result(type
);
94 if (subcode_
!= kNone
) {
95 uint32_t index
= static_cast<int32_t>(subcode_
);
96 assert(sizeof(msgs
) > index
);
97 result
.append(msgs
[index
]);
100 if (state_
!= nullptr) {
101 result
.append(state_
);
106 } // namespace rocksdb