@@ -11326,6 +11326,109 @@ static enum test_result test_failover_log_dcp(ENGINE_HANDLE *h,
1132611326 return SUCCESS ;
1132711327}
1132811328
11329+ struct mb16357_ctx {
11330+ mb16357_ctx (ENGINE_HANDLE *_h, ENGINE_HANDLE_V1 *_h1, int _items) :
11331+ h (_h), h1(_h1), items(_items) { }
11332+
11333+ ENGINE_HANDLE *h;
11334+ ENGINE_HANDLE_V1 *h1;
11335+ int items;
11336+ };
11337+
11338+ extern " C" {
11339+ static void dcp_thread_func (void *args) {
11340+ struct mb16357_ctx *ctx = static_cast <mb16357_ctx *>(args);
11341+
11342+ const void *cookie = testHarness.create_cookie ();
11343+ uint32_t opaque = 0xFFFF0000 ;
11344+ uint32_t flags = 0 ;
11345+ std::string name = " unittest" ;
11346+
11347+ while (get_int_stat (ctx->h , ctx->h1 , " ep_pending_compactions" ) == 0 );
11348+
11349+ // Switch to replica
11350+ check (set_vbucket_state (ctx->h , ctx->h1 , 0 , vbucket_state_replica),
11351+ " Failed to set vbucket state." );
11352+
11353+ // Open consumer connection
11354+ checkeq (ctx->h1 ->dcp .open (ctx->h , cookie, opaque, 0 , flags,
11355+ (void *)name.c_str (), name.length ()),
11356+ ENGINE_SUCCESS ,
11357+ " Failed dcp Consumer open connection." );
11358+
11359+ add_stream_for_consumer (ctx->h , ctx->h1 , cookie, opaque++, 0 , 0 ,
11360+ PROTOCOL_BINARY_RESPONSE_SUCCESS );
11361+
11362+
11363+ uint32_t stream_opaque = get_int_stat (ctx->h , ctx->h1 ,
11364+ " eq_dcpq:unittest:stream_0_opaque" ,
11365+ " dcp" );
11366+
11367+
11368+ for (int i = 1 ; i <= ctx->items ; i++) {
11369+ std::stringstream ss;
11370+ ss << " kamakeey-" << i;
11371+
11372+ // send mutations in single mutation snapshots to race more with compaction
11373+ checkeq (ctx->h1 ->dcp .snapshot_marker (ctx->h , cookie,
11374+ stream_opaque, 0 /* vbid*/ ,
11375+ ctx->items , ctx->items + i, 2 ),
11376+ ENGINE_SUCCESS ,
11377+ " Failed to send snapshot marker" );
11378+ checkeq (ctx->h1 ->dcp .mutation (ctx->h , cookie, stream_opaque,
11379+ ss.str ().c_str (), ss.str ().length (),
11380+ " value" , 5 , i * 3 , 0 , 0 , 0 ,
11381+ i + ctx->items , i + ctx->items ,
11382+ 0 , 0 , " " , 0 , INITIAL_NRU_VALUE ),
11383+ ENGINE_SUCCESS ,
11384+ " Failed to send dcp mutation" );
11385+ }
11386+
11387+ testHarness.destroy_cookie (cookie);
11388+ }
11389+
11390+ static void compact_thread_func (void *args) {
11391+ struct mb16357_ctx *ctx = static_cast <mb16357_ctx *>(args);
11392+ compact_db (ctx->h , ctx->h1 , 0 , 99 , ctx->items , 1 );
11393+ }
11394+ }
11395+
11396+ static enum test_result test_mb16357 (ENGINE_HANDLE *h,
11397+ ENGINE_HANDLE_V1 *h1) {
11398+
11399+ // Load up vb0 with n items, expire in 1 second
11400+ int num_items = 1000 ;
11401+
11402+ for (int j = 0 ; j < num_items; ++j) {
11403+ item *i = NULL ;
11404+ std::stringstream ss;
11405+ ss << " key-" << j;
11406+ check (store (h, h1, NULL , OPERATION_SET ,
11407+ ss.str ().c_str (), " data" , &i, 0 , 0 , 1 /* expire*/ , 0 )
11408+ == ENGINE_SUCCESS , " Failed to store a value" ); // expire in 1 second
11409+
11410+ h1->release (h, NULL , i);
11411+ }
11412+
11413+ wait_for_flusher_to_settle (h, h1);
11414+ testHarness.time_travel (3617 ); // force expiry pushing time forward.
11415+
11416+ struct mb16357_ctx ctx (h, h1, num_items);
11417+ cb_thread_t cp_thread, dcp_thread;
11418+
11419+ cb_assert (cb_create_thread (&cp_thread,
11420+ compact_thread_func,
11421+ &ctx, 0 ) == 0 );
11422+ cb_assert (cb_create_thread (&dcp_thread,
11423+ dcp_thread_func,
11424+ &ctx, 0 ) == 0 );
11425+
11426+ cb_assert (cb_join_thread (cp_thread) == 0 );
11427+ cb_assert (cb_join_thread (dcp_thread) == 0 );
11428+
11429+ return SUCCESS ;
11430+ }
11431+
1132911432static enum test_result prepare (engine_test_t *test) {
1133011433#ifdef __sun
1133111434 // Some of the tests doesn't work on Solaris.. Don't know why yet..
@@ -12251,7 +12354,9 @@ engine_test_t* get_tests(void) {
1225112354
1225212355 TestCase (" test failover log behavior" , test_failover_log_behavior,
1225312356 test_setup, teardown, NULL , prepare, cleanup),
12254-
12357+ TestCase (" test MB-16357" , test_mb16357,
12358+ test_setup, teardown, " compaction_exp_mem_threshold=85" ,
12359+ prepare, cleanup),
1225512360 TestCase (NULL , NULL , NULL , NULL , NULL , prepare, cleanup)
1225612361 };
1225712362
0 commit comments