You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

786 lines
26 KiB

After merge fixes Removed compiler warnings Fixed clashing function name in maria Disable maria tests from MySQL level for now BitKeeper/deleted/.del-ha_maria.cc: Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc BitKeeper/etc/ignore: added libmysqld/ha_maria.cc --- added storage/maria/unittest/maria_control unittest/maria_control --- added *.Tpo --- added unittest/page_cache_test_file_1 --- added unittest/pagecache_debug.log --- added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big --- added unittest/mysys/mf_pagecache_single_64k-t-big Makefile.am: Don't run 'test-unit' by default (takes too long time) client/mysqldump.c: Fixed compiler warning include/lf.h: Remove compiler warnings about not used require_pins constant include/pagecache.h: LSN should be of type ulonglong (This fixes some compiler warnings) mysql-test/r/events_logs_tests.result: Make test predictable mysql-test/r/view.result: Make test results predictable mysql-test/t/disabled.def: Disable maria tests for a while mysql-test/t/events_logs_tests.test: Make test predictable mysql-test/t/view.test: Make test results predictable mysys/lf_alloc-pin.c: #warning ->QQ mysys/lf_hash.c: #warning ->QQ Removed compiler warnings mysys/mf_pagecache.c: Removed compiler warnings mysys/my_rename.c: Removed compiler warnings plugin/daemon_example/daemon_example.c: Remove compiler warning sql/ha_ndbcluster.cc: Remove compiler warning sql/udf_example.c: Remove compiler warning storage/maria/lockman.c: Changed #warnings to QQ comment Removed compiler warnings storage/maria/ma_blockrec.c: Removed compiler warnings storage/maria/ma_check.c: After merge fixes storage/maria/ma_key.c: After merge fixes storage/maria/ma_packrec.c: After merge fixes storage/maria/ma_rkey.c: After merge fixes storage/maria/ma_sort.c: After merge fixes storage/maria/ma_sp_defs.h: Rename clashing function name storage/maria/ma_sp_key.c: Rename clashing function name storage/maria/ma_test_all.res: New test results storage/maria/ma_unique.c: Fixed compiler warning storage/maria/tablockman.c: #warning -> QQ storage/maria/tablockman.h: #warning -> QQ storage/maria/trnman.c: #warning -> QQ storage/maria/unittest/lockman2-t.c: Removed compiler warnings storage/maria/unittest/ma_control_file-t.c: Removed warning for 'maria_control' file not found storage/maria/unittest/trnman-t.c: Removed compiler warnings storage/ndb/src/mgmapi/mgmapi.cpp: Remove compiler warnings unittest/mysys/mf_pagecache_consist.c: Removed compiler warnings unittest/mysys/my_atomic-t.c: Removed compiler warnings
19 years ago
GPL license update (same change as was done for all files in 5.1). storage/maria/Makefile.am: GPL license update storage/maria/ft_maria.c: GPL license update storage/maria/ha_maria.cc: GPL license update storage/maria/ha_maria.h: GPL license update storage/maria/lockman.c: GPL license update storage/maria/lockman.h: GPL license update storage/maria/ma_bitmap.c: GPL license update storage/maria/ma_blockrec.c: GPL license update storage/maria/ma_blockrec.h: GPL license update storage/maria/ma_cache.c: GPL license update storage/maria/ma_changed.c: GPL license update storage/maria/ma_check.c: GPL license update storage/maria/ma_checkpoint.c: GPL license update storage/maria/ma_checkpoint.h: GPL license update storage/maria/ma_checksum.c: GPL license update storage/maria/ma_close.c: GPL license update storage/maria/ma_control_file.c: GPL license update storage/maria/ma_control_file.h: GPL license update storage/maria/ma_create.c: GPL license update storage/maria/ma_dbug.c: GPL license update storage/maria/ma_delete.c: GPL license update storage/maria/ma_delete_all.c: GPL license update storage/maria/ma_delete_table.c: GPL license update storage/maria/ma_dynrec.c: GPL license update storage/maria/ma_extra.c: GPL license update storage/maria/ma_ft_boolean_search.c: GPL license update storage/maria/ma_ft_eval.c: GPL license update storage/maria/ma_ft_eval.h: GPL license update storage/maria/ma_ft_nlq_search.c: GPL license update storage/maria/ma_ft_parser.c: GPL license update storage/maria/ma_ft_stem.c: GPL license update storage/maria/ma_ft_test1.c: GPL license update storage/maria/ma_ft_test1.h: GPL license update storage/maria/ma_ft_update.c: GPL license update storage/maria/ma_ftdefs.h: GPL license update storage/maria/ma_fulltext.h: GPL license update storage/maria/ma_info.c: GPL license update storage/maria/ma_init.c: GPL license update storage/maria/ma_key.c: GPL license update storage/maria/ma_keycache.c: GPL license update storage/maria/ma_least_recently_dirtied.c: GPL license update storage/maria/ma_least_recently_dirtied.h: GPL license update storage/maria/ma_locking.c: GPL license update storage/maria/ma_open.c: GPL license update storage/maria/ma_packrec.c: GPL license update storage/maria/ma_page.c: GPL license update storage/maria/ma_panic.c: GPL license update storage/maria/ma_preload.c: GPL license update storage/maria/ma_range.c: GPL license update storage/maria/ma_recovery.c: GPL license update storage/maria/ma_recovery.h: GPL license update storage/maria/ma_rename.c: GPL license update storage/maria/ma_rfirst.c: GPL license update storage/maria/ma_rkey.c: GPL license update storage/maria/ma_rlast.c: GPL license update storage/maria/ma_rnext.c: GPL license update storage/maria/ma_rnext_same.c: GPL license update storage/maria/ma_rprev.c: GPL license update storage/maria/ma_rrnd.c: GPL license update storage/maria/ma_rsame.c: GPL license update storage/maria/ma_rsamepos.c: GPL license update storage/maria/ma_rt_index.c: GPL license update storage/maria/ma_rt_index.h: GPL license update storage/maria/ma_rt_key.c: GPL license update storage/maria/ma_rt_key.h: GPL license update storage/maria/ma_rt_mbr.c: GPL license update storage/maria/ma_rt_mbr.h: GPL license update storage/maria/ma_rt_split.c: GPL license update storage/maria/ma_rt_test.c: GPL license update storage/maria/ma_scan.c: GPL license update storage/maria/ma_search.c: GPL license update storage/maria/ma_sort.c: GPL license update storage/maria/ma_sp_defs.h: GPL license update storage/maria/ma_sp_key.c: GPL license update storage/maria/ma_sp_test.c: GPL license update storage/maria/ma_static.c: GPL license update storage/maria/ma_statrec.c: GPL license update storage/maria/ma_test1.c: GPL license update storage/maria/ma_test2.c: GPL license update storage/maria/ma_test3.c: GPL license update storage/maria/ma_unique.c: GPL license update storage/maria/ma_update.c: GPL license update storage/maria/ma_write.c: GPL license update storage/maria/maria_chk.c: GPL license update storage/maria/maria_def.h: GPL license update storage/maria/maria_ftdump.c: GPL license update storage/maria/maria_pack.c: GPL license update storage/maria/tablockman.c: GPL license update storage/maria/tablockman.h: GPL license update storage/maria/trnman.c: GPL license update storage/maria/trnman.h: GPL license update
19 years ago
After merge fixes Removed compiler warnings Fixed clashing function name in maria Disable maria tests from MySQL level for now BitKeeper/deleted/.del-ha_maria.cc: Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc BitKeeper/etc/ignore: added libmysqld/ha_maria.cc --- added storage/maria/unittest/maria_control unittest/maria_control --- added *.Tpo --- added unittest/page_cache_test_file_1 --- added unittest/pagecache_debug.log --- added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big --- added unittest/mysys/mf_pagecache_single_64k-t-big Makefile.am: Don't run 'test-unit' by default (takes too long time) client/mysqldump.c: Fixed compiler warning include/lf.h: Remove compiler warnings about not used require_pins constant include/pagecache.h: LSN should be of type ulonglong (This fixes some compiler warnings) mysql-test/r/events_logs_tests.result: Make test predictable mysql-test/r/view.result: Make test results predictable mysql-test/t/disabled.def: Disable maria tests for a while mysql-test/t/events_logs_tests.test: Make test predictable mysql-test/t/view.test: Make test results predictable mysys/lf_alloc-pin.c: #warning ->QQ mysys/lf_hash.c: #warning ->QQ Removed compiler warnings mysys/mf_pagecache.c: Removed compiler warnings mysys/my_rename.c: Removed compiler warnings plugin/daemon_example/daemon_example.c: Remove compiler warning sql/ha_ndbcluster.cc: Remove compiler warning sql/udf_example.c: Remove compiler warning storage/maria/lockman.c: Changed #warnings to QQ comment Removed compiler warnings storage/maria/ma_blockrec.c: Removed compiler warnings storage/maria/ma_check.c: After merge fixes storage/maria/ma_key.c: After merge fixes storage/maria/ma_packrec.c: After merge fixes storage/maria/ma_rkey.c: After merge fixes storage/maria/ma_sort.c: After merge fixes storage/maria/ma_sp_defs.h: Rename clashing function name storage/maria/ma_sp_key.c: Rename clashing function name storage/maria/ma_test_all.res: New test results storage/maria/ma_unique.c: Fixed compiler warning storage/maria/tablockman.c: #warning -> QQ storage/maria/tablockman.h: #warning -> QQ storage/maria/trnman.c: #warning -> QQ storage/maria/unittest/lockman2-t.c: Removed compiler warnings storage/maria/unittest/ma_control_file-t.c: Removed warning for 'maria_control' file not found storage/maria/unittest/trnman-t.c: Removed compiler warnings storage/ndb/src/mgmapi/mgmapi.cpp: Remove compiler warnings unittest/mysys/mf_pagecache_consist.c: Removed compiler warnings unittest/mysys/my_atomic-t.c: Removed compiler warnings
19 years ago
After merge fixes Removed compiler warnings Fixed clashing function name in maria Disable maria tests from MySQL level for now BitKeeper/deleted/.del-ha_maria.cc: Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc BitKeeper/etc/ignore: added libmysqld/ha_maria.cc --- added storage/maria/unittest/maria_control unittest/maria_control --- added *.Tpo --- added unittest/page_cache_test_file_1 --- added unittest/pagecache_debug.log --- added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big --- added unittest/mysys/mf_pagecache_single_64k-t-big Makefile.am: Don't run 'test-unit' by default (takes too long time) client/mysqldump.c: Fixed compiler warning include/lf.h: Remove compiler warnings about not used require_pins constant include/pagecache.h: LSN should be of type ulonglong (This fixes some compiler warnings) mysql-test/r/events_logs_tests.result: Make test predictable mysql-test/r/view.result: Make test results predictable mysql-test/t/disabled.def: Disable maria tests for a while mysql-test/t/events_logs_tests.test: Make test predictable mysql-test/t/view.test: Make test results predictable mysys/lf_alloc-pin.c: #warning ->QQ mysys/lf_hash.c: #warning ->QQ Removed compiler warnings mysys/mf_pagecache.c: Removed compiler warnings mysys/my_rename.c: Removed compiler warnings plugin/daemon_example/daemon_example.c: Remove compiler warning sql/ha_ndbcluster.cc: Remove compiler warning sql/udf_example.c: Remove compiler warning storage/maria/lockman.c: Changed #warnings to QQ comment Removed compiler warnings storage/maria/ma_blockrec.c: Removed compiler warnings storage/maria/ma_check.c: After merge fixes storage/maria/ma_key.c: After merge fixes storage/maria/ma_packrec.c: After merge fixes storage/maria/ma_rkey.c: After merge fixes storage/maria/ma_sort.c: After merge fixes storage/maria/ma_sp_defs.h: Rename clashing function name storage/maria/ma_sp_key.c: Rename clashing function name storage/maria/ma_test_all.res: New test results storage/maria/ma_unique.c: Fixed compiler warning storage/maria/tablockman.c: #warning -> QQ storage/maria/tablockman.h: #warning -> QQ storage/maria/trnman.c: #warning -> QQ storage/maria/unittest/lockman2-t.c: Removed compiler warnings storage/maria/unittest/ma_control_file-t.c: Removed warning for 'maria_control' file not found storage/maria/unittest/trnman-t.c: Removed compiler warnings storage/ndb/src/mgmapi/mgmapi.cpp: Remove compiler warnings unittest/mysys/mf_pagecache_consist.c: Removed compiler warnings unittest/mysys/my_atomic-t.c: Removed compiler warnings
19 years ago
This patch is a collection of patches from from Sanja, Sergei and Monty. Added logging and pinning of pages to block format. Integration of transaction manager, log handler. Better page cache intergration Split trnman.h into two files, so that we don't have to include my_atomic.h into C++ programs. Renaming of structures, more comments, more debugging etc. Fixed problem with small head block + long varchar. Added extra argument to delete_record() and update_record() (needed for UNDO logging) Small changes to interface of pagecache and log handler. Change initialization of log_record_type_descriptors to not be depending on enum order. Use array of LEX_STRING's to send data to log handler Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists. include/lf.h: Interface fixes Rename of structures (Patch from Sergei via Sanja) include/my_atomic.h: More comments include/my_global.h: Added MY_ERRPTR include/pagecache.h: Added undo LSN when unlocking pages mysql-test/r/maria.result: Updated results mysql-test/t/maria.test: Added autocommit around lock tables (Patch from Sanja) mysys/lf_alloc-pin.c: Post-review fixes, simple optimizations More comments Struct slot renames Check amount of memory on stack (Patch from Sergei) mysys/lf_dynarray.c: More comments mysys/lf_hash.c: More comments After review fixes (Patch from Sergei) storage/maria/ha_maria.cc: Split trnman.h into two files, so that we don't have to include my_atomic.h into the .cc program. (Temporary fix to avoid bug in gcc) Move out all deferencing of the transaction structure. Transaction manager integrated (Patch from Sergei) storage/maria/ha_maria.h: Added prototype for start_stmt() storage/maria/lockman.c: Function call rename storage/maria/ma_bitmap.c: Mark deleted pages free from page cache storage/maria/ma_blockrec.c: Offset -> rownr More debugging Fixed problem with small head block + long varchar Added logging of changed pages Added logging of undo (Including only loggging of changed fields in case of update) Added pinning/unpinning of all changed pages More comments Added free_full_pages() as the same code was used in several places. fill_rows_parts() renamed as fill_insert_undo_parts() offset -> rownr Added some optimization of not transactional tables _ma_update_block_record() has new parameter, as we need original row to do efficent undo for update storage/maria/ma_blockrec.h: Added ROW_EXTENTS_ON_STACK Changed prototype for update and delete of row storage/maria/ma_check.c: Added original row to delete_record() call storage/maria/ma_control_file.h: Added ifdefs for C++ storage/maria/ma_delete.c: Added original row to delete_record() call (Needed for efficent undo logging) storage/maria/ma_dynrec.c: Added extra argument to delete_record() and update_record() Removed not used variable storage/maria/ma_init.c: Initialize log handler storage/maria/ma_loghandler.c: Removed not used variable Change initialization of log_record_type_descriptors to not be depending on enum order Use array of LEX_STRING's to send data to log handler storage/maria/ma_loghandler.h: New defines Use array of LEX_STRING's to send data to log handler storage/maria/ma_open.c: Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists. Store in MARIA_SHARE->page_type if pages will have up to date LSN's storage/maria/ma_pagecache.c: Don't decrease number of readers when using pagecache_write()/pagecache_read() In pagecache_write() decrement request count if page was left pinned Added pagecache_delete_pages() Removed some casts Make trace output consistent with rest of code Simplify calling of DBUG_ASSERT(0) Only update LSN if the LSN is bigger than what's already on the page Added LSN parameter pagecache_unpin_page(), pagecache_unpin(), and pagecache_unlock() (Part of patch from Sanja) storage/maria/ma_static.c: Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists. Added default page cache storage/maria/ma_statrec.c: Added extra argument to delete_record() and update_record() storage/maria/ma_test1.c: Added option -T for transactions storage/maria/ma_test2.c: Added option -T for transactions storage/maria/ma_test_all.sh: Test with transactions storage/maria/ma_update.c: Changed prototype for update of row storage/maria/maria_def.h: Changed prototype for update & delete of row as block records need to access the old row Store in MARIA_SHARE->page_type if pages will have up to date LSN's Added MARIA_MAX_TREE_LEVELS to allow us to calculate the number of possible pinned pages we may need. Removed not used 'empty_bits_buffer' Added pointer to transaction object Added array for pinned pages Added log_row_parts array for logging of field data. Added MARIA_PINNED_PAGE to store pinned pages storage/maria/trnman.c: Added accessor functions to transaction object Added missing DBUG_RETURN() More debugging More comments Changed // comment of code to #ifdef NOT_USED Transaction manager integrated. Post review fixes Part of patch originally from Sergei storage/maria/trnman.h: Split trnman.h into two files, so that we don't have to include my_atomic.h into the .cc program. (Temporary fix to avoid bug in gcc) storage/maria/unittest/ma_pagecache_single.c: Added missing argument Added SKIP_BIG_TESTS (Patch from Sanja) storage/maria/unittest/ma_test_loghandler-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/ma_test_loghandler_multigroup-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/ma_test_loghandler_multithread-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/ma_test_loghandler_pagecache-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/trnman-t.c: Stack overflow detection (Patch from Sergei) unittest/unit.pl: Command-line options --big and --verbose (Patch from Sergei) unittest/mytap/tap.c: Detect --big (Patch from Sergei) unittest/mytap/tap.h: Skip_big_tests and SKIP_BIG_TESTS (Patch from Sergei) storage/maria/trnman_public.h: New BitKeeper file ``storage/maria/trnman_public.h''
19 years ago
After merge fixes Removed compiler warnings Fixed clashing function name in maria Disable maria tests from MySQL level for now BitKeeper/deleted/.del-ha_maria.cc: Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc BitKeeper/etc/ignore: added libmysqld/ha_maria.cc --- added storage/maria/unittest/maria_control unittest/maria_control --- added *.Tpo --- added unittest/page_cache_test_file_1 --- added unittest/pagecache_debug.log --- added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big --- added unittest/mysys/mf_pagecache_single_64k-t-big Makefile.am: Don't run 'test-unit' by default (takes too long time) client/mysqldump.c: Fixed compiler warning include/lf.h: Remove compiler warnings about not used require_pins constant include/pagecache.h: LSN should be of type ulonglong (This fixes some compiler warnings) mysql-test/r/events_logs_tests.result: Make test predictable mysql-test/r/view.result: Make test results predictable mysql-test/t/disabled.def: Disable maria tests for a while mysql-test/t/events_logs_tests.test: Make test predictable mysql-test/t/view.test: Make test results predictable mysys/lf_alloc-pin.c: #warning ->QQ mysys/lf_hash.c: #warning ->QQ Removed compiler warnings mysys/mf_pagecache.c: Removed compiler warnings mysys/my_rename.c: Removed compiler warnings plugin/daemon_example/daemon_example.c: Remove compiler warning sql/ha_ndbcluster.cc: Remove compiler warning sql/udf_example.c: Remove compiler warning storage/maria/lockman.c: Changed #warnings to QQ comment Removed compiler warnings storage/maria/ma_blockrec.c: Removed compiler warnings storage/maria/ma_check.c: After merge fixes storage/maria/ma_key.c: After merge fixes storage/maria/ma_packrec.c: After merge fixes storage/maria/ma_rkey.c: After merge fixes storage/maria/ma_sort.c: After merge fixes storage/maria/ma_sp_defs.h: Rename clashing function name storage/maria/ma_sp_key.c: Rename clashing function name storage/maria/ma_test_all.res: New test results storage/maria/ma_unique.c: Fixed compiler warning storage/maria/tablockman.c: #warning -> QQ storage/maria/tablockman.h: #warning -> QQ storage/maria/trnman.c: #warning -> QQ storage/maria/unittest/lockman2-t.c: Removed compiler warnings storage/maria/unittest/ma_control_file-t.c: Removed warning for 'maria_control' file not found storage/maria/unittest/trnman-t.c: Removed compiler warnings storage/ndb/src/mgmapi/mgmapi.cpp: Remove compiler warnings unittest/mysys/mf_pagecache_consist.c: Removed compiler warnings unittest/mysys/my_atomic-t.c: Removed compiler warnings
19 years ago
After merge fixes Removed compiler warnings Fixed clashing function name in maria Disable maria tests from MySQL level for now BitKeeper/deleted/.del-ha_maria.cc: Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc BitKeeper/etc/ignore: added libmysqld/ha_maria.cc --- added storage/maria/unittest/maria_control unittest/maria_control --- added *.Tpo --- added unittest/page_cache_test_file_1 --- added unittest/pagecache_debug.log --- added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big --- added unittest/mysys/mf_pagecache_single_64k-t-big Makefile.am: Don't run 'test-unit' by default (takes too long time) client/mysqldump.c: Fixed compiler warning include/lf.h: Remove compiler warnings about not used require_pins constant include/pagecache.h: LSN should be of type ulonglong (This fixes some compiler warnings) mysql-test/r/events_logs_tests.result: Make test predictable mysql-test/r/view.result: Make test results predictable mysql-test/t/disabled.def: Disable maria tests for a while mysql-test/t/events_logs_tests.test: Make test predictable mysql-test/t/view.test: Make test results predictable mysys/lf_alloc-pin.c: #warning ->QQ mysys/lf_hash.c: #warning ->QQ Removed compiler warnings mysys/mf_pagecache.c: Removed compiler warnings mysys/my_rename.c: Removed compiler warnings plugin/daemon_example/daemon_example.c: Remove compiler warning sql/ha_ndbcluster.cc: Remove compiler warning sql/udf_example.c: Remove compiler warning storage/maria/lockman.c: Changed #warnings to QQ comment Removed compiler warnings storage/maria/ma_blockrec.c: Removed compiler warnings storage/maria/ma_check.c: After merge fixes storage/maria/ma_key.c: After merge fixes storage/maria/ma_packrec.c: After merge fixes storage/maria/ma_rkey.c: After merge fixes storage/maria/ma_sort.c: After merge fixes storage/maria/ma_sp_defs.h: Rename clashing function name storage/maria/ma_sp_key.c: Rename clashing function name storage/maria/ma_test_all.res: New test results storage/maria/ma_unique.c: Fixed compiler warning storage/maria/tablockman.c: #warning -> QQ storage/maria/tablockman.h: #warning -> QQ storage/maria/trnman.c: #warning -> QQ storage/maria/unittest/lockman2-t.c: Removed compiler warnings storage/maria/unittest/ma_control_file-t.c: Removed warning for 'maria_control' file not found storage/maria/unittest/trnman-t.c: Removed compiler warnings storage/ndb/src/mgmapi/mgmapi.cpp: Remove compiler warnings unittest/mysys/mf_pagecache_consist.c: Removed compiler warnings unittest/mysys/my_atomic-t.c: Removed compiler warnings
19 years ago
After merge fixes Removed compiler warnings Fixed clashing function name in maria Disable maria tests from MySQL level for now BitKeeper/deleted/.del-ha_maria.cc: Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc BitKeeper/etc/ignore: added libmysqld/ha_maria.cc --- added storage/maria/unittest/maria_control unittest/maria_control --- added *.Tpo --- added unittest/page_cache_test_file_1 --- added unittest/pagecache_debug.log --- added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big --- added unittest/mysys/mf_pagecache_single_64k-t-big Makefile.am: Don't run 'test-unit' by default (takes too long time) client/mysqldump.c: Fixed compiler warning include/lf.h: Remove compiler warnings about not used require_pins constant include/pagecache.h: LSN should be of type ulonglong (This fixes some compiler warnings) mysql-test/r/events_logs_tests.result: Make test predictable mysql-test/r/view.result: Make test results predictable mysql-test/t/disabled.def: Disable maria tests for a while mysql-test/t/events_logs_tests.test: Make test predictable mysql-test/t/view.test: Make test results predictable mysys/lf_alloc-pin.c: #warning ->QQ mysys/lf_hash.c: #warning ->QQ Removed compiler warnings mysys/mf_pagecache.c: Removed compiler warnings mysys/my_rename.c: Removed compiler warnings plugin/daemon_example/daemon_example.c: Remove compiler warning sql/ha_ndbcluster.cc: Remove compiler warning sql/udf_example.c: Remove compiler warning storage/maria/lockman.c: Changed #warnings to QQ comment Removed compiler warnings storage/maria/ma_blockrec.c: Removed compiler warnings storage/maria/ma_check.c: After merge fixes storage/maria/ma_key.c: After merge fixes storage/maria/ma_packrec.c: After merge fixes storage/maria/ma_rkey.c: After merge fixes storage/maria/ma_sort.c: After merge fixes storage/maria/ma_sp_defs.h: Rename clashing function name storage/maria/ma_sp_key.c: Rename clashing function name storage/maria/ma_test_all.res: New test results storage/maria/ma_unique.c: Fixed compiler warning storage/maria/tablockman.c: #warning -> QQ storage/maria/tablockman.h: #warning -> QQ storage/maria/trnman.c: #warning -> QQ storage/maria/unittest/lockman2-t.c: Removed compiler warnings storage/maria/unittest/ma_control_file-t.c: Removed warning for 'maria_control' file not found storage/maria/unittest/trnman-t.c: Removed compiler warnings storage/ndb/src/mgmapi/mgmapi.cpp: Remove compiler warnings unittest/mysys/mf_pagecache_consist.c: Removed compiler warnings unittest/mysys/my_atomic-t.c: Removed compiler warnings
19 years ago
  1. /* QQ: TODO - allocate everything from dynarrays !!! (benchmark) */
  2. /* QQ: TODO instant duration locks */
  3. /* QQ: #warning automatically place S instead of LS if possible */
  4. /* Copyright (C) 2006 MySQL AB
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; version 2 of the License.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  15. /*
  16. Generic Lock Manager
  17. Lock manager handles locks on "resources", a resource must be uniquely
  18. identified by a 64-bit number. Lock manager itself does not imply
  19. anything about the nature of a resource - it can be a row, a table, a
  20. database, or just anything.
  21. Locks belong to "lock owners". A Lock owner is uniquely identified by a
  22. 16-bit number. A function loid2lo must be provided by the application
  23. that takes such a number as an argument and returns a LOCK_OWNER
  24. structure.
  25. Lock levels are completely defined by three tables. Lock compatibility
  26. matrix specifies which locks can be held at the same time on a resource.
  27. Lock combining matrix specifies what lock level has the same behaviour as
  28. a pair of two locks of given levels. getlock_result matrix simplifies
  29. intention locking and lock escalation for an application, basically it
  30. defines which locks are intention locks and which locks are "loose"
  31. locks. It is only used to provide better diagnostics for the
  32. application, lock manager itself does not differentiate between normal,
  33. intention, and loose locks.
  34. Internally lock manager is based on a lock-free hash, see lf_hash.c for
  35. details. All locks are stored in a hash, with a resource id as a search
  36. key, so all locks for the same resource will be considered collisions and
  37. will be put in a one (lock-free) linked list. The main lock-handling
  38. logic is in the inner loop that searches for a lock in such a linked
  39. list - lockfind().
  40. This works as follows. Locks generally are added to the end of the list
  41. (with one exception, see below). When scanning the list it is always
  42. possible to determine what locks are granted (active) and what locks are
  43. waiting - first lock is obviously active, the second is active if it's
  44. compatible with the first, and so on, a lock is active if it's compatible
  45. with all previous locks and all locks before it are also active.
  46. To calculate the "compatible with all previous locks" all locks are
  47. accumulated in prev_lock variable using lock_combining_matrix.
  48. Lock upgrades: when a thread that has a lock on a given resource,
  49. requests a new lock on the same resource and the old lock is not enough
  50. to satisfy new lock requirements (which is defined by
  51. lock_combining_matrix[old_lock][new_lock] != old_lock), a new lock is
  52. placed in the list. Depending on other locks it is immediately active or
  53. it will wait for other locks. Here's an exception to "locks are added
  54. to the end" rule - upgraded locks are added after the last active lock
  55. but before all waiting locks. Old lock (the one we upgraded from) is
  56. not removed from the list, indeed it may be needed if the new lock was
  57. in a savepoint that gets rolled back. So old lock is marked as "ignored"
  58. (IGNORE_ME flag). New lock gets an UPGRADED flag.
  59. Loose locks add an important exception to the above. Loose locks do not
  60. always commute with other locks. In the list IX-LS both locks are active,
  61. while in the LS-IX list only the first lock is active. This creates a
  62. problem in lock upgrades. If the list was IX-LS and the owner of the
  63. first lock wants to place LS lock (which can be immediately granted), the
  64. IX lock is upgraded to LSIX and the list becomes IX-LS-LSIX, which,
  65. according to the lock compatibility matrix means that the last lock is
  66. waiting - of course it all happened because IX and LS were swapped and
  67. they don't commute. To work around this there's ACTIVE flag which is set
  68. in every lock that never waited (was placed active), and this flag
  69. overrides "compatible with all previous locks" rule.
  70. When a lock is placed to the end of the list it's either compatible with
  71. all locks and all locks are active - new lock becomes active at once, or
  72. it conflicts with some of the locks, in this case in the 'blocker'
  73. variable a conflicting lock is returned and the calling thread waits on a
  74. pthread condition in the LOCK_OWNER structure of the owner of the
  75. conflicting lock. Or a new lock is compatible with all locks, but some
  76. existing locks are not compatible with each other (example: request IS,
  77. when the list is S-IX) - that is not all locks are active. In this case a
  78. first waiting lock is returned in the 'blocker' variable, lockman_getlock()
  79. notices that a "blocker" does not conflict with the requested lock, and
  80. "dereferences" it, to find the lock that it's waiting on. The calling
  81. thread than begins to wait on the same lock.
  82. To better support table-row relations where one needs to lock the table
  83. with an intention lock before locking the row, extended diagnostics is
  84. provided. When an intention lock (presumably on a table) is granted,
  85. lockman_getlock() returns one of GOT_THE_LOCK (no need to lock the row,
  86. perhaps the thread already has a normal lock on this table),
  87. GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE (need to lock the row, as usual),
  88. GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE (only need to check
  89. whether it's possible to lock the row, but no need to lock it - perhaps
  90. the thread has a loose lock on this table). This is defined by
  91. getlock_result[] table.
  92. */
  93. #include <my_global.h>
  94. #include <my_sys.h>
  95. #include <my_bit.h>
  96. #include <lf.h>
  97. #include "lockman.h"
  98. /*
  99. Lock compatibility matrix.
  100. It's asymmetric. Read it as "Somebody has the lock <value in the row
  101. label>, can I set the lock <value in the column label> ?"
  102. ') Though you can take LS lock while somebody has S lock, it makes no
  103. sense - it's simpler to take S lock too.
  104. 1 - compatible
  105. 0 - incompatible
  106. -1 - "impossible", so that we can assert the impossibility.
  107. */
  108. static int lock_compatibility_matrix[10][10]=
  109. { /* N S X IS IX SIX LS LX SLX LSIX */
  110. { -1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* N */
  111. { -1, 1, 0, 1, 0, 0, 1, 0, 0, 0 }, /* S */
  112. { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* X */
  113. { -1, 1, 0, 1, 1, 1, 1, 1, 1, 1 }, /* IS */
  114. { -1, 0, 0, 1, 1, 0, 1, 1, 0, 1 }, /* IX */
  115. { -1, 0, 0, 1, 0, 0, 1, 0, 0, 0 }, /* SIX */
  116. { -1, 1, 0, 1, 0, 0, 1, 0, 0, 0 }, /* LS */
  117. { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* LX */
  118. { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* SLX */
  119. { -1, 0, 0, 1, 0, 0, 1, 0, 0, 0 } /* LSIX */
  120. };
  121. /*
  122. Lock combining matrix.
  123. It's symmetric. Read it as "what lock level L is identical to the
  124. set of two locks A and B"
  125. One should never get N from it, we assert the impossibility
  126. */
  127. static enum lock_type lock_combining_matrix[10][10]=
  128. {/* N S X IS IX SIX LS LX SLX LSIX */
  129. { N, S, X, IS, IX, SIX, S, SLX, SLX, SIX}, /* N */
  130. { S, S, X, S, SIX, SIX, S, SLX, SLX, SIX}, /* S */
  131. { X, X, X, X, X, X, X, X, X, X}, /* X */
  132. { IS, S, X, IS, IX, SIX, LS, LX, SLX, LSIX}, /* IS */
  133. { IX, SIX, X, IX, IX, SIX, LSIX, LX, SLX, LSIX}, /* IX */
  134. { SIX, SIX, X, SIX, SIX, SIX, SIX, SLX, SLX, SIX}, /* SIX */
  135. { LS, S, X, LS, LSIX, SIX, LS, LX, SLX, LSIX}, /* LS */
  136. { LX, SLX, X, LX, LX, SLX, LX, LX, SLX, LX}, /* LX */
  137. { SLX, SLX, X, SLX, SLX, SLX, SLX, SLX, SLX, SLX}, /* SLX */
  138. { LSIX, SIX, X, LSIX, LSIX, SIX, LSIX, LX, SLX, LSIX} /* LSIX */
  139. };
  140. #define REPEAT_ONCE_MORE 0
  141. #define OK_TO_PLACE_THE_LOCK 1
  142. #define OK_TO_PLACE_THE_REQUEST 2
  143. #define ALREADY_HAVE_THE_LOCK 4
  144. #define ALREADY_HAVE_THE_REQUEST 8
  145. #define PLACE_NEW_DISABLE_OLD 16
  146. #define REQUEST_NEW_DISABLE_OLD 32
  147. #define RESOURCE_WAS_UNLOCKED 64
  148. #define NEED_TO_WAIT (OK_TO_PLACE_THE_REQUEST | ALREADY_HAVE_THE_REQUEST |\
  149. REQUEST_NEW_DISABLE_OLD)
  150. #define ALREADY_HAVE (ALREADY_HAVE_THE_LOCK | ALREADY_HAVE_THE_REQUEST)
  151. #define LOCK_UPGRADE (PLACE_NEW_DISABLE_OLD | REQUEST_NEW_DISABLE_OLD)
  152. /*
  153. the return codes for lockman_getlock
  154. It's asymmetric. Read it as "I have the lock <value in the row label>,
  155. what value should be returned for <value in the column label> ?"
  156. 0 means impossible combination (assert!)
  157. Defines below help to preserve the table structure.
  158. I/L/A values are self explanatory
  159. x means the combination is possible (assert should not crash)
  160. but it cannot happen in row locks, only in table locks (S,X),
  161. or lock escalations (LS,LX)
  162. */
  163. #define I GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE
  164. #define L GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE
  165. #define A GOT_THE_LOCK
  166. #define x GOT_THE_LOCK
  167. static enum lockman_getlock_result getlock_result[10][10]=
  168. {/* N S X IS IX SIX LS LX SLX LSIX */
  169. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* N */
  170. { 0, x, 0, A, 0, 0, x, 0, 0, 0}, /* S */
  171. { 0, x, x, A, A, 0, x, x, 0, 0}, /* X */
  172. { 0, 0, 0, I, 0, 0, 0, 0, 0, 0}, /* IS */
  173. { 0, 0, 0, I, I, 0, 0, 0, 0, 0}, /* IX */
  174. { 0, x, 0, A, I, 0, x, 0, 0, 0}, /* SIX */
  175. { 0, 0, 0, L, 0, 0, x, 0, 0, 0}, /* LS */
  176. { 0, 0, 0, L, L, 0, x, x, 0, 0}, /* LX */
  177. { 0, x, 0, A, L, 0, x, x, 0, 0}, /* SLX */
  178. { 0, 0, 0, L, I, 0, x, 0, 0, 0} /* LSIX */
  179. };
  180. #undef I
  181. #undef L
  182. #undef A
  183. #undef x
  184. LF_REQUIRE_PINS(4);
  185. typedef struct lockman_lock {
  186. uint64 resource;
  187. struct lockman_lock *lonext;
  188. intptr volatile link;
  189. uint32 hashnr;
  190. /* QQ: TODO - remove hashnr from LOCK */
  191. uint16 loid;
  192. uchar lock; /* sizeof(uchar) <= sizeof(enum) */
  193. uchar flags;
  194. } LOCK;
  195. #define IGNORE_ME 1
  196. #define UPGRADED 2
  197. #define ACTIVE 4
  198. typedef struct {
  199. intptr volatile *prev;
  200. LOCK *curr, *next;
  201. LOCK *blocker, *upgrade_from;
  202. } CURSOR;
  203. #define PTR(V) (LOCK *)((V) & (~(intptr)1))
  204. #define DELETED(V) ((V) & 1)
  205. /*
  206. NOTE
  207. cursor is positioned in either case
  208. pins[0..3] are used, they are NOT removed on return
  209. */
  210. static int lockfind(LOCK * volatile *head, LOCK *node,
  211. CURSOR *cursor, LF_PINS *pins)
  212. {
  213. uint32 hashnr, cur_hashnr;
  214. uint64 resource, cur_resource;
  215. intptr link;
  216. my_bool cur_active, compatible, upgrading, prev_active;
  217. enum lock_type lock, prev_lock, cur_lock;
  218. uint16 loid, cur_loid;
  219. int cur_flags, flags;
  220. hashnr= node->hashnr;
  221. resource= node->resource;
  222. lock= node->lock;
  223. loid= node->loid;
  224. flags= node->flags;
  225. retry:
  226. cursor->prev= (intptr *)head;
  227. prev_lock= N;
  228. cur_active= TRUE;
  229. compatible= TRUE;
  230. upgrading= FALSE;
  231. cursor->blocker= cursor->upgrade_from= 0;
  232. _lf_unpin(pins, 3);
  233. do {
  234. cursor->curr= PTR(*cursor->prev);
  235. _lf_pin(pins, 1, cursor->curr);
  236. } while(*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);
  237. for (;;)
  238. {
  239. if (!cursor->curr)
  240. break;
  241. do {
  242. link= cursor->curr->link;
  243. cursor->next= PTR(link);
  244. _lf_pin(pins, 0, cursor->next);
  245. } while(link != cursor->curr->link && LF_BACKOFF);
  246. cur_hashnr= cursor->curr->hashnr;
  247. cur_resource= cursor->curr->resource;
  248. cur_lock= cursor->curr->lock;
  249. cur_loid= cursor->curr->loid;
  250. cur_flags= cursor->curr->flags;
  251. if (*cursor->prev != (intptr)cursor->curr)
  252. {
  253. (void)LF_BACKOFF;
  254. goto retry;
  255. }
  256. if (!DELETED(link))
  257. {
  258. if (cur_hashnr > hashnr ||
  259. (cur_hashnr == hashnr && cur_resource >= resource))
  260. {
  261. if (cur_hashnr > hashnr || cur_resource > resource)
  262. break;
  263. /* ok, we have a lock for this resource */
  264. DBUG_ASSERT(lock_compatibility_matrix[prev_lock][cur_lock] >= 0);
  265. DBUG_ASSERT(lock_compatibility_matrix[cur_lock][lock] >= 0);
  266. if ((cur_flags & IGNORE_ME) && ! (flags & IGNORE_ME))
  267. {
  268. DBUG_ASSERT(cur_active);
  269. if (cur_loid == loid)
  270. cursor->upgrade_from= cursor->curr;
  271. }
  272. else
  273. {
  274. prev_active= cur_active;
  275. if (cur_flags & ACTIVE)
  276. DBUG_ASSERT(prev_active == TRUE);
  277. else
  278. cur_active&= lock_compatibility_matrix[prev_lock][cur_lock];
  279. if (upgrading && !cur_active /*&& !(cur_flags & UPGRADED)*/)
  280. break;
  281. if (prev_active && !cur_active)
  282. {
  283. cursor->blocker= cursor->curr;
  284. _lf_pin(pins, 3, cursor->curr);
  285. }
  286. if (cur_loid == loid)
  287. {
  288. /* we already have a lock on this resource */
  289. DBUG_ASSERT(lock_combining_matrix[cur_lock][lock] != N);
  290. DBUG_ASSERT(!upgrading || (flags & IGNORE_ME));
  291. if (lock_combining_matrix[cur_lock][lock] == cur_lock)
  292. {
  293. /* new lock is compatible */
  294. if (cur_active)
  295. {
  296. cursor->blocker= cursor->curr; /* loose-locks! */
  297. _lf_unpin(pins, 3); /* loose-locks! */
  298. return ALREADY_HAVE_THE_LOCK;
  299. }
  300. else
  301. return ALREADY_HAVE_THE_REQUEST;
  302. }
  303. /* not compatible, upgrading */
  304. upgrading= TRUE;
  305. cursor->upgrade_from= cursor->curr;
  306. }
  307. else
  308. {
  309. if (!lock_compatibility_matrix[cur_lock][lock])
  310. {
  311. compatible= FALSE;
  312. cursor->blocker= cursor->curr;
  313. _lf_pin(pins, 3, cursor->curr);
  314. }
  315. }
  316. prev_lock= lock_combining_matrix[prev_lock][cur_lock];
  317. DBUG_ASSERT(prev_lock != N);
  318. }
  319. }
  320. cursor->prev= &(cursor->curr->link);
  321. _lf_pin(pins, 2, cursor->curr);
  322. }
  323. else
  324. {
  325. if (my_atomic_casptr((void **)cursor->prev,
  326. (void **)&cursor->curr, cursor->next))
  327. _lf_alloc_free(pins, cursor->curr);
  328. else
  329. {
  330. (void)LF_BACKOFF;
  331. goto retry;
  332. }
  333. }
  334. cursor->curr= cursor->next;
  335. _lf_pin(pins, 1, cursor->curr);
  336. }
  337. /*
  338. either the end of lock list - no more locks for this resource,
  339. or upgrading and the end of active lock list
  340. */
  341. if (upgrading)
  342. {
  343. if (compatible /*&& prev_active*/)
  344. return PLACE_NEW_DISABLE_OLD;
  345. else
  346. return REQUEST_NEW_DISABLE_OLD;
  347. }
  348. if (cur_active && compatible)
  349. {
  350. /*
  351. either no locks for this resource or all are compatible.
  352. ok to place the lock in any case.
  353. */
  354. return prev_lock == N ? RESOURCE_WAS_UNLOCKED
  355. : OK_TO_PLACE_THE_LOCK;
  356. }
  357. /* we have a lock conflict. ok to place a lock request. And wait */
  358. return OK_TO_PLACE_THE_REQUEST;
  359. }
  360. /*
  361. NOTE
  362. it uses pins[0..3], on return pins 0..2 are removed, pin 3 (blocker) stays
  363. */
  364. static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
  365. LOCK **blocker)
  366. {
  367. CURSOR cursor;
  368. int res;
  369. do
  370. {
  371. res= lockfind(head, node, &cursor, pins);
  372. DBUG_ASSERT(res != ALREADY_HAVE_THE_REQUEST);
  373. if (!(res & ALREADY_HAVE))
  374. {
  375. if (res & LOCK_UPGRADE)
  376. {
  377. node->flags|= UPGRADED;
  378. node->lock= lock_combining_matrix[cursor.upgrade_from->lock][node->lock];
  379. }
  380. if (!(res & NEED_TO_WAIT))
  381. node->flags|= ACTIVE;
  382. node->link= (intptr)cursor.curr;
  383. DBUG_ASSERT(node->link != (intptr)node);
  384. DBUG_ASSERT(cursor.prev != &node->link);
  385. if (!my_atomic_casptr((void **)cursor.prev, (void **)&cursor.curr, node))
  386. {
  387. res= REPEAT_ONCE_MORE;
  388. node->flags&= ~ACTIVE;
  389. }
  390. if (res & LOCK_UPGRADE)
  391. cursor.upgrade_from->flags|= IGNORE_ME;
  392. /*
  393. QQ: is this OK ? if a reader has already read upgrade_from,
  394. it may find it conflicting with node :(
  395. - see the last test from test_lockman_simple()
  396. */
  397. }
  398. } while (res == REPEAT_ONCE_MORE);
  399. _lf_unpin(pins, 0);
  400. _lf_unpin(pins, 1);
  401. _lf_unpin(pins, 2);
  402. /*
  403. note that blocker is not necessarily pinned here (when it's == curr).
  404. this is ok as in such a case it's either a dummy node for
  405. initialize_bucket() and dummy nodes don't need pinning,
  406. or it's a lock of the same transaction for lockman_getlock,
  407. and it cannot be removed by another thread
  408. */
  409. *blocker= cursor.blocker;
  410. return res;
  411. }
  412. /*
  413. NOTE
  414. it uses pins[0..3], on return pins 0..2 are removed, pin 3 (blocker) stays
  415. */
  416. static int lockpeek(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
  417. LOCK **blocker)
  418. {
  419. CURSOR cursor;
  420. int res;
  421. res= lockfind(head, node, &cursor, pins);
  422. _lf_unpin(pins, 0);
  423. _lf_unpin(pins, 1);
  424. _lf_unpin(pins, 2);
  425. if (blocker)
  426. *blocker= cursor.blocker;
  427. return res;
  428. }
  429. /*
  430. NOTE
  431. it uses pins[0..3], on return all pins are removed.
  432. One _must_ have the lock (or request) to call this
  433. */
  434. static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
  435. {
  436. CURSOR cursor;
  437. int res;
  438. do
  439. {
  440. res= lockfind(head, node, &cursor, pins);
  441. DBUG_ASSERT(res & ALREADY_HAVE);
  442. if (cursor.upgrade_from)
  443. cursor.upgrade_from->flags&= ~IGNORE_ME;
  444. /*
  445. XXX this does not work with savepoints, as old lock is left ignored.
  446. It cannot be unignored, as would basically mean moving the lock back
  447. in the lock chain (from upgraded). And the latter is not allowed -
  448. because it breaks list scanning. So old ignored lock must be deleted,
  449. new - same - lock must be installed right after the lock we're deleting,
  450. then we can delete. Good news is - this is only required when rolling
  451. back a savepoint.
  452. */
  453. if (my_atomic_casptr((void **)&(cursor.curr->link),
  454. (void **)&cursor.next, 1+(char *)cursor.next))
  455. {
  456. if (my_atomic_casptr((void **)cursor.prev,
  457. (void **)&cursor.curr, cursor.next))
  458. _lf_alloc_free(pins, cursor.curr);
  459. else
  460. lockfind(head, node, &cursor, pins);
  461. }
  462. else
  463. {
  464. res= REPEAT_ONCE_MORE;
  465. if (cursor.upgrade_from)
  466. cursor.upgrade_from->flags|= IGNORE_ME;
  467. }
  468. } while (res == REPEAT_ONCE_MORE);
  469. _lf_unpin(pins, 0);
  470. _lf_unpin(pins, 1);
  471. _lf_unpin(pins, 2);
  472. _lf_unpin(pins, 3);
  473. return res;
  474. }
  475. void lockman_init(LOCKMAN *lm, loid_to_lo_func *func, uint timeout)
  476. {
  477. lf_alloc_init(&lm->alloc, sizeof(LOCK), offsetof(LOCK, lonext));
  478. lf_dynarray_init(&lm->array, sizeof(LOCK **));
  479. lm->size= 1;
  480. lm->count= 0;
  481. lm->loid_to_lo= func;
  482. lm->lock_timeout= timeout;
  483. }
  484. void lockman_destroy(LOCKMAN *lm)
  485. {
  486. LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
  487. while (el)
  488. {
  489. intptr next= el->link;
  490. if (el->hashnr & 1)
  491. lf_alloc_direct_free(&lm->alloc, el);
  492. else
  493. my_free((void *)el, MYF(0));
  494. el= (LOCK *)next;
  495. }
  496. lf_alloc_destroy(&lm->alloc);
  497. lf_dynarray_destroy(&lm->array);
  498. }
  499. /* TODO: optimize it */
  500. #define MAX_LOAD 1
  501. static void initialize_bucket(LOCKMAN *lm, LOCK * volatile *node,
  502. uint bucket, LF_PINS *pins)
  503. {
  504. int res;
  505. uint parent= my_clear_highest_bit(bucket);
  506. LOCK *dummy= (LOCK *)my_malloc(sizeof(LOCK), MYF(MY_WME));
  507. LOCK **tmp= 0, *cur;
  508. LOCK * volatile *el= _lf_dynarray_lvalue(&lm->array, parent);
  509. if (*el == NULL && bucket)
  510. initialize_bucket(lm, el, parent, pins);
  511. dummy->hashnr= my_reverse_bits(bucket);
  512. dummy->loid= 0;
  513. dummy->lock= X; /* doesn't matter, in fact */
  514. dummy->resource= 0;
  515. dummy->flags= 0;
  516. res= lockinsert(el, dummy, pins, &cur);
  517. DBUG_ASSERT(res & (ALREADY_HAVE_THE_LOCK | RESOURCE_WAS_UNLOCKED));
  518. if (res & ALREADY_HAVE_THE_LOCK)
  519. {
  520. my_free((void *)dummy, MYF(0));
  521. dummy= cur;
  522. }
  523. my_atomic_casptr((void **)node, (void **)&tmp, dummy);
  524. }
  525. static inline uint calc_hash(uint64 resource)
  526. {
  527. const uchar *pos= (uchar *)&resource;
  528. ulong nr1= 1, nr2= 4, i;
  529. for (i= 0; i < sizeof(resource) ; i++, pos++)
  530. {
  531. nr1^= (ulong) ((((uint) nr1 & 63)+nr2) * ((uint)*pos)) + (nr1 << 8);
  532. nr2+= 3;
  533. }
  534. return nr1 & INT_MAX32;
  535. }
  536. /*
  537. RETURN
  538. see enum lockman_getlock_result
  539. NOTE
  540. uses pins[0..3], they're removed on return
  541. */
  542. enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
  543. uint64 resource,
  544. enum lock_type lock)
  545. {
  546. int res;
  547. uint csize, bucket, hashnr;
  548. LOCK *node, * volatile *el, *blocker;
  549. LF_PINS *pins= lo->pins;
  550. enum lock_type old_lock;
  551. DBUG_ASSERT(lo->loid);
  552. lf_rwlock_by_pins(pins);
  553. node= (LOCK *)_lf_alloc_new(pins);
  554. node->flags= 0;
  555. node->lock= lock;
  556. node->loid= lo->loid;
  557. node->resource= resource;
  558. hashnr= calc_hash(resource);
  559. bucket= hashnr % lm->size;
  560. el= _lf_dynarray_lvalue(&lm->array, bucket);
  561. if (*el == NULL)
  562. initialize_bucket(lm, el, bucket, pins);
  563. node->hashnr= my_reverse_bits(hashnr) | 1;
  564. res= lockinsert(el, node, pins, &blocker);
  565. if (res & ALREADY_HAVE)
  566. {
  567. int r;
  568. old_lock= blocker->lock;
  569. _lf_alloc_free(pins, node);
  570. lf_rwunlock_by_pins(pins);
  571. r= getlock_result[old_lock][lock];
  572. DBUG_ASSERT(r);
  573. return r;
  574. }
  575. /* a new value was added to the hash */
  576. csize= lm->size;
  577. if ((my_atomic_add32(&lm->count, 1)+1.0) / csize > MAX_LOAD)
  578. my_atomic_cas32(&lm->size, &csize, csize*2);
  579. node->lonext= lo->all_locks;
  580. lo->all_locks= node;
  581. for ( ; res & NEED_TO_WAIT; res= lockpeek(el, node, pins, &blocker))
  582. {
  583. LOCK_OWNER *wait_for_lo;
  584. ulonglong deadline;
  585. struct timespec timeout;
  586. _lf_assert_pin(pins, 3); /* blocker must be pinned here */
  587. wait_for_lo= lm->loid_to_lo(blocker->loid);
  588. /*
  589. now, this is tricky. blocker is not necessarily a LOCK
  590. we're waiting for. If it's compatible with what we want,
  591. then we're waiting for a lock that blocker is waiting for
  592. (see two places where blocker is set in lockfind)
  593. In the latter case, let's "dereference" it
  594. */
  595. if (lock_compatibility_matrix[blocker->lock][lock])
  596. {
  597. blocker= wait_for_lo->all_locks;
  598. _lf_pin(pins, 3, blocker);
  599. if (blocker != wait_for_lo->all_locks)
  600. continue;
  601. wait_for_lo= wait_for_lo->waiting_for;
  602. }
  603. /*
  604. note that the blocker transaction may have ended by now,
  605. its LOCK_OWNER and short id were reused, so 'wait_for_lo' may point
  606. to an unrelated - albeit valid - LOCK_OWNER
  607. */
  608. if (!wait_for_lo)
  609. continue;
  610. lo->waiting_for= wait_for_lo;
  611. lf_rwunlock_by_pins(pins);
  612. /*
  613. We lock a mutex - it may belong to a wrong LOCK_OWNER, but it must
  614. belong to _some_ LOCK_OWNER. It means, we can never free() a LOCK_OWNER,
  615. if there're other active LOCK_OWNERs.
  616. */
  617. /* QQ: race condition here */
  618. pthread_mutex_lock(wait_for_lo->mutex);
  619. if (DELETED(blocker->link))
  620. {
  621. /*
  622. blocker transaction was ended, or a savepoint that owned
  623. the lock was rolled back. Either way - the lock was removed
  624. */
  625. pthread_mutex_unlock(wait_for_lo->mutex);
  626. lf_rwlock_by_pins(pins);
  627. continue;
  628. }
  629. /* yuck. waiting */
  630. deadline= my_getsystime() + lm->lock_timeout * 10000;
  631. timeout.tv_sec= deadline/10000000;
  632. timeout.tv_nsec= (deadline % 10000000) * 100;
  633. do
  634. {
  635. pthread_cond_timedwait(wait_for_lo->cond, wait_for_lo->mutex, &timeout);
  636. } while (!DELETED(blocker->link) && my_getsystime() < deadline);
  637. pthread_mutex_unlock(wait_for_lo->mutex);
  638. lf_rwlock_by_pins(pins);
  639. if (!DELETED(blocker->link))
  640. {
  641. /*
  642. timeout.
  643. note that we _don't_ release the lock request here.
  644. Instead we're relying on the caller to abort the transaction,
  645. and release all locks at once - see lockman_release_locks()
  646. */
  647. _lf_unpin(pins, 3);
  648. lf_rwunlock_by_pins(pins);
  649. return DIDNT_GET_THE_LOCK;
  650. }
  651. }
  652. lo->waiting_for= 0;
  653. _lf_assert_unpin(pins, 3); /* unpin should not be needed */
  654. lf_rwunlock_by_pins(pins);
  655. return getlock_result[lock][lock];
  656. }
  657. /*
  658. RETURN
  659. 0 - deleted
  660. 1 - didn't (not found)
  661. NOTE
  662. see lockdelete() for pin usage notes
  663. */
  664. int lockman_release_locks(LOCKMAN *lm, LOCK_OWNER *lo)
  665. {
  666. LOCK * volatile *el, *node, *next;
  667. uint bucket;
  668. LF_PINS *pins= lo->pins;
  669. pthread_mutex_lock(lo->mutex);
  670. lf_rwlock_by_pins(pins);
  671. for (node= lo->all_locks; node; node= next)
  672. {
  673. next= node->lonext;
  674. bucket= calc_hash(node->resource) % lm->size;
  675. el= _lf_dynarray_lvalue(&lm->array, bucket);
  676. if (*el == NULL)
  677. initialize_bucket(lm, el, bucket, pins);
  678. lockdelete(el, node, pins);
  679. my_atomic_add32(&lm->count, -1);
  680. }
  681. lf_rwunlock_by_pins(pins);
  682. lo->all_locks= 0;
  683. /* now signal all waiters */
  684. pthread_cond_broadcast(lo->cond);
  685. pthread_mutex_unlock(lo->mutex);
  686. return 0;
  687. }
  688. #ifdef MY_LF_EXTRA_DEBUG
  689. static const char *lock2str[]=
  690. { "N", "S", "X", "IS", "IX", "SIX", "LS", "LX", "SLX", "LSIX" };
  691. /*
  692. NOTE
  693. the function below is NOT thread-safe !!!
  694. */
  695. void print_lockhash(LOCKMAN *lm)
  696. {
  697. LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
  698. printf("hash: size %u count %u\n", lm->size, lm->count);
  699. while (el)
  700. {
  701. intptr next= el->link;
  702. if (el->hashnr & 1)
  703. {
  704. printf("0x%08lx { resource %lu, loid %u, lock %s",
  705. (long) el->hashnr, (ulong) el->resource, el->loid,
  706. lock2str[el->lock]);
  707. if (el->flags & IGNORE_ME) printf(" IGNORE_ME");
  708. if (el->flags & UPGRADED) printf(" UPGRADED");
  709. if (el->flags & ACTIVE) printf(" ACTIVE");
  710. if (DELETED(next)) printf(" ***DELETED***");
  711. printf("}\n");
  712. }
  713. else
  714. {
  715. /*printf("0x%08x { dummy }\n", el->hashnr);*/
  716. DBUG_ASSERT(el->resource == 0 && el->loid == 0 && el->lock == X);
  717. }
  718. el= PTR(next);
  719. }
  720. }
  721. #endif