]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/status.cc
bump version to 18.2.2-pve1
[ceph.git] / 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).
5 //
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.
9
10 #include "rocksdb/status.h"
11
12 #include <stdio.h>
13 #ifdef OS_WIN
14 #include <string.h>
15 #endif
16 #include <cstring>
17
18 #include "port/port.h"
19
20 namespace ROCKSDB_NAMESPACE {
21
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);
27 }
28
29 static const char* msgs[static_cast<int>(Status::kMaxSubCode)] = {
30 "", // kNone
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
47 };
48
49 Status::Status(Code _code, SubCode _subcode, const Slice& msg,
50 const Slice& msg2, Severity sev)
51 : code_(_code),
52 subcode_(_subcode),
53 sev_(sev),
54 retryable_(false),
55 data_loss_(false),
56 scope_(0) {
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);
63 if (len2) {
64 result[len1] = ':';
65 result[len1 + 1] = ' ';
66 memcpy(result + len1 + 2, msg2.data(), len2);
67 }
68 result[size] = '\0'; // null terminator for C style string
69 state_.reset(result);
70 }
71
72 std::string Status::ToString() const {
73 #ifdef ROCKSDB_ASSERT_STATUS_CHECKED
74 checked_ = true;
75 #endif // ROCKSDB_ASSERT_STATUS_CHECKED
76 const char* type = nullptr;
77 switch (code_) {
78 case kOk:
79 return "OK";
80 case kNotFound:
81 type = "NotFound: ";
82 break;
83 case kCorruption:
84 type = "Corruption: ";
85 break;
86 case kNotSupported:
87 type = "Not implemented: ";
88 break;
89 case kInvalidArgument:
90 type = "Invalid argument: ";
91 break;
92 case kIOError:
93 type = "IO error: ";
94 break;
95 case kMergeInProgress:
96 type = "Merge in progress: ";
97 break;
98 case kIncomplete:
99 type = "Result incomplete: ";
100 break;
101 case kShutdownInProgress:
102 type = "Shutdown in progress: ";
103 break;
104 case kTimedOut:
105 type = "Operation timed out: ";
106 break;
107 case kAborted:
108 type = "Operation aborted: ";
109 break;
110 case kBusy:
111 type = "Resource busy: ";
112 break;
113 case kExpired:
114 type = "Operation expired: ";
115 break;
116 case kTryAgain:
117 type = "Operation failed. Try again.: ";
118 break;
119 case kCompactionTooLarge:
120 type = "Compaction too large: ";
121 break;
122 case kColumnFamilyDropped:
123 type = "Column family dropped: ";
124 break;
125 case kMaxCode:
126 assert(false);
127 break;
128 }
129 char tmp[30];
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.
134 assert(false);
135 snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", static_cast<int>(code()));
136 type = tmp;
137 }
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]);
143 }
144
145 if (state_ != nullptr) {
146 if (subcode_ != kNone) {
147 result.append(": ");
148 }
149 result.append(state_.get());
150 }
151 return result;
152 }
153
154 } // namespace ROCKSDB_NAMESPACE