Skip to content

Commit 9b961fd

Browse files
BenHuddlestondaverigby
authored andcommitted
MB-47387: Make ep_warmup_thread indicate all threads finished
Have ep_warmup_thread indicate that all warmup threads have actually finished (which in turn means that DcpConsumers can be created). ns_server can then create a DcpConsumer and expect that it should not return temporary_failure. Change-Id: Icd6c587001eab2d7821e09673a5652675f9817d0 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/163886 Tested-by: Build Bot <[email protected]> Reviewed-by: James H <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent d5c10c2 commit 9b961fd

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

engines/ep/src/warmup.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ void Warmup::addStats(const AddStatFn& add_stat, const CookieIface* c) const {
19021902
addStat(nullptr, "enabled", add_stat, c);
19031903
const char* stateName = state.toString();
19041904
addStat("state", stateName, add_stat, c);
1905-
if (finishedLoading.load()) {
1905+
if (isComplete()) {
19061906
addStat("thread", "complete", add_stat, c);
19071907
} else {
19081908
addStat("thread", "running", add_stat, c);

engines/ep/src/warmup.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ class WarmupState {
214214
*
215215
* Note that once warmup is complete (Warmup::isFinishedLoading() returns true)
216216
* the warmup will conclude the phase and short-cut to Done. When
217-
* Warmup::isFinishedLoading() returns true: 1) all CRUD operations are fully
218-
* processed. 2) DCP consumers can be created.
217+
* Warmup::isFinishedLoading() returns true all CRUD operations are fully
218+
* processed. When Warmup::isComplete() returns true DCP consumers can be
219+
* created. isComplete() will return true later than isFinishedLoading() as we
220+
* need to marshall all of the warmup threads before allowing DCP Consumers to
221+
* prevent race conditions with rollback.
219222
*/
220223
class Warmup {
221224
public:

engines/ep/tests/module_tests/evp_store_warmup_test.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,25 @@ TEST_F(WarmupTest, ConsumerDuringWarmup) {
28112811
runNextTask(readerQueue);
28122812
EXPECT_EQ(warmupPtr->getWarmupState(), WarmupState::State::LoadingData);
28132813

2814+
// ns_server gets stats to determine when to set up DcpConsumers. The stat
2815+
// ep_warmup_thread encapsulates the state of warmup threads and returns a
2816+
// value of either "running" or "complete". Check here that it is "running"
2817+
// as we will temp_fail a DcpConsumer creation.
2818+
{
2819+
bool threadStatAdded;
2820+
auto dummyAddStats = [&threadStatAdded](std::string_view key,
2821+
std::string_view value,
2822+
const void*) {
2823+
if (key == "ep_warmup_thread") {
2824+
EXPECT_EQ("running", value);
2825+
threadStatAdded = true;
2826+
}
2827+
};
2828+
EXPECT_EQ(cb::engine_errc::success,
2829+
engine->get_stats(*cookie, "warmup", {}, dummyAddStats));
2830+
EXPECT_TRUE(threadStatAdded);
2831+
}
2832+
28142833
// Still fails, not finished warmup
28152834
EXPECT_EQ(cb::engine_errc::temporary_failure,
28162835
engine->dcpOpen(cookie,
@@ -2828,6 +2847,23 @@ TEST_F(WarmupTest, ConsumerDuringWarmup) {
28282847
// finish warmup
28292848
runNextTask(readerQueue);
28302849

2850+
// Now that all warmup threads have complete, ep_warmup_thread should return
2851+
// "complete" indicating to ns_server that they can now create a DcpConsumer
2852+
{
2853+
bool threadStatAdded;
2854+
auto dummyAddStats = [&threadStatAdded](std::string_view key,
2855+
std::string_view value,
2856+
const void*) {
2857+
if (key == "ep_warmup_thread") {
2858+
EXPECT_EQ("complete", value);
2859+
threadStatAdded = true;
2860+
}
2861+
};
2862+
EXPECT_EQ(cb::engine_errc::success,
2863+
engine->get_stats(*cookie, "warmup", {}, dummyAddStats));
2864+
EXPECT_TRUE(threadStatAdded);
2865+
}
2866+
28312867
// Opening the connection should now work
28322868
EXPECT_EQ(cb::engine_errc::success,
28332869
engine->dcpOpen(cookie,

0 commit comments

Comments
 (0)