Skip to content

Commit f6faa7e

Browse files
daverigbytrondn
authored andcommitted
CBD-6348: [BP] Add missing formattors for enum classes
This is a cherry-pick from trinity (MB-51719) Upgrading to fmtlib 8.1.1 removed support for implicitly converting strongly-typed enums (enum class) to int when printing via fmtlib - see fmtlib/fmt#1841 This is considered a bug by fmtlib, as strongly-typed enums should be treated as such - to print them either provide a formatter, or cast to their underlying type. This highlighted that we had missed a number of operator<< overloads for custom enum classes - and one instance where our operator<< was not used as we were missing an include of <fmt/ostream.h> Change-Id: If0f4e19f3eff4ebf4b4e3ccec1f0815c794a709b Reviewed-on: https://review.couchbase.org/c/kv_engine/+/234744 Well-Formed: Restriction Checker Tested-by: Trond Norbye <[email protected]> Reviewed-by: Jim Walker <[email protected]>
1 parent 8431600 commit f6faa7e

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

engines/ep/src/dcp/backfill_disk.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "kv_bucket.h"
1818
#include "kvstore/kvstore.h"
1919
#include "vbucket.h"
20+
#include <fmt/ostream.h>
2021

2122
CacheCallback::CacheCallback(KVBucket& bucket, std::shared_ptr<ActiveStream> s)
2223
: bucket(bucket), streamPtr(s) {

engines/ep/src/kvstore/kvstore.cc

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,32 +522,32 @@ void KVStore::delSystemEvent(TransactionContext& txnCtx,
522522
del(txnCtx, item);
523523
}
524524

525-
std::string to_string(FlushStateDeletion state) {
525+
std::ostream& operator<<(std::ostream& os, const FlushStateDeletion& state) {
526526
switch (state) {
527527
case FlushStateDeletion::Delete:
528-
return "FlushStateDeletion::Delete";
528+
return os << "FlushStateDeletion::Delete";
529529
case FlushStateDeletion::LogicallyDocNotFound:
530-
return "FlushStateDeletion::LogicallyDocNotFound";
530+
return os << "FlushStateDeletion::LogicallyDocNotFound";
531531
case FlushStateDeletion::DocNotFound:
532-
return "FlushStateDeletion::DocNotFound";
532+
return os << "FlushStateDeletion::DocNotFound";
533533
case FlushStateDeletion::Failed:
534-
return "FlushStateDeletion::Failed";
534+
return os << "FlushStateDeletion::Failed";
535535
}
536-
folly::assume_unreachable();
536+
return os << "INVALID FlushStateDeletion value:" << static_cast<int>(state);
537537
}
538538

539-
std::string to_string(FlushStateMutation state) {
539+
std::ostream& operator<<(std::ostream& os, const FlushStateMutation& state) {
540540
switch (state) {
541541
case FlushStateMutation::Failed:
542-
return "FlushStateMutation::Failed";
542+
return os << "FlushStateMutation::Failed";
543543
case FlushStateMutation::Insert:
544-
return "FlushStateMutation::Insert";
544+
return os << "FlushStateMutation::Insert";
545545
case FlushStateMutation::LogicalInsert:
546-
return "FlushStateMutation::LogicalInsert";
546+
return os << "FlushStateMutation::LogicalInsert";
547547
case FlushStateMutation::Update:
548-
return "FlushStateMutation::Update";
548+
return os << "FlushStateMutation::Update";
549549
}
550-
folly::assume_unreachable();
550+
return os << "INVALID FlushStateMutation value:" << static_cast<int>(state);
551551
}
552552

553553
IORequest::IORequest(queued_item itm)
@@ -751,7 +751,7 @@ bool KVStore::checkAndFixKVStoreCreatedItem(Item& item) {
751751
// datatype XATTR, we should have its value to be able to verify it
752752
// is correct, or otherwise sanitise it.
753753
Expects(item.getValue());
754-
}
754+
}
755755
#endif
756756
if (item.isDeleted() &&
757757
item.getValue() &&
@@ -766,6 +766,32 @@ bool KVStore::checkAndFixKVStoreCreatedItem(Item& item) {
766766
cb::UserDataView(ss.str()).getSanitizedValue());
767767
item.setDataType(PROTOCOL_BINARY_RAW_BYTES);
768768
return true;
769-
}
769+
}
770770
return false;
771771
}
772+
773+
std::ostream& operator<<(std::ostream& os, const CompactDBStatus& status) {
774+
switch (status) {
775+
case CompactDBStatus::Success:
776+
return os << "CompactDBStatus::Success";
777+
case CompactDBStatus::Aborted:
778+
return os << "CompactDBStatus::Aborted";
779+
case CompactDBStatus::Failed:
780+
return os << "CompactDBStatus::Failed";
781+
}
782+
return os << "INVALID CompactDBStatus value:" << static_cast<int>(status);
783+
}
784+
785+
std::ostream& operator<<(std::ostream& os,
786+
const KVStoreIface::GetCollectionStatsStatus& status) {
787+
switch (status) {
788+
case KVStoreIface::GetCollectionStatsStatus::Success:
789+
return os << "GetCollectionStatsStatus::Success";
790+
case KVStoreIface::GetCollectionStatsStatus::NotFound:
791+
return os << "GetCollectionStatsStatus::NotFound";
792+
case KVStoreIface::GetCollectionStatsStatus::Failed:
793+
return os << "GetCollectionStatsStatus::Failed";
794+
}
795+
return os << "INVALID GetCollectionStatsStatus value:"
796+
<< static_cast<int>(status);
797+
}

engines/ep/src/kvstore/kvstore.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,6 @@ class KVStore : public KVStoreIface {
10211021
TestingHook<> saveDocsPostWriteDocsHook;
10221022
};
10231023

1024-
std::string to_string(FlushStateDeletion status);
1025-
std::string to_string(FlushStateMutation state);
1026-
10271024
/**
10281025
* The KVStoreFactory creates the correct KVStore instance(s) when
10291026
* needed by EPStore.

engines/ep/src/kvstore/kvstore_fwd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ enum class FlushStateDeletion {
3939
Failed
4040
};
4141

42+
std::ostream& operator<<(std::ostream& os, const FlushStateDeletion&);
43+
4244
/// Result of flushing a Mutation, passed to the PersistenceCallback.
4345
enum class FlushStateMutation {
4446
// An item was inserted (item did not exist before or was previously
@@ -56,3 +58,5 @@ enum class FlushStateMutation {
5658
// The persistence of the mutation failed
5759
Failed
5860
};
61+
62+
std::ostream& operator<<(std::ostream& os, const FlushStateMutation&);

engines/ep/src/kvstore/kvstore_iface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class KVStoreRevision {
110110
*/
111111
enum class CompactDBStatus { Success, Aborted, Failed };
112112

113+
std::ostream& operator<<(std::ostream&, const CompactDBStatus&);
114+
113115
/**
114116
* Functional interface of a KVStore. Each KVStore implementation must implement
115117
* each of these functions.
@@ -786,3 +788,6 @@ class KVStoreIface {
786788
};
787789

788790
std::string to_string(KVStoreIface::ReadVBStateStatus status);
791+
792+
std::ostream& operator<<(std::ostream&,
793+
const KVStoreIface::GetCollectionStatsStatus&);

engines/ep/src/kvstore/magma-kvstore/magma-kvstore.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ void MagmaKVStore::commitCallback(MagmaKVStoreTransactionContext& txnCtx,
854854
txnCtx.vbid,
855855
cb::UserData(req.getKey().to_string()),
856856
errCode,
857-
to_string(state));
857+
state);
858858
}
859859

860860
txnCtx.deleteCallback(req.getItem(), state);
@@ -888,7 +888,7 @@ void MagmaKVStore::commitCallback(MagmaKVStoreTransactionContext& txnCtx,
888888
txnCtx.vbid,
889889
cb::UserData(req.getKey().to_string()),
890890
errCode,
891-
to_string(state));
891+
state);
892892
}
893893

894894
txnCtx.setCallback(req.getItem(), state);

0 commit comments

Comments
 (0)