diff --git a/src/box/engine_sophia.cc b/src/box/engine_sophia.cc index 4d1ac85aad2653a680a1026b83e36c50ce7e2d0e..a1e526d4fcce199f526efb573e44e17ea3fe2616 100644 --- a/src/box/engine_sophia.cc +++ b/src/box/engine_sophia.cc @@ -277,39 +277,19 @@ SophiaFactory::commit(struct txn *txn) tx = NULL; }); - /* a. prepare transaction for commit */ - int rc = sp_prepare(tx); - if (rc == -1) - sophia_raise(env); - assert(rc == 0); - - /* b. create transaction log cursor and - * forge each statement's LSN number. - */ - void *lc = sp_ctl(tx, "log_cursor"); - if (lc == NULL) { - sp_rollback(tx); - sophia_raise(env); - } + /* a. get max lsn for commit */ + uint64_t lsn = 0; struct txn_stmt *stmt; rlist_foreach_entry(stmt, &txn->stmts, next) { - if (stmt->new_tuple == NULL && stmt->old_tuple == NULL) - continue; - void *v = sp_get(lc); - assert(v != NULL); - sp_set(v, "lsn", stmt->row->lsn); - /* remove tuple reference */ - if (stmt->new_tuple) { - /* 2 refs: iproto case */ - /* 3 refs: lua case */ - assert(stmt->new_tuple->refs >= 2); - tuple_unref(stmt->new_tuple); - } + if (stmt->row->lsn > lsn) + lsn = stmt->row->lsn; } - assert(sp_get(lc) == NULL); - sp_destroy(lc); - /* c. commit transaction */ + /* b. commit transaction */ + int rc = sp_prepare(tx, lsn); + assert(rc == 0); + if (rc == -1) + sophia_raise(env); rc = sp_commit(tx); if (rc == -1) sophia_raise(env); diff --git a/src/box/sophia_index.cc b/src/box/sophia_index.cc index 46744c2ff5a031c4f92ef69fd94282080f4d03a3..6e26ded7359fcc39c5bceeb3a2570ee17edaf14d 100644 --- a/src/box/sophia_index.cc +++ b/src/box/sophia_index.cc @@ -132,15 +132,18 @@ sophia_configure(struct space *space, struct key_def *key_def) (SophiaFactory*)space->engine->factory; void *env = factory->env; void *c = sp_ctl(env); + char pointer[128]; char name[128]; snprintf(name, sizeof(name), "%" PRIu32, key_def->space_id); sp_set(c, "db", name); snprintf(name, sizeof(name), "db.%" PRIu32 ".index.cmp", key_def->space_id); - sp_set(c, name, sophia_index_compare); + snprintf(pointer, sizeof(pointer), "pointer: %p", (void*)sophia_index_compare); + sp_set(c, name, pointer); snprintf(name, sizeof(name), "db.%" PRIu32 ".index.cmp_arg", key_def->space_id); - sp_set(c, name, key_def); + snprintf(pointer, sizeof(pointer), "pointer: %p", (void*)key_def); + sp_set(c, name, pointer); snprintf(name, sizeof(name), "db.%" PRIu32, key_def->space_id); void *db = sp_get(c, name); if (db == NULL) @@ -204,7 +207,8 @@ SophiaIndex::random(uint32_t rnd) const if (o == NULL) sophia_raise(env); sp_set(o, "key", &rnd, sizeof(rnd)); - void *c = sp_cursor(db, "random", o); + sp_set(o, "order", "random"); + void *c = sp_cursor(db, o); if (c == NULL) sophia_raise(env); auto scoped_guard = @@ -306,6 +310,8 @@ SophiaIndex::replace(struct tuple *old_tuple, struct tuple *new_tuple, SophiaFactory *factory = (SophiaFactory *)space->engine->factory; assert(factory->tx != NULL); + + /* insert, replace or update */ if (new_tuple) { const char *key = tuple_field(new_tuple, key_def->parts[0].fieldno); const char *keyptr = key; @@ -330,7 +336,9 @@ SophiaIndex::replace(struct tuple *old_tuple, struct tuple *new_tuple, } if (dup_tuple) return dup_tuple; + return old_tuple; } + /* delete */ if (old_tuple) sophia_index_stmt(factory->tx, db, 1, key_def, old_tuple); return old_tuple; @@ -470,9 +478,10 @@ SophiaIndex::initIterator(struct iterator *ptr, void *o = sp_object(db); if (o == NULL) sophia_raise(env); + sp_set(o, "order", compare); if (key) sp_set(o, "key", key, keysize); - it->cursor = sp_cursor(db, compare, o); + it->cursor = sp_cursor(db, o); if (it->cursor == NULL) sophia_raise(env); } diff --git a/test/sophia/crud.result b/test/sophia/crud.result index 548a312a5ee65233f69274ddbd5d1b9644038d79..f96bcff12fb39f99356a4c5edba7b3a8518d6481 100644 --- a/test/sophia/crud.result +++ b/test/sophia/crud.result @@ -446,6 +446,10 @@ for key = 1, 132 do space:delete({key}) end for key = 1, 132 do assert(space:get({key}) == nil) end --- ... +-- delete nonexistent +space:delete({1234}) +--- +... -- select for key = 1, 96 do space:insert({key}) end --- diff --git a/test/sophia/crud.test.lua b/test/sophia/crud.test.lua index fea140c1aecf7857ff59579b42c6858066a1c4ed..1bc09b18c2b72d8b4f223ca53eb4388fabe20d16 100644 --- a/test/sophia/crud.test.lua +++ b/test/sophia/crud.test.lua @@ -27,6 +27,9 @@ t for key = 1, 132 do space:delete({key}) end for key = 1, 132 do assert(space:get({key}) == nil) end +-- delete nonexistent +space:delete({1234}) + -- select for key = 1, 96 do space:insert({key}) end diff --git a/test/sophia/dml.result b/test/sophia/dml.result index 923f9560857fd857b36c678eb0dbea438a03305d..10ce0b15df4f81cad172509f06bbb3d889346707 100644 --- a/test/sophia/dml.result +++ b/test/sophia/dml.result @@ -4,18 +4,14 @@ space = box.schema.create_space('test', { id = 100, engine = 'sophia' }) ... sophia_printdir() --- -- 'snapshot - -' +- ... space:drop() --- ... sophia_printdir() --- -- 'snapshot - -' +- ... -- index create/drop space = box.schema.create_space('test', { id = 101, engine = 'sophia' }) @@ -28,8 +24,6 @@ sophia_printdir() --- - '101 - snapshot - ' ... space:drop() @@ -37,9 +31,7 @@ space:drop() ... sophia_printdir() --- -- 'snapshot - -' +- ... -- index create/drop alter space = box.schema.create_space('test', { id = 102, engine = 'sophia' }) @@ -52,8 +44,6 @@ sophia_printdir() --- - '102 - snapshot - ' ... _index = box.space[box.schema.INDEX_ID] @@ -65,9 +55,7 @@ _index:delete{102, 0} ... sophia_printdir() --- -- 'snapshot - -' +- ... space:drop() --- @@ -87,8 +75,6 @@ sophia_printdir() --- - '103 - snapshot - ' ... space:drop() @@ -109,8 +95,6 @@ sophia_printdir() --- - '104 - snapshot - ' ... space:drop() @@ -144,9 +128,7 @@ space:drop() ... sophia_printdir() --- -- 'snapshot - -' +- ... -- index size space = box.schema.create_space('test', { id = 107, engine = 'sophia' }) diff --git a/test/sophia/gh.result b/test/sophia/gh.result index 45d9befc9f2e0487f9cdc1d24aeb611a652cf1dd..9a60d57f5fba8e5f7bf951f9dd90d443df857cc2 100644 --- a/test/sophia/gh.result +++ b/test/sophia/gh.result @@ -147,3 +147,21 @@ box.space['name_of_space']:select{'a'} s:drop() --- ... +-- gh-680: Sophia: assertion on update +s = box.schema.space.create('tester', {engine='sophia'}) +--- +... +i = s:create_index('primary',{type = 'tree', parts = {2, 'STR'}}) +--- +... +s:insert{1,'X'} +--- +- [1, 'X'] +... +s:update({'X'}, {{'=', 2, 'Y'}}) +--- +- [1, 'Y'] +... +s:drop() +--- +... diff --git a/test/sophia/gh.test.lua b/test/sophia/gh.test.lua index 01763075f1905afb6ec9a0602580f7cf667b932d..35fe9512e680f8cbaa998086bf78d403d6e78369 100644 --- a/test/sophia/gh.test.lua +++ b/test/sophia/gh.test.lua @@ -59,3 +59,10 @@ box.space['name_of_space']:select{'a'} box.space['name_of_space']:truncate() box.space['name_of_space']:select{'a'} s:drop() + +-- gh-680: Sophia: assertion on update +s = box.schema.space.create('tester', {engine='sophia'}) +i = s:create_index('primary',{type = 'tree', parts = {2, 'STR'}}) +s:insert{1,'X'} +s:update({'X'}, {{'=', 2, 'Y'}}) +s:drop() diff --git a/test/sophia/snapshot.result b/test/sophia/snapshot.result index 3633d2134127d46ff963fa7c43a27295bb595781..6452499061ef5f40faa85eb16aa78e053f1e1c2f 100644 --- a/test/sophia/snapshot.result +++ b/test/sophia/snapshot.result @@ -9,8 +9,6 @@ sophia_printdir() --- - '100 - snapshot - ' ... for key = 1, 351 do space:insert({key}) end diff --git a/third_party/sophia b/third_party/sophia index aa631d6eb47e22a69638187251e00c5a927bdae2..13d0195e8c2694e01219d87592a5dd8e6a2e3b41 160000 --- a/third_party/sophia +++ b/third_party/sophia @@ -1 +1 @@ -Subproject commit aa631d6eb47e22a69638187251e00c5a927bdae2 +Subproject commit 13d0195e8c2694e01219d87592a5dd8e6a2e3b41