Skip to content
Snippets Groups Projects
Commit db19532f authored by Alexandr's avatar Alexandr
Browse files

fix gh-464 lua iterators fix

parent d8f92d85
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,7 @@ struct iterator { ...@@ -88,6 +88,7 @@ struct iterator {
int sc_version; int sc_version;
uint32_t space_id; uint32_t space_id;
uint32_t index_id; uint32_t index_id;
class Index *index;
}; };
static inline void static inline void
......
...@@ -98,6 +98,7 @@ boxffi_index_iterator(uint32_t space_id, uint32_t index_id, int type, ...@@ -98,6 +98,7 @@ boxffi_index_iterator(uint32_t space_id, uint32_t index_id, int type,
it->sc_version = sc_version; it->sc_version = sc_version;
it->space_id = space_id; it->space_id = space_id;
it->index_id = index_id; it->index_id = index_id;
it->index = index;
return it; return it;
} catch (Exception *) { } catch (Exception *) {
if (it) if (it)
...@@ -113,6 +114,8 @@ boxffi_iterator_next(struct iterator *itr) ...@@ -113,6 +114,8 @@ boxffi_iterator_next(struct iterator *itr)
if (itr->sc_version != sc_version) { if (itr->sc_version != sc_version) {
try { try {
Index *index = check_index(itr->space_id, itr->index_id); Index *index = check_index(itr->space_id, itr->index_id);
if (index != itr->index)
return NULL;
if (index->sc_version > itr->sc_version) if (index->sc_version > itr->sc_version)
return NULL; return NULL;
itr->sc_version = sc_version; itr->sc_version = sc_version;
......
...@@ -911,3 +911,52 @@ gen(param, state) ...@@ -911,3 +911,52 @@ gen(param, state)
space:drop() space:drop()
--- ---
... ...
-------------------------------------------------------------------------------
-- Iterator: https://github.com/tarantool/tarantool/issues/464
-- Iterator safety after changing schema
-------------------------------------------------------------------------------
space = box.schema.create_space('test', {temporary=true})
---
...
space:create_index('primary', {type='HASH',unique=true})
---
...
space:create_index('t1', {type='TREE',unique=true})
---
...
space:create_index('t2', {type='TREE',unique=true})
---
...
box.space.test:insert{0}
---
- [0]
...
box.space.test:insert{1}
---
- [1]
...
gen, param, state = space.index.t1:pairs({}, {iterator = box.index.ALL})
---
...
print(gen(param, state))
---
...
id = s.index.t1.id
---
- error: '[string "id = s.index.t1.id "]:1: attempt to index field ''t1'' (a nil value)'
...
box.schema.index.drop(s.id, id)
---
- error: Illegal parameters, index_id should be a number
...
box.schema.index.alter(s.id, s.index.t2.id, {id = id})
---
- error: '[string "return box.schema.index.alter(s.id, s.index.t..."]:1: attempt to
index field ''t2'' (a nil value)'
...
print(gen(param, state))
---
...
space:drop()
---
...
...@@ -169,3 +169,28 @@ index_space:delete{space.id, space.index['i1'].id} ...@@ -169,3 +169,28 @@ index_space:delete{space.id, space.index['i1'].id}
gen(param, state) gen(param, state)
space:drop() space:drop()
-------------------------------------------------------------------------------
-- Iterator: https://github.com/tarantool/tarantool/issues/464
-- Iterator safety after changing schema
-------------------------------------------------------------------------------
space = box.schema.create_space('test', {temporary=true})
space:create_index('primary', {type='HASH',unique=true})
space:create_index('t1', {type='TREE',unique=true})
space:create_index('t2', {type='TREE',unique=true})
box.space.test:insert{0}
box.space.test:insert{1}
gen, param, state = space.index.t1:pairs({}, {iterator = box.index.ALL})
print(gen(param, state))
id = s.index.t1.id
box.schema.index.drop(s.id, id)
box.schema.index.alter(s.id, s.index.t2.id, {id = id})
print(gen(param, state))
space:drop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment