Skip to content
Snippets Groups Projects
  1. Aug 07, 2018
    • Kirill Shcherbatov's avatar
      sql: fix segfault with check referencing new table · 16c3989c
      Kirill Shcherbatov authored
      Starting from 9a543202 on tuple insertion in _space we
      execute sql_checks_resolve_space_def_reference for checks
      if any on executing on_replace_dd_space trigger. Routine
      box_space_id_by_name that takes a look to _space space
      returns not-null value, at the same time space object
      doesn't present in space cache and can't be found by
      space_by_id.
      Before 1.10 patch 0ecabde8 was merged to 2.0 as a part of
      13df2b1f box_space_id_by_name used to return BOX_ID_NIL
      due to "multi-engine transaction error" that is not raised
      in same situation now.
      
      Closes #3611.
      16c3989c
    • Nikita Pettik's avatar
      sql: remove SQLITE_OMIT_FOREIGN_KEY define guard · 502fb2b4
      Nikita Pettik authored
      We always compile with enabled foreign keys constraints. They still can
      be turned off by <pragma foreign_keys = false> in runtime.
      
      Follow-up #3271
      502fb2b4
    • Nikita Pettik's avatar
      sql: display error on FK creation and drop failure · deea0693
      Nikita Pettik authored
      Before insertion to _fk_constraint we must be sure that there is no
      entry with given <name, child id>. Otherwise, insertion will fail and
      'duplicate key' will be shown. Such error message doesn't seem to be
      informative enough, so lets verify before insertion to _fk_constraint
      that it doesn't already contain entry with given name.
      The same is for dropping constraint, but here vice versa: we test
      that _fk_constraint contains entry with given name and child id.
      
      It is worth mentioning that during CREATE TABLE processing schema id
      changes and check in OP_OpenRead opcode fails (which in turn shows that
      pointer to space may expire). On the other hand, _fk_constraint space
      itself remains immutable, so as a temporary workaround lets use flag
      indicating pointer to system space passed to OP_OpenRead. It makes
      possible to use pointer to space, even if schema has changed.
      
      Closes #3271
      deea0693
    • Nikita Pettik's avatar
      sql: introduce ADD CONSTRAINT statement · 4fe0b812
      Nikita Pettik authored
      After introducing separate space for persisting foreign key
      constraints, nothing prevents us from adding ALTER TABLE statement to
      add or drop named constraints. According to ANSI syntax is following:
      
      ALTER TABLE <referencing table> ADD CONSTRAINT
        <referential constraint name> FOREIGN KEY
        <left paren> <referencing columns> <right paren> REFERENCES
        <referenced table> [ <referenced columns> ] [ MATCH <match type> ]
        [ <referential triggered action> ] [ <constraint check time> ]
      
      ALTER TABLE <referencing table> DROP CONSTRAINT <constrain name>
      
      In our terms it looks like:
      
      ALTER TABLE t1 ADD CONSTRAINT f1 FOREIGN KEY(id, a)
          REFERENCES t2 (id, b) MATCH FULL;
      ALTER TABLE t1 DROP CONSTRAINT f1;
      
      FK constraints which come with CREATE TABLE statement are also
      persisted with auto-generated name. They are coded after space and its
      indexes.
      
      Moreover, we don't use original SQLite foreign keys anymore: those
      obsolete structs have been removed alongside FK hash. Now FK constraints
      are stored only in space.
      
      Since types of referencing and referenced fields must match, and now in
      SQL only PK is allowed to feature INT (other fields are always SCALAR),
      some tests have been corrected to obey this rule.
      
      Part of #3271
      4fe0b812
    • Nikita Pettik's avatar
      schema: add new system space for FK constraints · 78fef3d0
      Nikita Pettik authored
      This patch introduces new system space to persist foreign keys
      constraints. Format of the space:
      
      _fk_constraint (space id = 358)
      
      [<constraint name> STR, <parent id> UINT, <child id> UINT,
       <is deferred> BOOL, <match> STR, <on delete action> STR,
       <on update action> STR, <child cols> ARRAY<UINT>,
       <parent cols> ARRAY<UINT>]
      
      FK constraint is local to space, so every pair <FK name, child id>
      is unique (and it is PK in _fk_constraint space).
      
      After insertion into this space, new instance describing FK constraint
      is created. FK constraints are held in data-dictionary as two lists
      (for child and parent constraints) in struct space.
      
      There is a list of FK restrictions:
       - At the time of FK creation parent and child spaces must exist;
       - VIEWs can't be involved into FK processing;
       - Child space must be empty;
       - Types of referencing and referenced fields must be comparable;
       - Collations of referencing and referenced fields must match;
       - Referenced fields must compose unique index;
       - Referenced fields can not contain duplicates.
      
      Until space (child) features FK constraints it isn't allowed to be
      dropped. Implicitly referenced index also can't be dropped
      (and that is why parent space can't be dropped). But :drop() method
      of child space firstly deletes all FK constraint (the same as SQL
      triggers, indexes etc) and then removes entry from _space.
      
      Part of #3271
      
      Review fixes
      78fef3d0
    • Nikita Pettik's avatar
      sql: prohibit creation of FK on unexisting tables · 30287377
      Nikita Pettik authored
      Originally, SQLite allows to create table with foreign keys constraint
      which refers to yet not created parent table. For instance:
      
      CREATE TABLE child(id INT PRIMARY KEY REFERENCES parent);
      CREATE TABLE parent(id INT PRIMARY KEY);
      
      This patch bans such ability since it contradicts SQL ANSI.
      Moreover, SQLite allows to drop parent table if deletion of all rows
      wouldn't result in FK constraint violations. This feature has been
      removed since in such situation child table would become inconsistent.
      
      Finally, within current patch ability to create FK constraints on VIEWs
      is banned as well.
      
      Part of #3271
      30287377
    • Kirill Yukhin's avatar
      Merge branch '1.10' into 2.0 · 52bbfc7d
      Kirill Yukhin authored
      52bbfc7d
    • Kirill Yukhin's avatar
      Merge branch '1.9' into 1.10 · e39b4c19
      Kirill Yukhin authored
      e39b4c19
    • Vladimir Davydov's avatar
      box: serialize calls to box.cfg · 1d3a6cb0
      Vladimir Davydov authored
      It is dangerous to call box.cfg() concurrently from different fibers.
      For example, replication configuration uses static variables and yields
      so calling it concurrently can result in a crash. To make sure it never
      happens, let's protect box.cfg() with a lock.
      
      Closes #3606
      1d3a6cb0
  2. Aug 03, 2018
  3. Aug 02, 2018
  4. Aug 01, 2018
    • Vladimir Davydov's avatar
      txn: add helper to detect transaction boundaries · 13acfe47
      Vladimir Davydov authored
      Add txn_is_first_statement() function, which returns true if this is the
      first statement of the transaction. The function is supposed to be used
      from on_replace trigger to detect transaction boundaries.
      
      Needed for #2129
      13acfe47
    • Vladimir Davydov's avatar
      vinyl: rename vy_task::status to is_failed · 21eed04c
      Vladimir Davydov authored
      vy_task::status stores the return code of the ->execute method. There
      are only two codes in use: 0 - success and -1 - failure. So let's chage
      this to a boolean flag.
      21eed04c
    • Vladimir Davydov's avatar
      vinyl: zap vy_scheduler::is_worker_pool_running · d77b4dc9
      Vladimir Davydov authored
      This flag is set iff worker_pool != NULL hence it is pointless.
      d77b4dc9
    • Vladimir Davydov's avatar
      vinyl: use cbus for communication between scheduler and worker threads · f4625e64
      Vladimir Davydov authored
      We need cbus for forwarding deferred DELETE statements generated in a
      worker thread during primary index compaction to the tx thread where
      they can be inserted into secondary indexes. Since pthread mutex/cond
      and cbus are incompatible by their nature, let's rework communication
      channel between the tx and worker threads using cbus.
      
      Needed for #2129
      f4625e64
    • Vladimir Davydov's avatar
      vinyl: rename some members of vy_scheduler and vy_task struct · 46f50aad
      Vladimir Davydov authored
      I'm planning to add some new members and remove some old members from
      those structs. For this to play nicely, let's do some renames:
      
        vy_scheduler::workers_available => idle_worker_count
        vy_scheduler::input_queue       => pending_tasks
        vy_scheduler::output_queue      => processed_tasks
        vy_task::link                   => in_pending, in_processed
      46f50aad
    • Vladimir Davydov's avatar
      vinyl: store pointer to scheduler in struct vy_task · 1331d232
      Vladimir Davydov authored
      Currently, we don't really need it, but once we switch communication
      channel between the scheduler and workers from pthread mutex/cond to
      cbus (needed for #2129), tasks won't be completed on behalf of the
      scheduler fiber and hence we will need a back pointer from vy_task to
      vy_scheduler.
      
      Needed for #2129
      1331d232
    • Vladimir Davydov's avatar
      vinyl: do not free pending tasks on shutdown · 15c28b75
      Vladimir Davydov authored
      This is a prerequisite for switching scheduler-worker communication from
      pthread mutex/cond to cbus, which in turn is needed to generate and send
      deferred DELETEs from workers back to tx (#2129).
      
      After this patch, pending tasks will be leaked on shutdown. This is OK,
      as we leak a lot of objects on shutdown anyway. The proper way of fixing
      this leak would be to rework shutdown without atexit() so that we can
      use cbus till the very end.
      
      Needed for #2129
      15c28b75
    • Vladimir Davydov's avatar
      vinyl: store full tuples in secondary index cache · 0c5e6cc8
      Vladimir Davydov authored
      Currently, both vy_read_iterator_next() and vy_point_lookup() add the
      returned tuple to the tuple cache. As a result, we store partial tuples
      in a secondary index tuple cache although we could store full tuples
      (we have to retrieve them anyway when reading a secondary index). This
      means wasting memory. Besides, when the #2129 gets implemented, there
      will be tuples in a secondary index that have to be skipped as they have
      been overwritten in the primary index. Caching them would be inefficient
      and error prone. So let's call vy_cache_add() from the upper level and
      add only full tuples to the cache.
      
      Closes #3478
      Needed for #2129
      0c5e6cc8
  5. Jul 31, 2018
    • Vladimir Davydov's avatar
      vinyl: refactor unique check · 85608344
      Vladimir Davydov authored
      For the sake of further patches, let's do some refactoring:
       - Rename vy_check_is_unique to vy_check_is_unique_primary and use it
         only for checking the unique constraint of primary indexes. Also,
         make it return immediately if the primary index doesn't need
         uniqueness check, like vy_check_is_unique_secondary does.
       - Open-code uniqueness check in vy_check_is_unique_secondary instead of
         using vy_check_is_unique.
       - Reduce indentation level of vy_check_is_unique_secondary by inverting
         the if statement.
      85608344
    • Vladimir Davydov's avatar
      vinyl: fold vy_delete_impl · f88a0bd1
      Vladimir Davydov authored
      vy_delete_impl helper is only used once in vy_delete and it is rather
      small so inlining it definitely won't hurt. On the contrary, it will
      consolidate DELETE logic in one place, making the code easier to follow.
      f88a0bd1
    • Vladimir Davydov's avatar
      vinyl: fold vy_replace_one and vy_replace_impl · 1dfeb601
      Vladimir Davydov authored
      There's no point in separating REPLACE path between the cases when
      the space has secondary indexes and when it only has the primary
      index, because they are quite similar. Let's fold vy_replace_one
      and vy_replace_impl into vy_replace to remove code duplication.
      1dfeb601
    • Vladimir Davydov's avatar
      vinyl: always get full tuple from pk after reading from secondary index · 5ceca76c
      Vladimir Davydov authored
      Currently, we don't always need a full tuple. Sometimes (e.g. for
      checking uniqueness constraint), a partial tuple read from a secondary
      index is enough. So we have vy_lsm_get() which reads a partial tuple
      from an index. However, once the optimization described in #2129 is
      implemented, it might happen that a tuple read from a secondary index
      was overwritten or deleted in the primary index, but DELETE statement
      hasn't been propagated to the secondary index yet, i.e. we will have to
      read the primary index anyway, even if we don't need a full tuple.
      
      That said, let us:
      
       - Make vy_lsm_get() always fetch a full tuple, even for secondary
         indexes, and rename it to vy_get().
      
       - Rewrite vy_lsm_full_by_key() as a wrapper around vy_get() and rename
         it to vy_get_by_raw_key().
      
       - Introduce vy_get_by_secondary_tuple() which gets a full tuple given a
         tuple read from a secondary index. For now, it's basically a call to
         vy_point_lookup(), but it'll become a bit more complex once #2129 is
         implemented.
      
       - Prepare vy_get() for the fact that a tuple read from a secondary
         index may be absent in the primary index, in which case it should
         try the next matching one.
      
      Needed for #2129
      5ceca76c
    • Vladimir Davydov's avatar
      vinyl: simplify vy_squash_process · 128503ea
      Vladimir Davydov authored
      Since vy_point_lookup() now guarantees that it returns the newest
      tuple version, we can remove the code that squashes UPSERTs from
      vy_squash_process().
      128503ea
    • Vladimir Davydov's avatar
      vinyl: make point lookup always return the latest tuple version · 6d85c35c
      Vladimir Davydov authored
      Currently, vy_point_lookup(), in contrast to vy_read_iterator, doesn't
      rescan the memory level after reading disk, so if the caller doesn't
      track the key before calling this function, the caller won't be sent to
      a read view in case the key gets updated during yield and hence will
      be returned a stale tuple. This is OK now, because we always track the
      key before calling vy_point_lookup(), either in the primary or in a
      secondary index. However, for #2129 we need it to always return the
      latest tuple version, no matter if the key is tracked or not.
      
      The point is in the scope of #2129 we won't write DELETE statements to
      secondary indexes corresponding to a tuple replaced in the primary
      index. Instead after reading a tuple from a secondary index we will
      check whether it matches the tuple corresponding to it in the primary
      index: if it is not, it means that the tuple read from the secondary
      index was overwritten and should be skipped. E.g. suppose we have the
      primary index over the first field and a secondary index over the second
      field and the following statements in the space:
      
        REPLACE{1, 10}
        REPLACE{1, 20}
      
      Then reading {10} from the secondary index will return REPLACE{1, 10}, but
      lookup of {1} in the primary index will return REPLACE{1, 20} which
      doesn't match REPLACE{1, 10} read from the secondary index hence the
      latter was overwritten and should be skipped.
      
      The problem is in the example above we don't want to track key {1} in
      the primary index before lookup, because we don't actually read its
      value. So for the check to work correctly, we need the point lookup to
      guarantee that the returned tuple is always the newest one. It's fairly
      easy to do - we just need to rescan the memory level after yielding on
      disk if its version changed.
      
      Needed for #2129
      6d85c35c
    • Konstantin Nazarov's avatar
      Add tarantoolctl rocks pack/unpack subcommands · 0746fdb4
      Konstantin Nazarov authored
      The subcommands are used to create binary rock distributions.
      In context of #3525
      0746fdb4
    • Kirill Yukhin's avatar
      sql: remove pragma schema_version · f2debd8b
      Kirill Yukhin authored
      This pragma is dead and produces nothing else but segfault.
      Along w/ this pragma, remove now dead opcodes which set/read
      schema_version and all related routines.
      Also, improve opcode generation script.
      
      Part of #3541
      f2debd8b
Loading