forked from membase/ep-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbgfetcher.hh
More file actions
76 lines (64 loc) · 1.64 KB
/
bgfetcher.hh
File metadata and controls
76 lines (64 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#ifndef BGFETCHER_HH
#define BGFETCHER 1
#include <map>
#include <vector>
#include <list>
#include "common.hh"
#include "dispatcher.hh"
// Forward declaration.
class EventuallyPersistentStore;
class BgFetcher;
/**
* A DispatcherCallback for BgFetcher
*/
class BgFetcherCallback : public DispatcherCallback {
public:
BgFetcherCallback(BgFetcher *b) : bgfetcher(b) { }
bool callback(Dispatcher &d, TaskId t);
std::string description() {
return std::string("Batching background fetch.");
}
private:
BgFetcher *bgfetcher;
};
/**
* Dispatcher job responsible for batching data reads and push to
* underlying storage
*/
class BgFetcher {
public:
static const double sleepInterval;
/**
* Construct a BgFetcher task.
*
* @param s the store
* @param d the dispatcher
*/
BgFetcher(EventuallyPersistentStore *s, Dispatcher *d, EPStats &st) :
store(s), dispatcher(d), stats(st) {}
void start(void);
void stop(void);
bool run(TaskId tid);
bool pendingJob(void) {
return numRemainingItems > 0;
}
void notifyBGEvent(void) {
if (++numRemainingItems == 1) {
LockHolder lh(taskMutex);
assert(task.get());
dispatcher->wake(task, &task);
}
}
private:
void doFetch(uint16_t vbId);
void clearItems(void);
EventuallyPersistentStore *store;
Dispatcher *dispatcher;
vb_bgfetch_queue_t items2fetch;
TaskId task;
Mutex taskMutex;
EPStats &stats;
Atomic<size_t> numRemainingItems;
};
#endif /* BGFETCHER_HH */