Skip to content

Commit e04af9d

Browse files
committed
KVStore: move impl-only types to kvstore_priv.h
kvstore.h currently contains two classes of code - (1) the interface for using KVStore subclasses, and (2) types and code used by subclasses and to implement KVStore. This results in unnecessary code being pulled in to files which just want to /use/ KVStore, and don't need to implement it. As such, create a new private header - kvstore_priv.h - to contain the implementation details and move implementaiton code to this file. Change-Id: Icfd721ffbb39005d7392f27806882d4b4ab97bc1 Reviewed-on: http://review.couchbase.org/82683 Reviewed-by: Manu Dhundi <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent bafd9a0 commit e04af9d

File tree

10 files changed

+244
-195
lines changed

10 files changed

+244
-195
lines changed

engines/ep/src/atomicqueue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class AtomicQueue {
7070
#include <queue>
7171

7272
#include <atomic>
73+
74+
#include "atomic.h"
7375
#include "threadlocal.h"
7476
#include "utility.h"
7577

engines/ep/src/bgfetcher.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <string>
2626

2727
#include "item.h"
28-
#include "kvstore.h"
2928
#include "stats.h"
3029
#include "vbucket.h"
3130

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "common.h"
2121
#include "couch-kvstore/couch-fs-stats.h"
22+
#include "kvstore.h"
23+
2224
#include <platform/histogram.h>
2325

2426
std::unique_ptr<FileOpsInterface> getCouchstoreStatsOps(

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
#ifndef SRC_COUCH_KVSTORE_COUCH_FS_STATS_H_
19-
#define SRC_COUCH_KVSTORE_COUCH_FS_STATS_H_ 1
18+
#pragma once
2019

2120
#include "config.h"
2221

@@ -25,7 +24,8 @@
2524

2625
#include <libcouchstore/couch_db.h>
2726
#include <platform/histogram.h>
28-
#include "kvstore.h"
27+
28+
struct FileStats;
2929

3030
/**
3131
* Returns an instance of StatsOps from a FileStats reference and
@@ -91,5 +91,3 @@ class StatsOps : public FileOpsInterface {
9191
size_t write_count_since_open;
9292
};
9393
};
94-
95-
#endif // SRC_COUCH_KVSTORE_COUCH_FS_STATS_H_

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@
1919
#define SRC_COUCH_KVSTORE_COUCH_KVSTORE_H_ 1
2020

2121
#include "config.h"
22+
23+
#include "atomicqueue.h"
24+
#include "configuration.h"
25+
#include "couch-kvstore/couch-fs-stats.h"
26+
#include "couch-kvstore/couch-kvstore-metadata.h"
27+
#include "item.h"
28+
#include "kvstore.h"
29+
#include "kvstore_priv.h"
2230
#include "libcouchstore/couch_db.h"
31+
#include "logger.h"
32+
33+
#include <platform/histogram.h>
34+
#include <platform/strerror.h>
2335
#include <relaxed_atomic.h>
2436

2537
#include <map>
2638
#include <memory>
2739
#include <string>
2840
#include <vector>
2941

30-
#include "configuration.h"
31-
#include "couch-kvstore/couch-fs-stats.h"
32-
#include "couch-kvstore/couch-kvstore-metadata.h"
33-
#include <platform/histogram.h>
34-
#include <platform/strerror.h>
35-
#include "logger.h"
36-
#include "item.h"
37-
#include "kvstore.h"
38-
#include "atomicqueue.h"
3942

4043
#define COUCHSTORE_NO_OPTIONS 0
4144

engines/ep/src/kvstore.cc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@
3737
#include <sys/types.h>
3838
#include <sys/stat.h>
3939

40+
ScanContext::ScanContext(std::shared_ptr<Callback<GetValue>> cb,
41+
std::shared_ptr<Callback<CacheLookup>> cl,
42+
uint16_t vb,
43+
size_t id,
44+
uint64_t start,
45+
uint64_t end,
46+
DocumentFilter _docFilter,
47+
ValueFilter _valFilter,
48+
uint64_t _documentCount,
49+
const KVStoreConfig& _config)
50+
: callback(cb),
51+
lookup(cl),
52+
lastReadSeqno(0),
53+
startSeqno(start),
54+
maxSeqno(end),
55+
scanId(id),
56+
vbid(vb),
57+
docFilter(_docFilter),
58+
valFilter(_valFilter),
59+
documentCount(_documentCount),
60+
logger(&global_logger),
61+
config(_config) {
62+
}
63+
64+
void FileStats::reset() {
65+
readTimeHisto.reset();
66+
readSeekHisto.reset();
67+
readSizeHisto.reset();
68+
writeTimeHisto.reset();
69+
writeSizeHisto.reset();
70+
syncTimeHisto.reset();
71+
readCountHisto.reset();
72+
writeCountHisto.reset();
73+
totalBytesRead = 0;
74+
totalBytesWritten = 0;
75+
}
76+
4077
KVStoreRWRO KVStoreFactory::create(KVStoreConfig& config) {
4178
std::string backend = config.getBackend();
4279
if (backend == "couchdb") {
@@ -296,6 +333,38 @@ void KVStore::optimizeWrites(std::vector<queued_item>& items) {
296333
std::sort(items.begin(), items.end(), cq);
297334
}
298335

336+
uint64_t KVStore::getLastPersistedSeqno(uint16_t vbid) {
337+
vbucket_state* state = cachedVBStates[vbid];
338+
if (state) {
339+
return state->highSeqno;
340+
}
341+
return 0;
342+
}
343+
344+
vbucket_state::vbucket_state(vbucket_state_t _state,
345+
uint64_t _chkid,
346+
uint64_t _maxDelSeqNum,
347+
int64_t _highSeqno,
348+
uint64_t _purgeSeqno,
349+
uint64_t _lastSnapStart,
350+
uint64_t _lastSnapEnd,
351+
uint64_t _maxCas,
352+
int64_t _hlcCasEpochSeqno,
353+
bool _mightContainXattrs,
354+
std::string _failovers)
355+
: state(_state),
356+
checkpointId(_chkid),
357+
maxDeletedSeqno(_maxDelSeqNum),
358+
highSeqno(_highSeqno),
359+
purgeSeqno(_purgeSeqno),
360+
lastSnapStart(_lastSnapStart),
361+
lastSnapEnd(_lastSnapEnd),
362+
maxCas(_maxCas),
363+
hlcCasEpochSeqno(_hlcCasEpochSeqno),
364+
mightContainXattrs(_mightContainXattrs),
365+
failovers(std::move(_failovers)) {
366+
}
367+
299368
std::string vbucket_state::toJSON() const {
300369
std::stringstream jsonState;
301370
jsonState << "{\"state\": \"" << VBucket::toString(state) << "\""
@@ -310,6 +379,31 @@ std::string vbucket_state::toJSON() const {
310379
return jsonState.str();
311380
}
312381

382+
bool vbucket_state::needsToBePersisted(const vbucket_state& vbstate) {
383+
/**
384+
* The vbucket state information is to be persisted
385+
* only if a change is detected in the state or the
386+
* failovers fields.
387+
*/
388+
if (state != vbstate.state || failovers.compare(vbstate.failovers) != 0) {
389+
return true;
390+
}
391+
return false;
392+
}
393+
394+
void vbucket_state::reset() {
395+
checkpointId = 0;
396+
maxDeletedSeqno = 0;
397+
highSeqno = 0;
398+
purgeSeqno = 0;
399+
lastSnapStart = 0;
400+
lastSnapEnd = 0;
401+
maxCas = 0;
402+
hlcCasEpochSeqno = HlcCasSeqnoUninitialised;
403+
mightContainXattrs = false;
404+
failovers.clear();
405+
}
406+
313407
IORequest::IORequest(uint16_t vbId, MutationRequestCallback &cb , bool del,
314408
const DocKey itmKey)
315409
: vbucketId(vbId), deleteItem(del), key(itmKey) {

0 commit comments

Comments
 (0)