if (vb->getState() != vbucket_state_active) {
return wantDeleted ? v : NULL;
}
- ReaderLockHolder(vb->getStateLock());
+
// queueDirty only allowed on active VB
if (queueExpired && vb->getState() == vbucket_state_active) {
incExpirationStat(vb, false);
// Obtain read-lock on VB state to ensure VB state changes are interlocked
// with this set
- ReaderLockHolder(vb->getStateLock());
+ ReaderLockHolder rlh(vb->getStateLock());
if (vb->getState() == vbucket_state_dead) {
++stats.numNotMyVBuckets;
return ENGINE_NOT_MY_VBUCKET;
// Obtain read-lock on VB state to ensure VB state changes are interlocked
// with this add
- ReaderLockHolder(vb->getStateLock());
+ ReaderLockHolder rlh(vb->getStateLock());
if (vb->getState() == vbucket_state_dead ||
vb->getState() == vbucket_state_replica) {
++stats.numNotMyVBuckets;
// Obtain read-lock on VB state to ensure VB state changes are interlocked
// with this replace
- ReaderLockHolder(vb->getStateLock());
+ ReaderLockHolder rlh(vb->getStateLock());
if (vb->getState() == vbucket_state_dead ||
vb->getState() == vbucket_state_replica) {
++stats.numNotMyVBuckets;
// Obtain read-lock on VB state to ensure VB state changes are interlocked
// with this add-tapbackfill
- ReaderLockHolder(vb->getStateLock());
+ ReaderLockHolder rlh(vb->getStateLock());
if (vb->getState() == vbucket_state_dead ||
vb->getState() == vbucket_state_active) {
++stats.numNotMyVBuckets;
RCPtr<VBucket> vb = getVBucket(vbucket);
if (vb) {
+ ReaderLockHolder rlh(vb->getStateLock());
int bucket_num(0);
LockHolder hlh = vb->ht.getLockedBucket(key, &bucket_num);
StoredValue *v = fetchValidValue(vb, key, bucket_num, true);
if (gcb.val.getStatus() == ENGINE_SUCCESS) {
v->unlocked_restoreValue(gcb.val.getValue(), vb->ht);
cb_assert(v->isResident());
- ReaderLockHolder(vb->getStateLock());
if (vb->getState() == vbucket_state_active &&
v->getExptime() != gcb.val.getValue()->getExptime() &&
v->getCas() == gcb.val.getValue()->getCas()) {
ENGINE_ERROR_CODE status = bgitem->value.getStatus();
Item *fetchedValue = bgitem->value.getValue();
const std::string &key = (*itemItr).first;
-
- int bucket = 0;
- LockHolder blh = vb->ht.getLockedBucket(key, &bucket);
- StoredValue *v = fetchValidValue(vb, key, bucket, true);
- if (bgitem->metaDataOnly) {
- if (v && v->unlocked_restoreMeta(fetchedValue, status, vb->ht)) {
- status = ENGINE_SUCCESS;
- }
- } else {
- bool restore = false;
- if (v && v->isResident()) {
- status = ENGINE_SUCCESS;
+ { // locking scope
+ ReaderLockHolder rlh(vb->getStateLock());
+
+ int bucket = 0;
+ LockHolder blh = vb->ht.getLockedBucket(key, &bucket);
+ StoredValue *v = fetchValidValue(vb, key, bucket, true);
+ if (bgitem->metaDataOnly) {
+ if (v && v->unlocked_restoreMeta(fetchedValue, status, vb->ht)) {
+ status = ENGINE_SUCCESS;
+ }
} else {
- switch (eviction_policy) {
- case VALUE_ONLY:
- if (v && !v->isResident() && !v->isDeleted()) {
- restore = true;
- }
- break;
- case FULL_EVICTION:
- if (v) {
- if (v->isTempInitialItem() ||
- (!v->isResident() && !v->isDeleted())) {
+ bool restore = false;
+ if (v && v->isResident()) {
+ status = ENGINE_SUCCESS;
+ } else {
+ switch (eviction_policy) {
+ case VALUE_ONLY:
+ if (v && !v->isResident() && !v->isDeleted()) {
restore = true;
}
- }
- break;
- default:
- throw std::logic_error("Unknown eviction policy");
+ break;
+ case FULL_EVICTION:
+ if (v) {
+ if (v->isTempInitialItem() ||
+ (!v->isResident() && !v->isDeleted())) {
+ restore = true;
+ }
+ }
+ break;
+ default:
+ throw std::logic_error("Unknown eviction policy");
+ }
}
- }
- if (restore) {
- if (status == ENGINE_SUCCESS) {
- v->unlocked_restoreValue(fetchedValue, vb->ht);
- cb_assert(v->isResident());
- ReaderLockHolder(vb->getStateLock());
- if (vb->getState() == vbucket_state_active &&
- v->getExptime() != fetchedValue->getExptime() &&
- v->getCas() == fetchedValue->getCas()) {
- // MB-9306: It is possible that by the time
- // bgfetcher returns, the item may have been
- // updated and queued
- // Hence test the CAS value to be the same first.
- // exptime mutated, schedule it into new checkpoint
- queueDirty(vb, v, &blh);
- }
- } else if (status == ENGINE_KEY_ENOENT) {
- v->setStoredValueState(StoredValue::state_non_existent_key);
- if (eviction_policy == FULL_EVICTION) {
- // For the full eviction, we should notify
- // ENGINE_SUCCESS to the memcached worker thread,
- // so that the worker thread can visit the
- // ep-engine and figure out the correct error
- // code.
- status = ENGINE_SUCCESS;
+ if (restore) {
+ if (status == ENGINE_SUCCESS) {
+ v->unlocked_restoreValue(fetchedValue, vb->ht);
+ cb_assert(v->isResident());
+ if (vb->getState() == vbucket_state_active &&
+ v->getExptime() != fetchedValue->getExptime() &&
+ v->getCas() == fetchedValue->getCas()) {
+ // MB-9306: It is possible that by the time
+ // bgfetcher returns, the item may have been
+ // updated and queued
+ // Hence test the CAS value to be the same first.
+ // exptime mutated, schedule it into new checkpoint
+ queueDirty(vb, v, &blh);
+ }
+ } else if (status == ENGINE_KEY_ENOENT) {
+ v->setStoredValueState(StoredValue::state_non_existent_key);
+ if (eviction_policy == FULL_EVICTION) {
+ // For the full eviction, we should notify
+ // ENGINE_SUCCESS to the memcached worker thread,
+ // so that the worker thread can visit the
+ // ep-engine and figure out the correct error
+ // code.
+ status = ENGINE_SUCCESS;
+ }
+ } else {
+ // underlying kvstore couldn't fetch requested data
+ // log returned error and notify TMPFAIL to client
+ LOG(EXTENSION_LOG_WARNING,
+ "Warning: failed background fetch for vb=%d "
+ "key=%s", vbId, key.c_str());
+ status = ENGINE_TMPFAIL;
}
- } else {
- // underlying kvstore couldn't fetch requested data
- // log returned error and notify TMPFAIL to client
- LOG(EXTENSION_LOG_WARNING,
- "Warning: failed background fetch for vb=%d "
- "key=%s", vbId, key.c_str());
- status = ENGINE_TMPFAIL;
}
}
- }
- blh.unlock();
+ } // locking scope ends
if (bgitem->metaDataOnly) {
++stats.bg_meta_fetched;
if (!vb) {
++stats.numNotMyVBuckets;
return GetValue(NULL, ENGINE_NOT_MY_VBUCKET);
- } else if (honorStates && vb->getState() == vbucket_state_dead) {
+ }
+
+ ReaderLockHolder rlh(vb->getStateLock());
+ if (honorStates && vb->getState() == vbucket_state_dead) {
++stats.numNotMyVBuckets;
return GetValue(NULL, ENGINE_NOT_MY_VBUCKET);
} else if (honorStates && vb->getState() == disallowedState) {
{
(void) cookie;
RCPtr<VBucket> vb = getVBucket(vbucket);
- if (!vb || vb->getState() == vbucket_state_dead ||
+ if (!vb) {
+ ++stats.numNotMyVBuckets;
+ return ENGINE_NOT_MY_VBUCKET;
+ }
+
+ ReaderLockHolder rlh(vb->getStateLock());
+ if (vb->getState() == vbucket_state_dead ||
vb->getState() == vbucket_state_replica) {
++stats.numNotMyVBuckets;
return ENGINE_NOT_MY_VBUCKET;
return ENGINE_NOT_MY_VBUCKET;
}
- ReaderLockHolder(vb->getStateLock());
+ ReaderLockHolder rlh(vb->getStateLock());
if (vb->getState() == vbucket_state_dead) {
++stats.numNotMyVBuckets;
return ENGINE_NOT_MY_VBUCKET;
if (!vb) {
++stats.numNotMyVBuckets;
return GetValue(NULL, ENGINE_NOT_MY_VBUCKET);
- } else if (vb->getState() == vbucket_state_dead) {
+ }
+
+ ReaderLockHolder rlh(vb->getStateLock());
+ if (vb->getState() == vbucket_state_dead) {
++stats.numNotMyVBuckets;
return GetValue(NULL, ENGINE_NOT_MY_VBUCKET);
} else if (vb->getState() == vbucket_state_replica) {
ENGINE_SUCCESS, v->getBySeqno());
if (exptime_mutated) {
- ReaderLockHolder(vb->getStateLock());
if (vb->getState() == vbucket_state_active) {
// persist the item in the underlying storage for
// mutated exptime but only if VB is active.