@@ -534,7 +534,7 @@ StoredValue *EventuallyPersistentStore::fetchValidValue(RCPtr<VBucket> &vb,
534
534
if (vb->getState () != vbucket_state_active) {
535
535
return wantDeleted ? v : NULL ;
536
536
}
537
- ReaderLockHolder (vb-> getStateLock ());
537
+
538
538
// queueDirty only allowed on active VB
539
539
if (queueExpired && vb->getState () == vbucket_state_active) {
540
540
incExpirationStat (vb, false );
@@ -632,7 +632,7 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::set(const Item &itm,
632
632
633
633
// Obtain read-lock on VB state to ensure VB state changes are interlocked
634
634
// with this set
635
- ReaderLockHolder (vb->getStateLock ());
635
+ ReaderLockHolder rlh (vb->getStateLock ());
636
636
if (vb->getState () == vbucket_state_dead) {
637
637
++stats.numNotMyVBuckets ;
638
638
return ENGINE_NOT_MY_VBUCKET;
@@ -711,7 +711,7 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::add(const Item &itm,
711
711
712
712
// Obtain read-lock on VB state to ensure VB state changes are interlocked
713
713
// with this add
714
- ReaderLockHolder (vb->getStateLock ());
714
+ ReaderLockHolder rlh (vb->getStateLock ());
715
715
if (vb->getState () == vbucket_state_dead ||
716
716
vb->getState () == vbucket_state_replica) {
717
717
++stats.numNotMyVBuckets ;
@@ -764,7 +764,7 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::replace(const Item &itm,
764
764
765
765
// Obtain read-lock on VB state to ensure VB state changes are interlocked
766
766
// with this replace
767
- ReaderLockHolder (vb->getStateLock ());
767
+ ReaderLockHolder rlh (vb->getStateLock ());
768
768
if (vb->getState () == vbucket_state_dead ||
769
769
vb->getState () == vbucket_state_replica) {
770
770
++stats.numNotMyVBuckets ;
@@ -848,7 +848,7 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::addTAPBackfillItem(const Item &itm,
848
848
849
849
// Obtain read-lock on VB state to ensure VB state changes are interlocked
850
850
// with this add-tapbackfill
851
- ReaderLockHolder (vb->getStateLock ());
851
+ ReaderLockHolder rlh (vb->getStateLock ());
852
852
if (vb->getState () == vbucket_state_dead ||
853
853
vb->getState () == vbucket_state_active) {
854
854
++stats.numNotMyVBuckets ;
@@ -1437,6 +1437,7 @@ void EventuallyPersistentStore::completeBGFetch(const std::string &key,
1437
1437
1438
1438
RCPtr<VBucket> vb = getVBucket (vbucket);
1439
1439
if (vb) {
1440
+ ReaderLockHolder rlh (vb->getStateLock ());
1440
1441
int bucket_num (0 );
1441
1442
LockHolder hlh = vb->ht .getLockedBucket (key, &bucket_num);
1442
1443
StoredValue *v = fetchValidValue (vb, key, bucket_num, true );
@@ -1473,7 +1474,6 @@ void EventuallyPersistentStore::completeBGFetch(const std::string &key,
1473
1474
if (gcb.val .getStatus () == ENGINE_SUCCESS) {
1474
1475
v->unlocked_restoreValue (gcb.val .getValue (), vb->ht );
1475
1476
cb_assert (v->isResident ());
1476
- ReaderLockHolder (vb->getStateLock ());
1477
1477
if (vb->getState () == vbucket_state_active &&
1478
1478
v->getExptime () != gcb.val .getValue ()->getExptime () &&
1479
1479
v->getCas () == gcb.val .getValue ()->getCas ()) {
@@ -1543,74 +1543,75 @@ void EventuallyPersistentStore::completeBGFetchMulti(uint16_t vbId,
1543
1543
ENGINE_ERROR_CODE status = bgitem->value .getStatus ();
1544
1544
Item *fetchedValue = bgitem->value .getValue ();
1545
1545
const std::string &key = (*itemItr).first ;
1546
-
1547
- int bucket = 0 ;
1548
- LockHolder blh = vb->ht .getLockedBucket (key, &bucket);
1549
- StoredValue *v = fetchValidValue (vb, key, bucket, true );
1550
- if (bgitem->metaDataOnly ) {
1551
- if (v && v->unlocked_restoreMeta (fetchedValue, status, vb->ht )) {
1552
- status = ENGINE_SUCCESS;
1553
- }
1554
- } else {
1555
- bool restore = false ;
1556
- if (v && v->isResident ()) {
1557
- status = ENGINE_SUCCESS;
1546
+ { // locking scope
1547
+ ReaderLockHolder rlh (vb->getStateLock ());
1548
+
1549
+ int bucket = 0 ;
1550
+ LockHolder blh = vb->ht .getLockedBucket (key, &bucket);
1551
+ StoredValue *v = fetchValidValue (vb, key, bucket, true );
1552
+ if (bgitem->metaDataOnly ) {
1553
+ if (v && v->unlocked_restoreMeta (fetchedValue, status, vb->ht )) {
1554
+ status = ENGINE_SUCCESS;
1555
+ }
1558
1556
} else {
1559
- switch (eviction_policy) {
1560
- case VALUE_ONLY:
1561
- if (v && !v->isResident () && !v->isDeleted ()) {
1562
- restore = true ;
1563
- }
1564
- break ;
1565
- case FULL_EVICTION:
1566
- if (v) {
1567
- if (v->isTempInitialItem () ||
1568
- (!v->isResident () && !v->isDeleted ())) {
1557
+ bool restore = false ;
1558
+ if (v && v->isResident ()) {
1559
+ status = ENGINE_SUCCESS;
1560
+ } else {
1561
+ switch (eviction_policy) {
1562
+ case VALUE_ONLY:
1563
+ if (v && !v->isResident () && !v->isDeleted ()) {
1569
1564
restore = true ;
1570
1565
}
1571
- }
1572
- break ;
1573
- default :
1574
- throw std::logic_error (" Unknown eviction policy" );
1566
+ break ;
1567
+ case FULL_EVICTION:
1568
+ if (v) {
1569
+ if (v->isTempInitialItem () ||
1570
+ (!v->isResident () && !v->isDeleted ())) {
1571
+ restore = true ;
1572
+ }
1573
+ }
1574
+ break ;
1575
+ default :
1576
+ throw std::logic_error (" Unknown eviction policy" );
1577
+ }
1575
1578
}
1576
- }
1577
1579
1578
- if (restore) {
1579
- if (status == ENGINE_SUCCESS) {
1580
- v->unlocked_restoreValue (fetchedValue, vb->ht );
1581
- cb_assert (v->isResident ());
1582
- ReaderLockHolder (vb->getStateLock ());
1583
- if (vb->getState () == vbucket_state_active &&
1584
- v->getExptime () != fetchedValue->getExptime () &&
1585
- v->getCas () == fetchedValue->getCas ()) {
1586
- // MB-9306: It is possible that by the time
1587
- // bgfetcher returns, the item may have been
1588
- // updated and queued
1589
- // Hence test the CAS value to be the same first.
1590
- // exptime mutated, schedule it into new checkpoint
1591
- queueDirty (vb, v, &blh);
1592
- }
1593
- } else if (status == ENGINE_KEY_ENOENT) {
1594
- v->setStoredValueState (StoredValue::state_non_existent_key);
1595
- if (eviction_policy == FULL_EVICTION) {
1596
- // For the full eviction, we should notify
1597
- // ENGINE_SUCCESS to the memcached worker thread,
1598
- // so that the worker thread can visit the
1599
- // ep-engine and figure out the correct error
1600
- // code.
1601
- status = ENGINE_SUCCESS;
1580
+ if (restore) {
1581
+ if (status == ENGINE_SUCCESS) {
1582
+ v->unlocked_restoreValue (fetchedValue, vb->ht );
1583
+ cb_assert (v->isResident ());
1584
+ if (vb->getState () == vbucket_state_active &&
1585
+ v->getExptime () != fetchedValue->getExptime () &&
1586
+ v->getCas () == fetchedValue->getCas ()) {
1587
+ // MB-9306: It is possible that by the time
1588
+ // bgfetcher returns, the item may have been
1589
+ // updated and queued
1590
+ // Hence test the CAS value to be the same first.
1591
+ // exptime mutated, schedule it into new checkpoint
1592
+ queueDirty (vb, v, &blh);
1593
+ }
1594
+ } else if (status == ENGINE_KEY_ENOENT) {
1595
+ v->setStoredValueState (StoredValue::state_non_existent_key);
1596
+ if (eviction_policy == FULL_EVICTION) {
1597
+ // For the full eviction, we should notify
1598
+ // ENGINE_SUCCESS to the memcached worker thread,
1599
+ // so that the worker thread can visit the
1600
+ // ep-engine and figure out the correct error
1601
+ // code.
1602
+ status = ENGINE_SUCCESS;
1603
+ }
1604
+ } else {
1605
+ // underlying kvstore couldn't fetch requested data
1606
+ // log returned error and notify TMPFAIL to client
1607
+ LOG (EXTENSION_LOG_WARNING,
1608
+ " Warning: failed background fetch for vb=%d "
1609
+ " key=%s" , vbId, key.c_str ());
1610
+ status = ENGINE_TMPFAIL;
1602
1611
}
1603
- } else {
1604
- // underlying kvstore couldn't fetch requested data
1605
- // log returned error and notify TMPFAIL to client
1606
- LOG (EXTENSION_LOG_WARNING,
1607
- " Warning: failed background fetch for vb=%d "
1608
- " key=%s" , vbId, key.c_str ());
1609
- status = ENGINE_TMPFAIL;
1610
1612
}
1611
1613
}
1612
- }
1613
- blh.unlock ();
1614
+ } // locking scope ends
1614
1615
1615
1616
if (bgitem->metaDataOnly ) {
1616
1617
++stats.bg_meta_fetched ;
@@ -1680,7 +1681,10 @@ GetValue EventuallyPersistentStore::getInternal(const std::string &key,
1680
1681
if (!vb) {
1681
1682
++stats.numNotMyVBuckets ;
1682
1683
return GetValue (NULL , ENGINE_NOT_MY_VBUCKET);
1683
- } else if (honorStates && vb->getState () == vbucket_state_dead) {
1684
+ }
1685
+
1686
+ ReaderLockHolder rlh (vb->getStateLock ());
1687
+ if (honorStates && vb->getState () == vbucket_state_dead) {
1684
1688
++stats.numNotMyVBuckets ;
1685
1689
return GetValue (NULL , ENGINE_NOT_MY_VBUCKET);
1686
1690
} else if (honorStates && vb->getState () == disallowedState) {
@@ -1777,7 +1781,13 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::getMetaData(
1777
1781
{
1778
1782
(void ) cookie;
1779
1783
RCPtr<VBucket> vb = getVBucket (vbucket);
1780
- if (!vb || vb->getState () == vbucket_state_dead ||
1784
+ if (!vb) {
1785
+ ++stats.numNotMyVBuckets ;
1786
+ return ENGINE_NOT_MY_VBUCKET;
1787
+ }
1788
+
1789
+ ReaderLockHolder rlh (vb->getStateLock ());
1790
+ if (vb->getState () == vbucket_state_dead ||
1781
1791
vb->getState () == vbucket_state_replica) {
1782
1792
++stats.numNotMyVBuckets ;
1783
1793
return ENGINE_NOT_MY_VBUCKET;
@@ -1839,7 +1849,7 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::setWithMeta(const Item &itm,
1839
1849
return ENGINE_NOT_MY_VBUCKET;
1840
1850
}
1841
1851
1842
- ReaderLockHolder (vb->getStateLock ());
1852
+ ReaderLockHolder rlh (vb->getStateLock ());
1843
1853
if (vb->getState () == vbucket_state_dead) {
1844
1854
++stats.numNotMyVBuckets ;
1845
1855
return ENGINE_NOT_MY_VBUCKET;
@@ -1925,7 +1935,10 @@ GetValue EventuallyPersistentStore::getAndUpdateTtl(const std::string &key,
1925
1935
if (!vb) {
1926
1936
++stats.numNotMyVBuckets ;
1927
1937
return GetValue (NULL , ENGINE_NOT_MY_VBUCKET);
1928
- } else if (vb->getState () == vbucket_state_dead) {
1938
+ }
1939
+
1940
+ ReaderLockHolder rlh (vb->getStateLock ());
1941
+ if (vb->getState () == vbucket_state_dead) {
1929
1942
++stats.numNotMyVBuckets ;
1930
1943
return GetValue (NULL , ENGINE_NOT_MY_VBUCKET);
1931
1944
} else if (vb->getState () == vbucket_state_replica) {
@@ -1967,7 +1980,6 @@ GetValue EventuallyPersistentStore::getAndUpdateTtl(const std::string &key,
1967
1980
ENGINE_SUCCESS, v->getBySeqno ());
1968
1981
1969
1982
if (exptime_mutated) {
1970
- ReaderLockHolder (vb->getStateLock ());
1971
1983
if (vb->getState () == vbucket_state_active) {
1972
1984
// persist the item in the underlying storage for
1973
1985
// mutated exptime but only if VB is active.
0 commit comments