]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/status.cc
bump version to 19.2.0-pve1
[ceph.git] / ceph / src / rocksdb / util / status.cc
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
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"
1e59de90 11
7c673cae 12#include <stdio.h>
11fdf7f2
TL
13#ifdef OS_WIN
14#include <string.h>
15#endif
7c673cae 16#include <cstring>
1e59de90 17
7c673cae
FG
18#include "port/port.h"
19
f67539c2 20namespace ROCKSDB_NAMESPACE {
7c673cae 21
1e59de90
TL
22std::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);
7c673cae
FG
27}
28
11fdf7f2
TL
29static 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
494da23a
TL
38 "Space limit reached", // kSpaceLimit
39 "No such file or directory", // kPathNotFound
f67539c2
TL
40 // KMergeOperandsInsufficientCapacity
41 "Insufficient capacity for merge operands",
42 // kManualCompactionPaused
43 "Manual compaction paused",
20effc67
TL
44 " (overwritten)", // kOverwritten, subcode of OK
45 "Txn not prepared", // kTxnNotPrepared
46 "IO fenced off", // kIOFenced
11fdf7f2
TL
47};
48
49Status::Status(Code _code, SubCode _subcode, const Slice& msg,
1e59de90
TL
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) {
7c673cae
FG
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
1e59de90 69 state_.reset(result);
7c673cae
FG
70}
71
72std::string Status::ToString() const {
20effc67
TL
73#ifdef ROCKSDB_ASSERT_STATUS_CHECKED
74 checked_ = true;
75#endif // ROCKSDB_ASSERT_STATUS_CHECKED
1e59de90 76 const char* type = nullptr;
7c673cae
FG
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;
1e59de90
TL
119 case kCompactionTooLarge:
120 type = "Compaction too large: ";
121 break;
f67539c2
TL
122 case kColumnFamilyDropped:
123 type = "Column family dropped: ";
124 break;
1e59de90
TL
125 case kMaxCode:
126 assert(false);
7c673cae
FG
127 break;
128 }
1e59de90
TL
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 }
7c673cae
FG
138 std::string result(type);
139 if (subcode_ != kNone) {
140 uint32_t index = static_cast<int32_t>(subcode_);
20effc67 141 assert(sizeof(msgs) / sizeof(msgs[0]) > index);
7c673cae
FG
142 result.append(msgs[index]);
143 }
144
145 if (state_ != nullptr) {
1e59de90
TL
146 if (subcode_ != kNone) {
147 result.append(": ");
148 }
149 result.append(state_.get());
7c673cae
FG
150 }
151 return result;
152}
153
f67539c2 154} // namespace ROCKSDB_NAMESPACE