Skip to content

Commit 3a63f5e

Browse files
committed
MB-51413: Move ReadVBStateStatus to KVStoreIface
We'll use it in getPersistedVBucketState in a future patch to differentiate between NotFound and Success. Change-Id: I8432208e0ae12959ab9c8a55848f90a3b81d0d01 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/172254 Reviewed-by: James H <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 650443a commit 3a63f5e

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,6 @@ static std::string getDBFileName(const std::string& dbname,
198198
std::to_string(rev);
199199
}
200200

201-
std::string to_string(CouchKVStore::ReadVBStateStatus status) {
202-
switch (status) {
203-
case CouchKVStore::ReadVBStateStatus::Success:
204-
return "Success";
205-
case CouchKVStore::ReadVBStateStatus::NotFound:
206-
return "NotFound";
207-
case CouchKVStore::ReadVBStateStatus::JsonInvalid:
208-
return "JsonInvalid";
209-
case CouchKVStore::ReadVBStateStatus::CorruptSnapshot:
210-
return "CorruptSnapshot";
211-
case CouchKVStore::ReadVBStateStatus::CouchstoreError:
212-
return "CouchstoreError";
213-
}
214-
folly::assume_unreachable();
215-
}
216-
217201
/// @returns the document ID used to store cid
218202
std::string CouchKVStore::getCollectionStatsLocalDocId(CollectionID cid) {
219203
return fmt::format("|{:#x}|", uint32_t(cid));
@@ -3309,7 +3293,7 @@ CouchKVStore::ReadVBStateResult CouchKVStore::readVBState(Db* db,
33093293
" error:{}, {}",
33103294
couchstore_strerror(couchStoreStatus),
33113295
vbId);
3312-
return {ReadVBStateStatus::CouchstoreError, {}};
3296+
return {ReadVBStateStatus::Error, {}};
33133297
}
33143298

33153299
// Proceed to read/parse the vbstate

engines/ep/src/kvstore/couch-kvstore/couch-kvstore.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ class CouchKVStore : public KVStore
150150
using PendingRequestQueue = std::deque<CouchRequest>;
151151
using PendingLocalDocRequestQueue = std::deque<CouchLocalDocRequest>;
152152

153-
enum class ReadVBStateStatus : uint8_t {
154-
Success = 0,
155-
NotFound,
156-
JsonInvalid,
157-
CorruptSnapshot,
158-
CouchstoreError
159-
};
160-
161153
/**
162154
* Constructor - creates a read/write CouchKVStore
163155
*
@@ -827,16 +819,6 @@ class CouchKVStore : public KVStore
827819
concurrentCompactionPreLockHook = std::move(hook);
828820
}
829821

830-
/**
831-
* Result of the readVBState function
832-
*/
833-
struct ReadVBStateResult {
834-
ReadVBStateStatus status{ReadVBStateStatus::Success};
835-
836-
// Only valid if status == ReadVBStateStatus::Success
837-
vbucket_state state;
838-
};
839-
840822
/**
841823
* Read the vbucket_state from disk.
842824
*/
@@ -1065,5 +1047,3 @@ struct CouchKVStoreTransactionContext : public TransactionContext {
10651047
*/
10661048
CouchKVStore::PendingLocalDocRequestQueue pendingLocalReqsQ;
10671049
};
1068-
1069-
std::string to_string(CouchKVStore::ReadVBStateStatus status);

engines/ep/src/kvstore/kvstore.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,4 +688,20 @@ std::ostream& operator<<(std::ostream& os, ScanStatus status) {
688688
return os << "ScanStatus::Failed";
689689
}
690690
folly::assume_unreachable();
691+
}
692+
693+
std::string to_string(KVStoreIface::ReadVBStateStatus status) {
694+
switch (status) {
695+
case KVStoreIface::ReadVBStateStatus::Success:
696+
return "Success";
697+
case KVStoreIface::ReadVBStateStatus::NotFound:
698+
return "NotFound";
699+
case KVStoreIface::ReadVBStateStatus::JsonInvalid:
700+
return "JsonInvalid";
701+
case KVStoreIface::ReadVBStateStatus::CorruptSnapshot:
702+
return "CorruptSnapshot";
703+
case KVStoreIface::ReadVBStateStatus::Error:
704+
return "Error";
705+
}
706+
folly::assume_unreachable();
691707
}

engines/ep/src/kvstore/kvstore_iface.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "collections/kvstore.h"
1616
#include "ep_types.h"
1717
#include "persistence_callback.h"
18+
#include "vbucket_state.h"
1819

1920
#include <memcached/engine_common.h>
2021
#include <memcached/thread_pool_config.h>
@@ -37,7 +38,6 @@ struct CompactionConfig;
3738
struct CompactionContext;
3839
struct DBFileInfo;
3940
struct TransactionContext;
40-
struct vbucket_state;
4141

4242
namespace Collections::VB {
4343
struct PersistedStats;
@@ -332,6 +332,24 @@ class KVStoreIface {
332332
*/
333333
virtual vbucket_state* getCachedVBucketState(Vbid vbid) = 0;
334334

335+
enum class ReadVBStateStatus : uint8_t {
336+
Success = 0,
337+
NotFound,
338+
JsonInvalid,
339+
CorruptSnapshot,
340+
Error,
341+
};
342+
343+
/**
344+
* Result of the readVBState function
345+
*/
346+
struct ReadVBStateResult {
347+
ReadVBStateStatus status{ReadVBStateStatus::Success};
348+
349+
// Only valid if status == ReadVBStateStatus::Success
350+
vbucket_state state;
351+
};
352+
335353
/**
336354
* Return the vbucket_state stored on disk for the given vBucket. Does NOT
337355
* update the cachedVBState.
@@ -739,3 +757,5 @@ class KVStoreIface {
739757
*/
740758
virtual void prepareToCreateImpl(Vbid vbid) = 0;
741759
};
760+
761+
std::string to_string(KVStoreIface::ReadVBStateStatus status);

0 commit comments

Comments
 (0)