diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 69db2c81d3bfc09be2c269195fb5279ab0872b5b..df518fcc151d624a2132999d6051762e4c6b605d 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -3868,6 +3868,14 @@ vinyl_iterator_next(struct iterator *base, struct tuple **ret) } if (it->index->id > 0) { +#ifndef NDEBUG + struct errinj *delay = errinj(ERRINJ_VY_DELAY_PK_LOOKUP, + ERRINJ_BOOL); + if (delay && delay->bparam) { + while (delay->bparam) + fiber_sleep(0.01); + } +#endif /* Get the full tuple from the primary index. */ if (vy_index_get(it->index->pk, it->tx, it->rv, tuple, &tuple) != 0) diff --git a/src/errinj.h b/src/errinj.h index 512d2342f33e1b1686bc42461d87d8a1d94fd593..20f3824cfa58cf29922fb42fb0318664ddb67452 100644 --- a/src/errinj.h +++ b/src/errinj.h @@ -105,6 +105,7 @@ struct errinj { _(ERRINJ_BUILD_SECONDARY, ERRINJ_INT, {.iparam = -1}) \ _(ERRINJ_VY_POINT_ITER_WAIT, ERRINJ_BOOL, {.bparam = false}) \ _(ERRINJ_RELAY_EXIT_DELAY, ERRINJ_DOUBLE, {.dparam = 0}) \ + _(ERRINJ_VY_DELAY_PK_LOOKUP, ERRINJ_BOOL, {.bparam = false}) \ ENUM0(errinj_id, ERRINJ_LIST); extern struct errinj errinjs[]; diff --git a/test/box/errinj.result b/test/box/errinj.result index 355185169428cc3b1f9eef9d9b9c93084756ecec..4ef7e887c1cf650969d6fb4b0887d970da7b78ef 100644 --- a/test/box/errinj.result +++ b/test/box/errinj.result @@ -30,6 +30,8 @@ errinj.info() state: false ERRINJ_VYRUN_INDEX_GARBAGE: state: false + ERRINJ_VY_DELAY_PK_LOOKUP: + state: false ERRINJ_VY_TASK_COMPLETE: state: false ERRINJ_PORT_DUMP: diff --git a/test/vinyl/errinj.result b/test/vinyl/errinj.result index 8aaa47457dc4a12e12ccd22a97c508b9fba6cd54..5e4037cfdadf83311a3dcd2242de2cb2fe83dfa6 100644 --- a/test/vinyl/errinj.result +++ b/test/vinyl/errinj.result @@ -1194,3 +1194,68 @@ box.commit() s:drop() --- ... +-- +-- gh-2442: secondary index cursor must skip key update, made +-- after the secondary index scan, but before a primary index +-- lookup. It is ok, and the test checks this. +-- +s = box.schema.create_space('test', {engine = 'vinyl'}) +--- +... +pk = s:create_index('pk') +--- +... +sk = s:create_index('sk', {parts = {{2, 'unsigned'}}}) +--- +... +s:replace{1, 1} +--- +- [1, 1] +... +s:replace{3, 3} +--- +- [3, 3] +... +box.snapshot() +--- +- ok +... +ret = nil +--- +... +function do_read() ret = sk:select({2}, {iterator = 'GE'}) end +--- +... +errinj.set("ERRINJ_VY_DELAY_PK_LOOKUP", true) +--- +- ok +... +f = fiber.create(do_read) +--- +... +f:status() +--- +- suspended +... +ret +--- +- null +... +s:replace{2, 2} +--- +- [2, 2] +... +errinj.set("ERRINJ_VY_DELAY_PK_LOOKUP", false) +--- +- ok +... +while ret == nil do fiber.sleep(0.01) end +--- +... +ret +--- +- - [3, 3] +... +s:drop() +--- +... diff --git a/test/vinyl/errinj.test.lua b/test/vinyl/errinj.test.lua index 45eed72ebaaea596c20d7f13bbbb9b5562f88af2..bbfb44abda61eaba37e1f3eac8314b86b7b03ff7 100644 --- a/test/vinyl/errinj.test.lua +++ b/test/vinyl/errinj.test.lua @@ -466,3 +466,26 @@ value box.commit() s:drop() + +-- +-- gh-2442: secondary index cursor must skip key update, made +-- after the secondary index scan, but before a primary index +-- lookup. It is ok, and the test checks this. +-- +s = box.schema.create_space('test', {engine = 'vinyl'}) +pk = s:create_index('pk') +sk = s:create_index('sk', {parts = {{2, 'unsigned'}}}) +s:replace{1, 1} +s:replace{3, 3} +box.snapshot() +ret = nil +function do_read() ret = sk:select({2}, {iterator = 'GE'}) end +errinj.set("ERRINJ_VY_DELAY_PK_LOOKUP", true) +f = fiber.create(do_read) +f:status() +ret +s:replace{2, 2} +errinj.set("ERRINJ_VY_DELAY_PK_LOOKUP", false) +while ret == nil do fiber.sleep(0.01) end +ret +s:drop()