forked from membase/ep-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vbucket.cc
54 lines (44 loc) · 1.83 KB
/
vbucket.cc
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
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include "config.h"
#include <functional>
#include "vbucket.hh"
const vbucket_state_t VBucket::ACTIVE = static_cast<vbucket_state_t>(htonl(active));
const vbucket_state_t VBucket::REPLICA = static_cast<vbucket_state_t>(htonl(replica));
const vbucket_state_t VBucket::PENDING = static_cast<vbucket_state_t>(htonl(pending));
const vbucket_state_t VBucket::DEAD = static_cast<vbucket_state_t>(htonl(dead));
void VBucket::fireAllOps(SERVER_CORE_API *core, ENGINE_ERROR_CODE code) {
if (pendingOpsStart > 0) {
hrtime_t now = gethrtime();
if (now > pendingOpsStart) {
hrtime_t d = (now - pendingOpsStart) / 1000;
stats.pendingOpsMaxDuration.setIfBigger(d);
}
}
pendingOpsStart = 0;
stats.pendingOps.decr(pendingOps.size());
stats.pendingOpsMax.setIfBigger(pendingOps.size());
std::for_each(pendingOps.begin(), pendingOps.end(),
std::bind2nd(std::ptr_fun(core->notify_io_complete), code));
pendingOps.clear();
getLogger()->log(EXTENSION_LOG_INFO, NULL,
"Fired pendings ops for vbucket %d in state %s\n",
id, VBucket::toString(state));
}
void VBucket::fireAllOps(SERVER_CORE_API *core) {
LockHolder lh(pendingOpLock);
if (state == active) {
fireAllOps(core, ENGINE_SUCCESS);
} else if (state == pending) {
// Nothing
} else {
fireAllOps(core, ENGINE_NOT_MY_VBUCKET);
}
}
void VBucket::setState(vbucket_state_t to, SERVER_CORE_API *core) {
assert(core);
vbucket_state_t oldstate(state);
getLogger()->log(EXTENSION_LOG_DEBUG, NULL,
"transitioning vbucket %d from %s to %s\n",
id, VBucket::toString(oldstate), VBucket::toString(to));
state = to;
}