Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19986

MyRocks: Range Locking: SeekForUpdate support

Details

    Description

      This is to support "Seek For Update" functionality in Range Locking feature for RocksDB.

      Initial input

      SeekForUpdate(prefix_X) -> should try to lock range from prefix_X to X
       
      Prototype with
        Seek(prefix_X) -> X; 
        TryRangeLock(prefix_X, X);
        Update snapshot (by destroying/recreating iterator?)
        Z = Seek(X) (optimizations, only look through memtable);
        if (Z > Y)
          return SeekForUpdate(X);
        else
          return Z;
      

      The code

      MyRocks part: https://github.com/spetrunia/mysql-5.6/tree/range-locking-fb-mysql-5.6.35-seekforupdate
      RocksDB part: https://github.com/spetrunia/rocksdb/tree/spetrunia-rocksdb-range-locking-seekforupdate

      Questions

      • criteria when to use SeekForUpdate
      • do we need to support shared locks in the first milestone? (TODO: check they will "happen to work"?)

      Attachments

        Issue Links

          Activity

            The API

            Class Transaction has a new member function w/o implementation

            class Transaction {
              ...
              virtual Iterator *GetLockingIterator() {return nullptr; }
            

            PessimisticTransaction implements it :

            class PessimisticTransaction {
              ...
              Iterator* GetLockingIterator() override;
            

            GetLockingIterator returns an object that will implement all iterator methods (not all methods are implemented yet):

            //
            // LockingIterator is an iterator that locks the rows before returning, as well
            // as the gaps between the returned rows.
            //
            //  Example:
            //    lock_iter= trx->GetLockingIterator();
            //    lock_iter->Seek('abc');
            //    lock_iter->Valid()==true && lock_iter->key() == 'bcd';
            //
            //   After the above, the returned record 'bcd' is locked by transaction trx.
            //   Also, the range between ['abc'..'bcd'] is guaranteed to have no records
            //   and be locked by trx.
            //
            //    lock_iter->Next();
            //    lock_iter->Valid()==true && lock_iter->key() == 'efg'
            //
            //   Now, the range ['bcd'.. 'efg'] (bounds incluive) is also locked, and the
            //   only records in it are 'bcd' and 'efg'.
            //
            class LockingIterator : public Iterator {
            ...
            };
            

            psergei Sergei Petrunia added a comment - The API Class Transaction has a new member function w/o implementation class Transaction { ... virtual Iterator *GetLockingIterator() { return nullptr; } PessimisticTransaction implements it : class PessimisticTransaction { ... Iterator* GetLockingIterator() override; GetLockingIterator returns an object that will implement all iterator methods (not all methods are implemented yet): // // LockingIterator is an iterator that locks the rows before returning, as well // as the gaps between the returned rows. // // Example: // lock_iter= trx->GetLockingIterator(); // lock_iter->Seek('abc'); // lock_iter->Valid()==true && lock_iter->key() == 'bcd'; // // After the above, the returned record 'bcd' is locked by transaction trx. // Also, the range between ['abc'..'bcd'] is guaranteed to have no records // and be locked by trx. // // lock_iter->Next(); // lock_iter->Valid()==true && lock_iter->key() == 'efg' // // Now, the range ['bcd'.. 'efg'] (bounds incluive) is also locked, and the // only records in it are 'bcd' and 'efg'. // class LockingIterator : public Iterator { ... };
            psergei Sergei Petrunia added a comment - - edited

            When to use SeekForUpdate

            At the moment, MyRocks will use SeekForUpdate when the scanned range has no other bound.

            Example 1: this uses range access:

            select * from t1 where pk >=700 limit 10 for update;
            

            Example 2: this uses index access:

            select * from t1 order by pk limit 10 for update;
            

            (Forward scans pass a basic test. Backward scans should be doable but I didn't have time to implement them, yet)

            TODO: is this a suitable criterion?

            psergei Sergei Petrunia added a comment - - edited When to use SeekForUpdate At the moment, MyRocks will use SeekForUpdate when the scanned range has no other bound. Example 1: this uses range access: select * from t1 where pk >=700 limit 10 for update ; Example 2: this uses index access: select * from t1 order by pk limit 10 for update ; (Forward scans pass a basic test. Backward scans should be doable but I didn't have time to implement them, yet) TODO: is this a suitable criterion?

            People

              psergei Sergei Petrunia
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.