List:Commits« Previous MessageNext Message »
From:Igor Babaev Date:December 13 2008 12:03pm
Subject:bzr commit into mysql-6.0-bka-preview branch (igor:2678)
View as plain text  
#At file:///home/igor/dev-bzr/mysql-6.0-bka-preview-merge/

 2678 Igor Babaev	2008-12-13 [merge]
      Manual merge
removed:
  mysql-test/r/innodb_bug34053.result
  mysql-test/r/rpl_slave_exec_mode_basic.result.moved
  mysql-test/t/innodb_bug34053.test
  mysql-test/t/rpl_slave_exec_mode_basic.test.moved
added:
  mysql-test/extra/rpl_tests/rpl_row_basic_no_pk.test
  mysql-test/suite/backup_engines/r/backup_partition.result
  mysql-test/suite/backup_engines/t/backup_partition.test
  mysql-test/suite/ndb/r/ndb_dbug_lock.result
  mysql-test/suite/ndb/r/ndb_discover_db.result
  mysql-test/suite/ndb/r/ndb_discover_db2.result
  mysql-test/suite/ndb/t/ndb_dbug_lock.test
  mysql-test/suite/ndb/t/ndb_discover_db.test
  mysql-test/suite/ndb/t/ndb_discover_db2-master.opt
  mysql-test/suite/ndb/t/ndb_discover_db2.test
  mysql-test/suite/ndb_binlog/t/ndb_binlog_restore-master.opt
  sql/ha_ndbcluster_lock_ext.h
  storage/ndb/include/util/NdbTap.hpp
  storage/ndb/test/run-test/atrt-backtrace.sh
renamed:
  mysql-test/r/rpl_slave_allow_batching_basic.result.moved =>
mysql-test/r/slave_allow_batching_basic.result
  mysql-test/r/rpl_slave_compressed_protocol_basic.result.moved =>
mysql-test/r/slave_compressed_protocol_basic.result
  mysql-test/r/rpl_slave_net_timeout_basic.result.moved =>
mysql-test/r/slave_net_timeout_basic.result
  mysql-test/suite/funcs_1/r/is_collation_charset_applic.result =>
mysql-test/suite/funcs_1/r/is_collation_character_set_applicability.result
  mysql-test/suite/funcs_1/t/is_collation_charset_applic.test =>
mysql-test/suite/funcs_1/t/is_collation_character_set_applicability.test
  mysql-test/suite/ndb_team/r/ndb_dd_restore_compat.result =>
mysql-test/suite/ndb/r/ndb_dd_restore_compat.result
  mysql-test/suite/ndb_team/t/ndb_dd_restore_compat.test =>
mysql-test/suite/ndb/t/ndb_dd_restore_compat.test
  mysql-test/suite/rpl_ndb_big/r/rpl_ndb_add_column.result =>
mysql-test/suite/rpl_ndb/r/rpl_ndb_add_column.result
  mysql-test/suite/rpl_ndb_big/t/rpl_ndb_add_column.test =>
mysql-test/suite/rpl_ndb/t/rpl_ndb_add_column.test
  mysql-test/t/rpl_slave_allow_batching_basic.test.moved =>
mysql-test/t/slave_allow_batching_basic.test
  mysql-test/t/rpl_slave_compressed_protocol_basic.test.moved =>
mysql-test/t/slave_compressed_protocol_basic.test
  mysql-test/t/rpl_slave_net_timeout_basic.test.moved =>
mysql-test/t/slave_net_timeout_basic.test
modified:
  .bzrignore
  BUILD/SETUP.sh
  Makefile.am
  client/mysql.cc
  client/mysqladmin.cc
  client/mysqldump.c
  client/mysqlimport.c
  client/mysqlshow.c
  client/mysqlslap.c
  client/mysqltest.c
  configure.in
  extra/CMakeLists.txt
  extra/Makefile.am
  include/config-win.h
  include/hash.h
  include/thr_lock.h
  mysql-test/extra/rpl_tests/rpl_row_basic.test
  mysql-test/include/have_blackhole.inc
  mysql-test/lib/mtr_cases.pl
  mysql-test/lib/mtr_report.pl
  mysql-test/mysql-test-run.pl
  mysql-test/r/sp-error.result
  mysql-test/suite/backup/r/backup.result
  mysql-test/suite/backup/r/backup_backupdir.result
  mysql-test/suite/backup/r/backup_default.result
  mysql-test/suite/backup/r/backup_errors.result
  mysql-test/suite/backup/r/backup_views.result
  mysql-test/suite/backup/t/backup.test
  mysql-test/suite/backup/t/backup_backupdir.test
  mysql-test/suite/backup/t/backup_default.test
  mysql-test/suite/backup/t/backup_errors.test
  mysql-test/suite/backup/t/backup_myisam1.test
  mysql-test/suite/backup/t/backup_views.test
  mysql-test/suite/backup/t/disabled.def
  mysql-test/suite/funcs_1/r/ndb_trig_1011ext.result
  mysql-test/suite/funcs_1/t/disabled.def
  mysql-test/suite/ndb/r/ndb_alter_table_online.result
  mysql-test/suite/ndb/r/ndb_alter_table_online2.result
  mysql-test/suite/ndb/r/ndb_basic.result
  mysql-test/suite/ndb/r/ndb_cache.result
  mysql-test/suite/ndb/r/ndb_dd_ddl.result
  mysql-test/suite/ndb/r/ndb_insert.result
  mysql-test/suite/ndb/r/ndb_single_user.result
  mysql-test/suite/ndb/t/ndb_alter_table_online.test
  mysql-test/suite/ndb/t/ndb_alter_table_online2.test
  mysql-test/suite/ndb/t/ndb_basic.test
  mysql-test/suite/ndb/t/ndb_cache.test
  mysql-test/suite/ndb/t/ndb_cache2.test
  mysql-test/suite/ndb/t/ndb_dd_ddl.test
  mysql-test/suite/ndb/t/ndb_dd_dump.test
  mysql-test/suite/ndb/t/ndb_insert.test
  mysql-test/suite/ndb/t/ndb_single_user.test
  mysql-test/suite/ndb_team/r/ndb_autodiscover3.result
  mysql-test/suite/ndb_team/t/ndb_autodiscover3.test
  mysql-test/suite/parts/r/partition_engine_ndb.result
  mysql-test/suite/rpl/r/rpl_heartbeat.result
  mysql-test/suite/rpl/r/rpl_locktrans_innodb.result
  mysql-test/suite/rpl/t/rpl_row_basic_2myisam.test
  mysql-test/suite/rpl/t/rpl_row_basic_3innodb.test
  mysql-test/suite/rpl_ndb/t/disabled.def
  mysql-test/suite/rpl_ndb_big/r/rpl_ndb_apply_status.result
  mysql-test/suite/rpl_ndb_big/r/rpl_row_basic_7ndb.result
  mysql-test/suite/rpl_ndb_big/t/disabled.def
  mysql-test/suite/rpl_ndb_big/t/rpl_ndb_apply_status.test
  mysql-test/suite/rpl_ndb_big/t/rpl_row_basic_7ndb.test
  mysql-test/t/sp-error.test
  mysql-test/t/subselect3.test
  mysys/Makefile.am
  mysys/hash.c
  sql/Makefile.am
  sql/backup/backup_info.cc
  sql/backup/backup_info.h
  sql/backup/backup_kernel.h
  sql/backup/data_backup.cc
  sql/backup/image_info.cc
  sql/backup/image_info.h
  sql/backup/kernel.cc
  sql/backup/logger.cc
  sql/backup/logger.h
  sql/backup/restore_info.h
  sql/backup/stream.cc
  sql/backup/stream.h
  sql/event_db_repository.cc
  sql/event_parse_data.cc
  sql/event_parse_data.h
  sql/field.cc
  sql/field.h
  sql/gen_lex_hash.cc
  sql/ha_ndbcluster.cc
  sql/ha_ndbcluster.h
  sql/ha_ndbcluster_binlog.cc
  sql/ha_ndbcluster_binlog.h
  sql/ha_ndbcluster_connection.cc
  sql/ha_ndbcluster_connection.h
  sql/ha_partition.cc
  sql/ha_partition.h
  sql/handler.cc
  sql/handler.h
  sql/item.cc
  sql/item.h
  sql/item_func.cc
  sql/item_func.h
  sql/lock.cc
  sql/log.cc
  sql/log_event.cc
  sql/mysql_priv.h
  sql/mysqld.cc
  sql/opt_range.cc
  sql/partition_info.h
  sql/set_var.cc
  sql/share/errmsg.txt
  sql/si_logs.h
  sql/sp_head.cc
  sql/sql_base.cc
  sql/sql_cache.cc
  sql/sql_class.cc
  sql/sql_class.h
  sql/sql_db.cc
  sql/sql_delete.cc
  sql/sql_insert.cc
  sql/sql_lex.cc
  sql/sql_lex.h
  sql/sql_parse.cc
  sql/sql_partition.cc
  sql/sql_rename.cc
  sql/sql_select.cc
  sql/sql_show.cc
  sql/sql_show.h
  sql/sql_table.cc
  sql/sql_union.cc
  sql/sql_update.cc
  sql/sql_yacc.yy
  sql/table.cc
  sql/table.h
  storage/archive/archive_reader.c
  storage/blackhole/ha_blackhole.cc
  storage/blackhole/ha_blackhole.h
  storage/myisam/myisampack.c
  storage/ndb/docs/doxygen/postdoxy.pl
  storage/ndb/include/debugger/SignalLoggerManager.hpp
  storage/ndb/include/kernel/NodeState.hpp
  storage/ndb/include/kernel/signaldata/SumaImpl.hpp
  storage/ndb/include/logger/LogHandler.hpp
  storage/ndb/include/logger/Logger.hpp
  storage/ndb/include/mgmapi/mgmapi.h
  storage/ndb/include/mgmapi/mgmapi_debug.h
  storage/ndb/include/ndb_constants.h
  storage/ndb/include/ndb_version.h.in
  storage/ndb/include/ndbapi/Ndb.hpp
  storage/ndb/include/ndbapi/NdbBlob.hpp
  storage/ndb/include/ndbapi/NdbOperation.hpp
  storage/ndb/include/ndbapi/NdbScanOperation.hpp
  storage/ndb/include/util/BaseString.hpp
  storage/ndb/include/util/InputStream.hpp
  storage/ndb/include/util/NdbOut.hpp
  storage/ndb/include/util/OutputStream.hpp
  storage/ndb/include/util/basestring_vsnprintf.h
  storage/ndb/include/util/ndb_opts.h
  storage/ndb/include/util/socket_io.h
  storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile
  storage/ndb/ndbapi-examples/mgmapi_logevent2/Makefile
  storage/ndb/ndbapi-examples/ndbapi_async/Makefile
  storage/ndb/ndbapi-examples/ndbapi_async1/Makefile
  storage/ndb/ndbapi-examples/ndbapi_blob/Makefile
  storage/ndb/ndbapi-examples/ndbapi_blob_ndbrecord/Makefile
  storage/ndb/ndbapi-examples/ndbapi_event/Makefile
  storage/ndb/ndbapi-examples/ndbapi_recattr_vs_record/Makefile
  storage/ndb/ndbapi-examples/ndbapi_retries/Makefile
  storage/ndb/ndbapi-examples/ndbapi_s_i_ndbrecord/Makefile
  storage/ndb/ndbapi-examples/ndbapi_scan/Makefile
  storage/ndb/ndbapi-examples/ndbapi_simple/Makefile
  storage/ndb/ndbapi-examples/ndbapi_simple_dual/Makefile
  storage/ndb/ndbapi-examples/ndbapi_simple_index/Makefile
  storage/ndb/src/common/debugger/EventLogger.cpp
  storage/ndb/src/common/debugger/signaldata/SignalNames.cpp
  storage/ndb/src/common/logger/LogHandler.cpp
  storage/ndb/src/common/logger/Logger.cpp
  storage/ndb/src/common/portlib/NdbTick.c
  storage/ndb/src/common/transporter/TCP_Transporter.cpp
  storage/ndb/src/common/transporter/TransporterRegistry.cpp
  storage/ndb/src/common/util/BaseString.cpp
  storage/ndb/src/common/util/Makefile.am
  storage/ndb/src/common/util/ndb_init.cpp
  storage/ndb/src/common/util/socket_io.cpp
  storage/ndb/src/cw/cpcd/APIService.cpp
  storage/ndb/src/cw/cpcd/Process.cpp
  storage/ndb/src/cw/cpcd/main.cpp
  storage/ndb/src/kernel/blocks/ERROR_codes.txt
  storage/ndb/src/kernel/blocks/backup/Backup.cpp
  storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp
  storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp
  storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
  storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
  storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp
  storage/ndb/src/kernel/blocks/dblqh/DblqhInit.cpp
  storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp
  storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp
  storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp
  storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp
  storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp
  storage/ndb/src/kernel/blocks/dbtup/DbtupIndex.cpp
  storage/ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp
  storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.cpp
  storage/ndb/src/kernel/blocks/ndbfs/Ndbfs.cpp
  storage/ndb/src/kernel/blocks/qmgr/Qmgr.hpp
  storage/ndb/src/kernel/blocks/qmgr/QmgrInit.cpp
  storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp
  storage/ndb/src/kernel/blocks/restore.cpp
  storage/ndb/src/kernel/blocks/suma/Suma.cpp
  storage/ndb/src/kernel/blocks/suma/Suma.hpp
  storage/ndb/src/kernel/blocks/trix/Trix.cpp
  storage/ndb/src/kernel/blocks/trix/Trix.hpp
  storage/ndb/src/kernel/error/ErrorReporter.cpp
  storage/ndb/src/kernel/vm/LongSignal.hpp
  storage/ndb/src/kernel/vm/SimulatedBlock.hpp
  storage/ndb/src/kernel/vm/TransporterCallback.cpp
  storage/ndb/src/kernel/vm/WatchDog.cpp
  storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp
  storage/ndb/src/mgmapi/LocalConfig.cpp
  storage/ndb/src/mgmapi/mgmapi.cpp
  storage/ndb/src/mgmclient/CommandInterpreter.cpp
  storage/ndb/src/mgmsrv/ConfigInfo.cpp
  storage/ndb/src/mgmsrv/MgmtSrvr.cpp
  storage/ndb/src/mgmsrv/Services.cpp
  storage/ndb/src/ndbapi/Ndb.cpp
  storage/ndb/src/ndbapi/NdbBlob.cpp
  storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp
  storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp
  storage/ndb/src/ndbapi/NdbInterpretedCode.cpp
  storage/ndb/src/ndbapi/NdbOperation.cpp
  storage/ndb/src/ndbapi/NdbOperationDefine.cpp
  storage/ndb/src/ndbapi/NdbOperationExec.cpp
  storage/ndb/src/ndbapi/NdbOperationInt.cpp
  storage/ndb/src/ndbapi/NdbOperationSearch.cpp
  storage/ndb/src/ndbapi/NdbRecAttr.cpp
  storage/ndb/src/ndbapi/NdbScanOperation.cpp
  storage/ndb/src/ndbapi/NdbTransaction.cpp
  storage/ndb/src/ndbapi/Ndbif.cpp
  storage/ndb/src/ndbapi/ObjectMap.cpp
  storage/ndb/src/ndbapi/ObjectMap.hpp
  storage/ndb/src/ndbapi/TransporterFacade.cpp
  storage/ndb/src/ndbapi/ndb_cluster_connection.cpp
  storage/ndb/src/ndbapi/ndberror.c
  storage/ndb/test/include/HugoAsynchTransactions.hpp
  storage/ndb/test/include/HugoOperations.hpp
  storage/ndb/test/include/HugoTransactions.hpp
  storage/ndb/test/include/NDBT_Test.hpp
  storage/ndb/test/include/NdbRestarter.hpp
  storage/ndb/test/ndbapi/Makefile.am
  storage/ndb/test/ndbapi/bench/mainAsyncGenerator.cpp
  storage/ndb/test/ndbapi/bench/ndb_async2.cpp
  storage/ndb/test/ndbapi/bench/testData.h
  storage/ndb/test/ndbapi/flexAsynch.cpp
  storage/ndb/test/ndbapi/msa.cpp
  storage/ndb/test/ndbapi/testIndex.cpp
  storage/ndb/test/ndbapi/testNdbApi.cpp
  storage/ndb/test/ndbapi/testNodeRestart.cpp
  storage/ndb/test/ndbapi/testOperations.cpp
  storage/ndb/test/ndbapi/testScanFilter.cpp
  storage/ndb/test/ndbapi/testSystemRestart.cpp
  storage/ndb/test/ndbapi/testTransactions.cpp
  storage/ndb/test/ndbapi/test_event.cpp
  storage/ndb/test/run-test/Makefile.am
  storage/ndb/test/run-test/atrt-analyze-result.sh
  storage/ndb/test/run-test/atrt.hpp
  storage/ndb/test/run-test/autotest-boot.sh
  storage/ndb/test/run-test/autotest-run.sh
  storage/ndb/test/run-test/command.cpp
  storage/ndb/test/run-test/daily-basic-tests.txt
  storage/ndb/test/run-test/daily-devel-tests.txt
  storage/ndb/test/run-test/db.cpp
  storage/ndb/test/run-test/files.cpp
  storage/ndb/test/run-test/main.cpp
  storage/ndb/test/run-test/setup.cpp
  storage/ndb/test/run-test/test-tests.txt
  storage/ndb/test/src/CpcClient.cpp
  storage/ndb/test/src/DbUtil.cpp
  storage/ndb/test/src/HugoAsynchTransactions.cpp
  storage/ndb/test/src/HugoOperations.cpp
  storage/ndb/test/src/HugoTransactions.cpp
  storage/ndb/test/src/NDBT_Tables.cpp
  storage/ndb/test/src/NDBT_Test.cpp
  storage/ndb/test/src/NdbBackup.cpp
  storage/ndb/test/src/NdbRestarter.cpp
  storage/ndb/test/tools/connect.cpp
  storage/ndb/test/tools/hugoPkRead.cpp
  storage/ndb/test/tools/rep_latency.cpp
  storage/ndb/tools/desc.cpp
  strings/conf_to_src.c
  support-files/build-tags
  support-files/compiler_warnings.supp
  support-files/mysql.spec.sh
  mysql-test/r/slave_allow_batching_basic.result
  mysql-test/t/slave_allow_batching_basic.test

=== modified file '.bzrignore'
--- a/.bzrignore	2008-12-11 19:02:44 +0000
+++ b/.bzrignore	2008-12-13 11:02:16 +0000
@@ -764,6 +764,7 @@ mysql-test/install_test_db
 mysql-test/lib/init_db.sql
 mysql-test/linux_sys_vars.inc
 mysql-test/load_sysvars.inc
+mysql-test/maria_recovery.trace
 mysql-test/mtr
 mysql-test/mysql-test-run
 mysql-test/mysql-test-run-shell
@@ -1679,6 +1680,86 @@ storage/ndb/src/common/transporter/libtr
 storage/ndb/src/common/util/libgeneral.dsp
 storage/ndb/src/common/util/ndb_show_compat
 storage/ndb/src/common/util/testBitmask.cpp
+storage/ndb/src/libndb.ver
+storage/ndb/src/mgmclient/ndb_mgm
+storage/ndb/src/mgmclient/test_cpcd/*.d
+storage/ndb/src/mgmsrv/ndb_mgmd
+storage/ndb/src/ndbapi/ndberror_check
+storage/ndb/test/ndbapi/DbAsyncGenerator
+storage/ndb/test/ndbapi/DbCreate
+storage/ndb/test/ndbapi/bank/bankCreator
+storage/ndb/test/ndbapi/bank/bankMakeGL
+storage/ndb/test/ndbapi/bank/bankSumAccounts
+storage/ndb/test/ndbapi/bank/bankTimer
+storage/ndb/test/ndbapi/bank/bankTransactionMaker
+storage/ndb/test/ndbapi/bank/bankValidateAllGLs
+storage/ndb/test/ndbapi/bank/testBank
+storage/ndb/test/ndbapi/create_all_tabs
+storage/ndb/test/ndbapi/create_tab
+storage/ndb/test/ndbapi/drop_all_tabs
+storage/ndb/test/ndbapi/flexAsynch
+storage/ndb/test/ndbapi/flexBench
+storage/ndb/test/ndbapi/flexHammer
+storage/ndb/test/ndbapi/flexTT
+storage/ndb/test/ndbapi/ndbapi_slow_select
+storage/ndb/test/ndbapi/testBackup
+storage/ndb/test/ndbapi/testBasic
+storage/ndb/test/ndbapi/testBasicAsynch
+storage/ndb/test/ndbapi/testBitfield
+storage/ndb/test/ndbapi/testBlobs
+storage/ndb/test/ndbapi/testDataBuffers
+storage/ndb/test/ndbapi/testDeadlock
+storage/ndb/test/ndbapi/testDict
+storage/ndb/test/ndbapi/testIndex
+storage/ndb/test/ndbapi/testIndexStat
+storage/ndb/test/ndbapi/testInterpreter
+storage/ndb/test/ndbapi/testLcp
+storage/ndb/test/ndbapi/testMgm
+storage/ndb/test/ndbapi/testNdbApi
+storage/ndb/test/ndbapi/testNodeRestart
+storage/ndb/test/ndbapi/testOIBasic
+storage/ndb/test/ndbapi/testOperations
+storage/ndb/test/ndbapi/testPartitioning
+storage/ndb/test/ndbapi/testReadPerf
+storage/ndb/test/ndbapi/testRestartGci
+storage/ndb/test/ndbapi/testSRBank
+storage/ndb/test/ndbapi/testScan
+storage/ndb/test/ndbapi/testScanInterpreter
+storage/ndb/test/ndbapi/testScanPerf
+storage/ndb/test/ndbapi/testSystemRestart
+storage/ndb/test/ndbapi/testTimeout
+storage/ndb/test/ndbapi/testTransactions
+storage/ndb/test/ndbapi/test_event
+storage/ndb/test/ndbapi/test_event_merge
+storage/ndb/test/run-test/atrt
+storage/ndb/test/tools/copy_tab
+storage/ndb/test/tools/create_index
+storage/ndb/test/tools/hugoCalculator
+storage/ndb/test/tools/hugoFill
+storage/ndb/test/tools/hugoLoad
+storage/ndb/test/tools/hugoLockRecords
+storage/ndb/test/tools/hugoPkDelete
+storage/ndb/test/tools/hugoPkRead
+storage/ndb/test/tools/hugoPkReadRecord
+storage/ndb/test/tools/hugoPkUpdate
+storage/ndb/test/tools/hugoScanRead
+storage/ndb/test/tools/hugoScanUpdate
+storage/ndb/test/tools/listen_event
+storage/ndb/test/tools/ndb_cpcc
+storage/ndb/test/tools/rep_latency
+storage/ndb/test/tools/restart
+storage/ndb/test/tools/verify_index
+storage/ndb/tools/ndb_config
+storage/ndb/tools/ndb_delete_all
+storage/ndb/tools/ndb_desc
+storage/ndb/tools/ndb_drop_index
+storage/ndb/tools/ndb_drop_table
+storage/ndb/tools/ndb_restore
+storage/ndb/tools/ndb_select_all
+storage/ndb/tools/ndb_select_count
+storage/ndb/tools/ndb_show_tables
+storage/ndb/tools/ndb_test_platform
+storage/ndb/tools/ndb_waiter
 storage/ndb/src/cw/cpcd/ndb_cpcd
 storage/ndb/src/dummy.cpp
 storage/ndb/src/kernel/blocks/backup/ndb_print_backup_file
@@ -1906,12 +1987,7 @@ ylwrap
 zlib/*.ds?
 zlib/*.vcproj
 extra/libevent/event-config.h
-mysql-test/bug36522-64.tar
-mysql-test/bug36522.tar
-mysql-test/t.log
-mysql-test/tps.log
 libmysqld/event_parse_data.cc
-storage/ndb/src/common/util/ndb_show_compat
 libmysqld/ddl_blocker.cc
 libmysqld/mdl.cc
 mysql-test/bug36522-64.tar

=== modified file 'BUILD/SETUP.sh'
--- a/BUILD/SETUP.sh	2008-12-11 18:04:55 +0000
+++ b/BUILD/SETUP.sh	2008-12-13 11:02:16 +0000
@@ -92,13 +92,17 @@ if [ "x$warning_mode" != "xpedantic" ]; 
 # Both C and C++ warnings
   warnings="-Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W"
   warnings="$warnings -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare"
-  warnings="$warnings -Wwrite-strings -Wunused-function -Wunused-label -Wunused-value
-Wunused-variable"
+  warnings="$warnings -Wwrite-strings -Wunused-function -Wunused-label"
+  warnings="$warnings -Wunused-value -Wunused-variable"
+
+  # Make "printf like format specifier warnings" into error
+  #warnings="$warnings -Werror=format"
 
 # For more warnings, uncomment the following line
 # warnings="$global_warnings -Wshadow"
 
 # C warnings
-  c_warnings="$warnings -Wunused-parameter"
+  c_warnings="$warnings -Wunused-parameter -Wno-format-zero-length"
 # C++ warnings
   cxx_warnings="$warnings"
 # cxx_warnings="$cxx_warnings -Woverloaded-virtual -Wsign-promo"

=== modified file 'Makefile.am'
--- a/Makefile.am	2008-12-08 21:15:06 +0000
+++ b/Makefile.am	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2000-2006 MySQL AB
+# Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -170,6 +170,8 @@ test-bt:
 	    @PERL@ ./mysql-test-run.pl --force --comment=partitions --suite=parts
 	-cd mysql-test ; MTR_BUILD_THREAD=auto \
 	    @PERL@ ./mysql-test-run.pl --force --comment=stress --suite=stress
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl --force --comment=jp --suite=jp
 	-if [ -d mysql-test/suite/nist ] ; then \
 	  cd mysql-test ; MTR_BUILD_THREAD=auto \
 	      @PERL@ ./mysql-test-run.pl --comment=nist --force --suite=nist ; \
@@ -187,15 +189,28 @@ test-bt:
 	  echo "no program found for 'embedded' tests - skipped testing" ; \
 	fi
 
-# Re-enable the "jp" suite when bug#28563 is fixed
-#	-cd mysql-test ; MTR_BUILD_THREAD=auto \
-#	    @PERL@ ./mysql-test-run.pl --force --comment=jp --suite=jp
+test-bt-fast:
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl  --comment=ps    --force --timer \
+	        --skip-ndbcluster --ps-protocol --report-features
+	-if [ -e bin/ndbd -o -e storage/ndb/src/kernel/ndbd ] ; then \
+	  cd mysql-test ; \
+	    MTR_BUILD_THREAD=auto \
+	      @PERL@ ./mysql-test-run.pl --comment=ndb --force --timer \
+	          --with-ndbcluster-only ; \
+	else \
+	  echo "no program found for 'ndbcluster' tests - skipped testing" ; \
+	fi
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl --force --comment=stress --suite=stress
 
 test-bt-debug:
 	-cd mysql-test ; MTR_BUILD_THREAD=auto \
 	    @PERL@ ./mysql-test-run.pl --comment=debug  --force --timer \
 	        --skip-ndbcluster --skip-rpl --report-features
 
+test-bt-debug-fast:
+
 # Keep these for a while
 test-pl:	test
 test-full-pl:	test-full

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2008-12-08 21:15:06 +0000
+++ b/client/mysql.cc	2008-12-13 11:02:16 +0000
@@ -1566,7 +1566,7 @@ static void usage(int version)
   if (version)
     return;
   printf("\
-Copyright (C) 2000-2008 MySQL AB\n\
+Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.\n\
 This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
 and you are welcome to modify and redistribute it under the GPL license\n");
   printf("Usage: %s [OPTIONS] [database]\n", my_progname);

=== modified file 'client/mysqladmin.cc'
--- a/client/mysqladmin.cc	2008-05-29 15:44:11 +0000
+++ b/client/mysqladmin.cc	2008-12-09 18:59:54 +0000
@@ -634,7 +634,7 @@ static int execute_commands(MYSQL *mysql
     case ADMIN_VER:
       new_line=1;
       print_version();
-      puts("Copyright (C) 2000-2006 MySQL AB");
+      puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
       puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand
you are welcome to modify and redistribute it under the GPL license\n");
       printf("Server version\t\t%s\n", mysql_get_server_info(mysql));
       printf("Protocol version\t%d\n", mysql_get_proto_info(mysql));
@@ -1023,7 +1023,7 @@ static void print_version(void)
 static void usage(void)
 {
   print_version();
-  puts("Copyright (C) 2000-2006 MySQL AB");
+  puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you
are welcome to modify and redistribute it under the GPL license\n");
   puts("Administration program for the mysqld daemon.");
   printf("Usage: %s [OPTIONS] command command....\n", my_progname);

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2008-12-08 21:15:06 +0000
+++ b/client/mysqldump.c	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'client/mysqlimport.c'
--- a/client/mysqlimport.c	2008-04-25 16:43:25 +0000
+++ b/client/mysqlimport.c	2008-12-09 18:59:54 +0000
@@ -193,7 +193,7 @@ static void print_version(void)
 static void usage(void)
 {
   print_version();
-  puts("Copyright (C) 2000-2006 MySQL AB");
+  puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you
are welcome to modify and redistribute it under the GPL license\n");
   printf("\
 Loads tables from text files in various formats.  The base name of the\n\

=== modified file 'client/mysqlshow.c'
--- a/client/mysqlshow.c	2007-11-08 11:23:08 +0000
+++ b/client/mysqlshow.c	2008-11-14 16:29:38 +0000
@@ -249,7 +249,7 @@ static void print_version(void)
 static void usage(void)
 {
   print_version();
-  puts("Copyright (C) 2000-2006 MySQL AB");
+  puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you
are welcome to modify and redistribute it under the GPL license\n");
   puts("Shows the structure of a mysql database (databases,tables and columns)\n");
   printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname);

=== modified file 'client/mysqlslap.c'
--- a/client/mysqlslap.c	2008-07-14 14:24:32 +0000
+++ b/client/mysqlslap.c	2008-12-09 18:59:54 +0000
@@ -754,9 +754,7 @@ static void usage(void)
 {
   print_version();
   puts("Copyright (C) 2005 MySQL AB");
-  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
-       \nand you are welcome to modify and redistribute it under the GPL \
-       license\n");
+  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you
are welcome to modify and redistribute it under the GPL license\n");
   puts("Run a query multiple times against the server\n");
   printf("Usage: %s [OPTIONS]\n",my_progname);
   print_defaults("my",load_default_groups);

=== modified file 'client/mysqltest.c'
--- a/client/mysqltest.c	2008-12-08 21:15:06 +0000
+++ b/client/mysqltest.c	2008-12-13 11:02:16 +0000
@@ -281,8 +281,9 @@ enum enum_commands {
   Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_DIFF_FILES,
   Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR, Q_LIST_FILES,
   Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
-  Q_RESULT_FORMAT_VERSION,
   Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
+  Q_RESULT_FORMAT_VERSION,
+
   Q_UNKNOWN,			       /* Unknown command.   */
   Q_COMMENT,			       /* Comments, ignored. */
   Q_COMMENT_WITH_COMMAND,
@@ -374,9 +375,10 @@ const char *command_names[]=
   "list_files",
   "list_files_write_file",
   "list_files_append_file",
-  "result_format",
   "send_shutdown",
   "shutdown_server",
+  "result_format",
+  "result_format",
 
   0
 };
@@ -5072,7 +5074,6 @@ int read_line(char *buf, int size)
       }
       else if (my_isspace(charset_info, c))
       {
-        /* Skip all space at begining of line */
 	if (c == '\n')
         {
           if (last_char == '\n')

=== modified file 'configure.in'
--- a/configure.in	2008-12-08 21:15:06 +0000
+++ b/configure.in	2008-12-13 11:02:16 +0000
@@ -16,8 +16,8 @@ AM_CONFIG_HEADER([include/config.h:confi
 
 NDB_VERSION_MAJOR=6
 NDB_VERSION_MINOR=2
-NDB_VERSION_BUILD=16
-NDB_VERSION_STATUS="-RC"
+NDB_VERSION_BUILD=17
+NDB_VERSION_STATUS="-GA"
 
 PROTOCOL_VERSION=10
 DOT_FRM_VERSION=6
@@ -403,7 +403,7 @@ fi
 MYSQL_PROG_AR
 
 # libmysqlclient versioning when linked with GNU ld.
-if $LD --version 2>/dev/null|grep -q GNU; then
+if $LD --version 2>/dev/null| grep GNU >/dev/null 2>&1; then
   LD_VERSION_SCRIPT="-Wl,--version-script=\$(top_builddir)/libmysql/libmysql.ver"
   AC_CONFIG_FILES(libmysql/libmysql.ver)
 fi
@@ -475,11 +475,11 @@ AC_SUBST(PERL5)
 
 # Enable the abi_check rule only if gcc is available
 
-if expr "$CC" : ".*gcc.*"
+if test "$GCC" != "yes" || expr "$CC" : ".*icc.*"
 then
-  ABI_CHECK="abi_check"
-else
   ABI_CHECK=""
+else
+  ABI_CHECK="abi_check"
 fi
 
 AC_SUBST(ABI_CHECK)
@@ -2094,7 +2094,7 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bs
   sighold sigset sigthreadmask port_create sleep thr_yield \
   snprintf socket stpcpy strcasecmp strerror strsignal strnlen strpbrk strstr \
   strtol strtoll strtoul strtoull tell tempnam thr_setconcurrency vidattr \
-  posix_fallocate backtrace backtrace_symbols backtrace_symbols_fd)
+  posix_fallocate backtrace backtrace_symbols backtrace_symbols_fd directio)
 
 #
 #

=== modified file 'extra/CMakeLists.txt'
--- a/extra/CMakeLists.txt	2008-11-05 10:19:19 +0000
+++ b/extra/CMakeLists.txt	2008-12-12 07:48:03 +0000
@@ -46,6 +46,9 @@ TARGET_LINK_LIBRARIES(perror strings mys
 ADD_EXECUTABLE(resolveip resolveip.c)
 TARGET_LINK_LIBRARIES(resolveip strings mysys dbug)
 
+ADD_EXECUTABLE(resolveip resolveip.c)
+TARGET_LINK_LIBRARIES(resolveip strings mysys debug dbug wsock32)
+
 ADD_EXECUTABLE(replace replace.c)
 TARGET_LINK_LIBRARIES(replace strings mysys dbug)
 

=== modified file 'extra/Makefile.am'
--- a/extra/Makefile.am	2008-10-15 01:19:02 +0000
+++ b/extra/Makefile.am	2008-12-13 11:02:16 +0000
@@ -46,12 +46,12 @@ $(top_builddir)/include/mysqld_ername.h:
 $(top_builddir)/include/sql_state.h: $(top_builddir)/include/mysqld_error.h
 
 bin_PROGRAMS =		replace perror resolveip my_print_defaults \
-			resolve_stack_dump mysql_waitpid 
+			resolve_stack_dump mysql_waitpid
 # "innochecksum" should be switched
 if BUILD_INNODB_TOOLS
 bin_PROGRAMS += innochecksum
 endif
-			
+
 noinst_PROGRAMS =	charset2html
 EXTRA_DIST =		CMakeLists.txt
 

=== modified file 'include/config-win.h'
--- a/include/config-win.h	2008-11-24 15:30:37 +0000
+++ b/include/config-win.h	2008-12-12 07:48:03 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -394,6 +394,9 @@ inline double ulonglong2double(ulonglong
 #define HAVE_OPENSSL 1
 #define HAVE_YASSL 1
 
+#define COMMUNITY_SERVER 1
+#define ENABLED_PROFILING 1
+
 /* Define charsets you want */
 /* #undef HAVE_CHARSET_armscii8 */
 /* #undef HAVE_CHARSET_ascii */

=== modified file 'include/hash.h'
--- a/include/hash.h	2008-10-01 10:21:15 +0000
+++ b/include/hash.h	2008-11-10 20:21:49 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'include/thr_lock.h'
--- a/include/thr_lock.h	2008-09-29 18:20:59 +0000
+++ b/include/thr_lock.h	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'mysql-test/extra/rpl_tests/rpl_row_basic.test'
--- a/mysql-test/extra/rpl_tests/rpl_row_basic.test	2008-12-08 21:15:06 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_row_basic.test	2008-12-13 11:02:16 +0000
@@ -472,183 +472,6 @@ connection master;
 drop table t1;
 sync_slave_with_master;
 
-#
-# Bug #38230  Differences between master and slave after 
-#             UPDATE or DELETE with LIMIT with pk
-#
-# the regression test verifies consistency via selecting
-
---disable_abort_on_error
-
---connection master
-
---disable_warnings
-DROP TABLE IF EXISTS t1, t2;
---enable_warnings
-
-eval CREATE TABLE t1 (
-  `pk` int(11) NOT NULL AUTO_INCREMENT,
-  `int_nokey` int(11) NOT NULL,
-  `int_key` int(11) NOT NULL,
-  `date_key` date NOT NULL,
-  `date_nokey` date NOT NULL,
-  `time_key` time NOT NULL,
-  `time_nokey` time NOT NULL,
-  `datetime_key` datetime NOT NULL,
-  `datetime_nokey` datetime NOT NULL,
-  `varchar_key` varchar(1) NOT NULL,
-  `varchar_nokey` varchar(1) NOT NULL,
-  PRIMARY KEY (`pk`),
-  KEY `int_key` (`int_key`),
-  KEY `date_key` (`date_key`),
-  KEY `time_key` (`time_key`),
-  KEY `datetime_key` (`datetime_key`),
-  KEY `varchar_key` (`varchar_key`)
-) ENGINE=$type;
-
-INSERT INTO t1 VALUES (1,8,5,'0000-00-00','0000-00-00','10:37:38','10:37:38','0000-00-00
00:00:00','0000-00-00
00:00:00','p','p'),(2,0,9,'0000-00-00','0000-00-00','00:00:00','00:00:00','2007-10-14
00:00:00','2007-10-14 00:00:00','d','d');
-
-eval CREATE TABLE t2 (
-  `pk` int(11) NOT NULL AUTO_INCREMENT,
-  `int_nokey` int(11) NOT NULL,
-  `int_key` int(11) NOT NULL,
-  `date_key` date NOT NULL,
-  `date_nokey` date NOT NULL,
-  `time_key` time NOT NULL,
-  `time_nokey` time NOT NULL,
-  `datetime_key` datetime NOT NULL,
-  `datetime_nokey` datetime NOT NULL,
-  `varchar_key` varchar(1) NOT NULL,
-  `varchar_nokey` varchar(1) NOT NULL,
-  PRIMARY KEY (`pk`),
-  KEY `int_key` (`int_key`),
-  KEY `date_key` (`date_key`),
-  KEY `time_key` (`time_key`),
-  KEY `datetime_key` (`datetime_key`),
-  KEY `varchar_key` (`varchar_key`)
-) ENGINE=$type;
-
-INSERT INTO t2 VALUES (1,1,6,'2005-12-23','2005-12-23','02:24:28','02:24:28','0000-00-00
00:00:00','0000-00-00
00:00:00','g','g'),(2,0,3,'2009-09-14','2009-09-14','00:00:00','00:00:00','2000-01-30
16:39:40','2000-01-30
16:39:40','q','q'),(3,0,3,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','c','c'),(4,1,6,'2007-03-29','2007-03-29','15:49:00','15:49:00','0000-00-00
00:00:00','0000-00-00
00:00:00','m','m'),(5,4,0,'2002-12-04','2002-12-04','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','o','o'),(6,9,0,'2005-01-28','2005-01-28','00:00:00','00:00:00','2001-05-18
00:00:00','2001-05-18
00:00:00','w','w'),(7,6,0,'0000-00-00','0000-00-00','06:57:25','06:57:25','0000-00-00
00:00:00','0000-00-00
00:00:00','m','m'),(8,0,0,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','z','z'),(9,4,6,'2006-08-15','2006-08-15','00:00:00','00:00:00','2002-04-12
14:44:25','2002-04-12 14:44:25','j',
 'j'),(10,0,5,'2006-12-20','2006-12-20','10:13:53','10:13:53','2008-07-22
00:00:00','2008-07-22
00:00:00','y','y'),(11,9,7,'0000-00-00','0000-00-00','00:00:00','00:00:00','2004-07-05
00:00:00','2004-07-05
00:00:00','{','{'),(12,4,3,'2007-01-26','2007-01-26','23:00:51','23:00:51','2001-05-16
00:00:00','2001-05-16
00:00:00','f','f'),(13,7,0,'2004-03-27','2004-03-27','00:00:00','00:00:00','2005-01-24
03:30:37','2005-01-24
03:30:37','',''),(14,6,0,'2006-07-26','2006-07-26','18:43:57','18:43:57','0000-00-00
00:00:00','0000-00-00
00:00:00','{','{'),(15,0,6,'2000-01-14','2000-01-14','00:00:00','00:00:00','2000-09-21
00:00:00','2000-09-21
00:00:00','o','o'),(16,9,8,'0000-00-00','0000-00-00','21:15:08','21:15:08','0000-00-00
00:00:00','0000-00-00
00:00:00','a','a'),(17,2,0,'2004-10-27','2004-10-27','00:00:00','00:00:00','2004-03-24
22:13:43','2004-03-24
22:13:43','',''),(18,7,4,'0000-00-00','0000-00-00','08:38:27','08:38:27','2002-03-18
19:51:44','2002-03-18 19:51:44','t','t'),(19,5,3
 ,'2008-03-07','2008-03-07','03:29:07','03:29:07','2007-12-01 18:44:44','2007-12-01
18:44:44','t','t'),(20,0,0,'2002-04-09','2002-04-09','16:06:03','16:06:03','2009-04-22
00:00:00','2009-04-22 00:00:00','n','n');
-
-DELETE FROM t2 WHERE `int_key` < 3 LIMIT 1;
-UPDATE t1 SET `int_key` = 3 ORDER BY `pk` LIMIT 4;
-DELETE FROM t2 WHERE `int_key` < 3 LIMIT 1;
-DELETE FROM t2 WHERE `pk` < 6 LIMIT 1;
-UPDATE t1 SET `int_key` = 6 ORDER BY `pk` LIMIT 3;
-DELETE FROM t2 WHERE `pk` < 6 LIMIT 1;
-UPDATE t1 SET `pk` = 6 ORDER BY `int_key` LIMIT 6;
-DELETE FROM t2 WHERE `pk` < 7 LIMIT 1;
-UPDATE t1 SET `int_key` = 4 ORDER BY `pk` LIMIT 6;
-
---sync_slave_with_master
---echo *** results: t2 must be consistent ****
-
-let $diff_table_1=master:test.t2;
-let $diff_table_2=master:test.t2;
-source include/diff_tables.inc;
-
---connection master
-DROP TABLE t1, t2;
-
---enable_abort_on_error
-
---echo EOF OF TESTS
-
-#
-# BUG#40004: Replication failure with no PK + no indexes
-#
-
-# The test cases are taken from the bug report. It is difficult to
-# produce a test case that generates a HA_ERR_RECORD_DELETED, so we go
-# with the test cases we have.
-
-connection master;
-
-eval CREATE TABLE t1 (a int) ENGINE=$type;
-
-INSERT IGNORE INTO t1 VALUES (NULL);
-INSERT INTO t1 ( a ) VALUES ( 0 );
-INSERT INTO t1 ( a ) VALUES ( 9 );
-INSERT INTO t1 ( a ) VALUES ( 2 );
-INSERT INTO t1 ( a ) VALUES ( 9 );
-INSERT INTO t1 ( a ) VALUES ( 5 );
-
-UPDATE t1 SET a = 5 WHERE a = 9;
-DELETE FROM t1 WHERE a < 6;
-UPDATE t1 SET a = 9 WHERE a < 3;
-INSERT INTO t1 ( a ) VALUES ( 3 );
-UPDATE t1 SET a = 0 WHERE a < 4;
-UPDATE t1 SET a = 8 WHERE a < 5;
-
-sync_slave_with_master;
-
-let $diff_table_1=master:test.t1;
-let $diff_table_2=slave:test.t1;
-source include/diff_tables.inc;
-
-connection master;
-drop table t1;
-sync_slave_with_master;
-
-#
-# Bug #39752: Replication failure on RBR + MyISAM + no PK
-#
-
-# The test cases are taken from the bug report. It is difficult to
-# produce a test case that generates a HA_ERR_RECORD_DELETED, so we go
-# with the test cases we have.
-
-connection master;
-
---disable_warnings
-eval CREATE TABLE t1 (a bit) ENGINE=$type;
-INSERT IGNORE INTO t1 VALUES (NULL);
-INSERT INTO t1 ( a ) VALUES ( 0 );
-UPDATE t1 SET a = 0 WHERE a = 1 LIMIT 3;
-INSERT INTO t1 ( a ) VALUES ( 5 );
-DELETE FROM t1 WHERE a < 2 LIMIT 4;
-DELETE FROM t1 WHERE a < 9 LIMIT 4;
-INSERT INTO t1 ( a ) VALUES ( 9 );
-UPDATE t1 SET a = 8 WHERE a = 0 LIMIT 6;
-INSERT INTO t1 ( a ) VALUES ( 8 );
-UPDATE t1 SET a = 0 WHERE a < 6 LIMIT 0;
-INSERT INTO t1 ( a ) VALUES ( 4 );
-INSERT INTO t1 ( a ) VALUES ( 3 );
-UPDATE t1 SET a = 0 WHERE a = 7 LIMIT 6;
-DELETE FROM t1 WHERE a = 4 LIMIT 7;
-UPDATE t1 SET a = 9 WHERE a < 2 LIMIT 9;
-UPDATE t1 SET a = 0 WHERE a < 9 LIMIT 2;
-DELETE FROM t1 WHERE a < 0 LIMIT 5;
-INSERT INTO t1 ( a ) VALUES ( 5 );
-UPDATE t1 SET a = 4 WHERE a < 6 LIMIT 4;
-INSERT INTO t1 ( a ) VALUES ( 5 );
-UPDATE t1 SET a = 9 WHERE a < 5 LIMIT 8;
-DELETE FROM t1 WHERE a < 8 LIMIT 8;
-INSERT INTO t1 ( a ) VALUES ( 6 );
-DELETE FROM t1 WHERE a < 6 LIMIT 7;
-UPDATE t1 SET a = 7 WHERE a = 3 LIMIT 7;
-UPDATE t1 SET a = 8 WHERE a = 0 LIMIT 6;
-INSERT INTO t1 ( a ) VALUES ( 7 );
-DELETE FROM t1 WHERE a < 9 LIMIT 4;
-INSERT INTO t1 ( a ) VALUES ( 7 );
-INSERT INTO t1 ( a ) VALUES ( 6 );
-UPDATE t1 SET a = 8 WHERE a = 3 LIMIT 4;
-DELETE FROM t1 WHERE a = 2 LIMIT 9;
-DELETE FROM t1 WHERE a = 1 LIMIT 4;
-UPDATE t1 SET a = 4 WHERE a = 2 LIMIT 7;
-INSERT INTO t1 ( a ) VALUES ( 0 );
-DELETE FROM t1 WHERE a < 3 LIMIT 0;
-UPDATE t1 SET a = 8 WHERE a = 5 LIMIT 2;
-INSERT INTO t1 ( a ) VALUES ( 1 );
-UPDATE t1 SET a = 9 WHERE a < 5 LIMIT 3;
---enable_warnings
-
-sync_slave_with_master;
-
-let $diff_table_1=master:test.t1;
-let $diff_table_2=slave:test.t1;
-source include/diff_tables.inc;
-
-connection master;
-drop table t1;
-sync_slave_with_master;
+# Test case moved to separate file as there is problem for ndb.
+# file extra/rpl_tests/rpl_row_basic_no_pk.test as not to have 
+# to disable the whole testcase

=== added file 'mysql-test/extra/rpl_tests/rpl_row_basic_no_pk.test'
--- a/mysql-test/extra/rpl_tests/rpl_row_basic_no_pk.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_row_basic_no_pk.test	2008-12-09 18:59:54 +0000
@@ -0,0 +1,180 @@
+#
+# Bug #38230  Differences between master and slave after 
+#             UPDATE or DELETE with LIMIT with pk
+#
+# the regression test verifies consistency via selecting
+
+--disable_abort_on_error
+
+--connection master
+
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+
+eval CREATE TABLE t1 (
+  `pk` int(11) NOT NULL AUTO_INCREMENT,
+  `int_nokey` int(11) NOT NULL,
+  `int_key` int(11) NOT NULL,
+  `date_key` date NOT NULL,
+  `date_nokey` date NOT NULL,
+  `time_key` time NOT NULL,
+  `time_nokey` time NOT NULL,
+  `datetime_key` datetime NOT NULL,
+  `datetime_nokey` datetime NOT NULL,
+  `varchar_key` varchar(1) NOT NULL,
+  `varchar_nokey` varchar(1) NOT NULL,
+  PRIMARY KEY (`pk`),
+  KEY `int_key` (`int_key`),
+  KEY `date_key` (`date_key`),
+  KEY `time_key` (`time_key`),
+  KEY `datetime_key` (`datetime_key`),
+  KEY `varchar_key` (`varchar_key`)
+) ENGINE=$type;
+
+INSERT INTO t1 VALUES (1,8,5,'0000-00-00','0000-00-00','10:37:38','10:37:38','0000-00-00
00:00:00','0000-00-00
00:00:00','p','p'),(2,0,9,'0000-00-00','0000-00-00','00:00:00','00:00:00','2007-10-14
00:00:00','2007-10-14 00:00:00','d','d');
+
+eval CREATE TABLE t2 (
+  `pk` int(11) NOT NULL AUTO_INCREMENT,
+  `int_nokey` int(11) NOT NULL,
+  `int_key` int(11) NOT NULL,
+  `date_key` date NOT NULL,
+  `date_nokey` date NOT NULL,
+  `time_key` time NOT NULL,
+  `time_nokey` time NOT NULL,
+  `datetime_key` datetime NOT NULL,
+  `datetime_nokey` datetime NOT NULL,
+  `varchar_key` varchar(1) NOT NULL,
+  `varchar_nokey` varchar(1) NOT NULL,
+  PRIMARY KEY (`pk`),
+  KEY `int_key` (`int_key`),
+  KEY `date_key` (`date_key`),
+  KEY `time_key` (`time_key`),
+  KEY `datetime_key` (`datetime_key`),
+  KEY `varchar_key` (`varchar_key`)
+) ENGINE=$type;
+
+INSERT INTO t2 VALUES (1,1,6,'2005-12-23','2005-12-23','02:24:28','02:24:28','0000-00-00
00:00:00','0000-00-00
00:00:00','g','g'),(2,0,3,'2009-09-14','2009-09-14','00:00:00','00:00:00','2000-01-30
16:39:40','2000-01-30
16:39:40','q','q'),(3,0,3,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','c','c'),(4,1,6,'2007-03-29','2007-03-29','15:49:00','15:49:00','0000-00-00
00:00:00','0000-00-00
00:00:00','m','m'),(5,4,0,'2002-12-04','2002-12-04','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','o','o'),(6,9,0,'2005-01-28','2005-01-28','00:00:00','00:00:00','2001-05-18
00:00:00','2001-05-18
00:00:00','w','w'),(7,6,0,'0000-00-00','0000-00-00','06:57:25','06:57:25','0000-00-00
00:00:00','0000-00-00
00:00:00','m','m'),(8,0,0,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','z','z'),(9,4,6,'2006-08-15','2006-08-15','00:00:00','00:00:00','2002-04-12
14:44:25','2002-04-12 14:44:25','j',
 'j'),(10,0,5,'2006-12-20','2006-12-20','10:13:53','10:13:53','2008-07-22
00:00:00','2008-07-22
00:00:00','y','y'),(11,9,7,'0000-00-00','0000-00-00','00:00:00','00:00:00','2004-07-05
00:00:00','2004-07-05
00:00:00','{','{'),(12,4,3,'2007-01-26','2007-01-26','23:00:51','23:00:51','2001-05-16
00:00:00','2001-05-16
00:00:00','f','f'),(13,7,0,'2004-03-27','2004-03-27','00:00:00','00:00:00','2005-01-24
03:30:37','2005-01-24
03:30:37','',''),(14,6,0,'2006-07-26','2006-07-26','18:43:57','18:43:57','0000-00-00
00:00:00','0000-00-00
00:00:00','{','{'),(15,0,6,'2000-01-14','2000-01-14','00:00:00','00:00:00','2000-09-21
00:00:00','2000-09-21
00:00:00','o','o'),(16,9,8,'0000-00-00','0000-00-00','21:15:08','21:15:08','0000-00-00
00:00:00','0000-00-00
00:00:00','a','a'),(17,2,0,'2004-10-27','2004-10-27','00:00:00','00:00:00','2004-03-24
22:13:43','2004-03-24
22:13:43','',''),(18,7,4,'0000-00-00','0000-00-00','08:38:27','08:38:27','2002-03-18
19:51:44','2002-03-18 19:51:44','t','t'),(19,5,3
 ,'2008-03-07','2008-03-07','03:29:07','03:29:07','2007-12-01 18:44:44','2007-12-01
18:44:44','t','t'),(20,0,0,'2002-04-09','2002-04-09','16:06:03','16:06:03','2009-04-22
00:00:00','2009-04-22 00:00:00','n','n');
+
+DELETE FROM t2 WHERE `int_key` < 3 LIMIT 1;
+UPDATE t1 SET `int_key` = 3 ORDER BY `pk` LIMIT 4;
+DELETE FROM t2 WHERE `int_key` < 3 LIMIT 1;
+DELETE FROM t2 WHERE `pk` < 6 LIMIT 1;
+UPDATE t1 SET `int_key` = 6 ORDER BY `pk` LIMIT 3;
+DELETE FROM t2 WHERE `pk` < 6 LIMIT 1;
+UPDATE t1 SET `pk` = 6 ORDER BY `int_key` LIMIT 6;
+DELETE FROM t2 WHERE `pk` < 7 LIMIT 1;
+UPDATE t1 SET `int_key` = 4 ORDER BY `pk` LIMIT 6;
+
+--sync_slave_with_master
+--echo *** results: t2 must be consistent ****
+
+let $diff_table_1=master:test.t2;
+let $diff_table_2=master:test.t2;
+source include/diff_tables.inc;
+
+--connection master
+DROP TABLE t1, t2;
+
+--enable_abort_on_error
+
+--echo EOF OF TESTS
+
+#
+# BUG#40004: Replication failure with no PK + no indexes
+#
+
+# The test cases are taken from the bug report. It is difficult to
+# produce a test case that generates a HA_ERR_RECORD_DELETED, so we go
+# with the test cases we have.
+
+connection master;
+
+eval CREATE TABLE t1 (a int) ENGINE=$type;
+
+INSERT IGNORE INTO t1 VALUES (NULL);
+INSERT INTO t1 ( a ) VALUES ( 0 );
+INSERT INTO t1 ( a ) VALUES ( 9 );
+INSERT INTO t1 ( a ) VALUES ( 2 );
+INSERT INTO t1 ( a ) VALUES ( 9 );
+INSERT INTO t1 ( a ) VALUES ( 5 );
+
+UPDATE t1 SET a = 5 WHERE a = 9;
+DELETE FROM t1 WHERE a < 6;
+UPDATE t1 SET a = 9 WHERE a < 3;
+INSERT INTO t1 ( a ) VALUES ( 3 );
+UPDATE t1 SET a = 0 WHERE a < 4;
+UPDATE t1 SET a = 8 WHERE a < 5;
+
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+
+connection master;
+drop table t1;
+sync_slave_with_master;
+
+#
+# Bug #39752: Replication failure on RBR + MyISAM + no PK
+#
+
+# The test cases are taken from the bug report. It is difficult to
+# produce a test case that generates a HA_ERR_RECORD_DELETED, so we go
+# with the test cases we have.
+
+connection master;
+
+--disable_warnings
+eval CREATE TABLE t1 (a bit) ENGINE=$type;
+INSERT IGNORE INTO t1 VALUES (NULL);
+INSERT INTO t1 ( a ) VALUES ( 0 );
+UPDATE t1 SET a = 0 WHERE a = 1 LIMIT 3;
+INSERT INTO t1 ( a ) VALUES ( 5 );
+DELETE FROM t1 WHERE a < 2 LIMIT 4;
+DELETE FROM t1 WHERE a < 9 LIMIT 4;
+INSERT INTO t1 ( a ) VALUES ( 9 );
+UPDATE t1 SET a = 8 WHERE a = 0 LIMIT 6;
+INSERT INTO t1 ( a ) VALUES ( 8 );
+UPDATE t1 SET a = 0 WHERE a < 6 LIMIT 0;
+INSERT INTO t1 ( a ) VALUES ( 4 );
+INSERT INTO t1 ( a ) VALUES ( 3 );
+UPDATE t1 SET a = 0 WHERE a = 7 LIMIT 6;
+DELETE FROM t1 WHERE a = 4 LIMIT 7;
+UPDATE t1 SET a = 9 WHERE a < 2 LIMIT 9;
+UPDATE t1 SET a = 0 WHERE a < 9 LIMIT 2;
+DELETE FROM t1 WHERE a < 0 LIMIT 5;
+INSERT INTO t1 ( a ) VALUES ( 5 );
+UPDATE t1 SET a = 4 WHERE a < 6 LIMIT 4;
+INSERT INTO t1 ( a ) VALUES ( 5 );
+UPDATE t1 SET a = 9 WHERE a < 5 LIMIT 8;
+DELETE FROM t1 WHERE a < 8 LIMIT 8;
+INSERT INTO t1 ( a ) VALUES ( 6 );
+DELETE FROM t1 WHERE a < 6 LIMIT 7;
+UPDATE t1 SET a = 7 WHERE a = 3 LIMIT 7;
+UPDATE t1 SET a = 8 WHERE a = 0 LIMIT 6;
+INSERT INTO t1 ( a ) VALUES ( 7 );
+DELETE FROM t1 WHERE a < 9 LIMIT 4;
+INSERT INTO t1 ( a ) VALUES ( 7 );
+INSERT INTO t1 ( a ) VALUES ( 6 );
+UPDATE t1 SET a = 8 WHERE a = 3 LIMIT 4;
+DELETE FROM t1 WHERE a = 2 LIMIT 9;
+DELETE FROM t1 WHERE a = 1 LIMIT 4;
+UPDATE t1 SET a = 4 WHERE a = 2 LIMIT 7;
+INSERT INTO t1 ( a ) VALUES ( 0 );
+DELETE FROM t1 WHERE a < 3 LIMIT 0;
+UPDATE t1 SET a = 8 WHERE a = 5 LIMIT 2;
+INSERT INTO t1 ( a ) VALUES ( 1 );
+UPDATE t1 SET a = 9 WHERE a < 5 LIMIT 3;
+--enable_warnings
+
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+
+connection master;
+drop table t1;
+sync_slave_with_master;

=== modified file 'mysql-test/include/have_blackhole.inc'
--- a/mysql-test/include/have_blackhole.inc	2008-07-04 18:48:25 +0000
+++ b/mysql-test/include/have_blackhole.inc	2008-12-08 10:30:21 +0000
@@ -1,4 +1,9 @@
 disable_query_log;
 --require r/true.require
-select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines
where engine = 'blackhole';
+let $have_blackhole=`select (support = 'YES' or support = 'DEFAULT') as `TRUE` 
+                   from information_schema.engines where engine = 'blackhole'`;
+if (!$have_blackhole)
+{
+  skip Test needs the Blackhole storage engine;
+}
 enable_query_log;

=== modified file 'mysql-test/lib/mtr_cases.pl'
--- a/mysql-test/lib/mtr_cases.pl	2008-10-21 23:12:53 +0000
+++ b/mysql-test/lib/mtr_cases.pl	2008-12-10 16:17:36 +0000
@@ -820,6 +820,13 @@ sub collect_one_test_case($$$$$$$$$) {
       return;
     }
 
+    if ( $tinfo->{'not_embedded'} and $::glob_use_embedded_server )
+    {
+      $tinfo->{'skip'}= 1;
+      $tinfo->{'comment'}= "Test disabled for embedded";
+      return;
+    }
+
     if ( $tinfo->{'require_manager'} )
     {
       $tinfo->{'skip'}= 1;
@@ -923,6 +930,7 @@ our @tags=
  ["include/have_ndb.inc", "ndb_test", 1],
  ["include/have_multi_ndb.inc", "ndb_test", 1],
  ["include/have_ndb_extra.inc", "ndb_extra", 1],
+ ["include/not_embedded.inc", "not_embedded", 1],
  ["include/ndb_master-slave.inc", "ndb_test", 1],
  ["require_manager", "require_manager", 1],
  ["include/federated.inc", "federated_test", 1],

=== modified file 'mysql-test/lib/mtr_report.pl'
--- a/mysql-test/lib/mtr_report.pl	2008-12-08 21:15:06 +0000
+++ b/mysql-test/lib/mtr_report.pl	2008-12-13 11:02:16 +0000
@@ -1,5 +1,5 @@
 # -*- cperl -*-
-# Copyright (C) 2004-2006 MySQL AB
+# Copyright 2004-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -438,7 +438,14 @@ sub mtr_report_stats ($) {
                 /setrlimit could not change the size of core files to 'infinity'/ or
 
                 # rpl_ndb_basic expects this error
-                /Slave: Got error 146 during COMMIT Error_code: 1180/ or
+                ($testname eq 'rpl_ndb.rpl_ndb_basic'
+                 and (/Slave: Got error 146 during COMMIT Error_code: 1180/)
+                ) or
+
+                # ndb_autodiscover3 expects this error
+                ($testname eq 'ndb_team.ndb_autodiscover3'
+                 and (/NDB_SHARE: \.\/test\/t1 already exists/)
+                ) or
 
 		# rpl_extrColmaster_*.test, the slave thread produces warnings
 		# when it get updates to a table that has more columns on the

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2008-12-08 21:15:06 +0000
+++ b/mysql-test/mysql-test-run.pl	2008-12-13 11:02:16 +0000
@@ -133,7 +133,7 @@ our $default_vardir;
 
 our $opt_usage;
 our $opt_suites;
-our $opt_suites_default= "main,backup,backup_engines,binlog,rpl,rpl_ndb,ndb"; # Default
suites to run
+our $opt_suites_default= "ndb,ndb_binlog,rpl_ndb,main,backup,backup_engines,binlog,rpl";
# Default suites to run
 our $opt_script_debug= 0;  # Script debugging, enable with --script-debug
 our $opt_verbose= 0;  # Verbose output, enable with --verbose
 
@@ -404,17 +404,18 @@ sub main () {
       # Check for any extra suites to enable based on the path name
       my %extra_suites=
 	(
-	 "mysql-5.1-new-ndb"              => "ndb_team",
-	 "mysql-5.1-new-ndb-merge"        => "ndb_team",
-	 "mysql-5.1-telco-6.2"            => "ndb_team",
-	 "mysql-5.1-telco-6.2-merge"      => "ndb_team",
-	 "mysql-5.1-telco-6.3"            => "ndb_team",
-	 "mysql-6.0-ndb"                  => "ndb_team",
-	 "mysql-6.0-falcon"               => "falcon_team",
-	 "mysql-6.0-falcon-team"          => "falcon_team",
-	 "mysql-6.0-falcon-wlad"          => "falcon_team",
-	 "mysql-6.0-falcon-chris"         => "falcon_team",
-	 "mysql-6.0-falcon-kevin"         => "falcon_team",
+	 "bzr_mysql-5.1-ndb"                  => "ndb_team",
+	 "bzr_mysql-5.1-ndb-merge"            => "ndb_team",
+	 "bzr_mysql-5.1-telco-6.2"            => "ndb_team",
+	 "bzr_mysql-5.1-telco-6.2-merge"      => "ndb_team",
+	 "bzr_mysql-5.1-telco-6.3"            => "ndb_team",
+	 "bzr_mysql-5.1-telco-6.4"            => "ndb_team",
+	 "bzr_mysql-6.0-ndb"                  => "ndb_team,rpl_ndb_big",
+	 "bzr_mysql-6.0-falcon"               => "falcon_team",
+	 "bzr_mysql-6.0-falcon-team"          => "falcon_team",
+	 "bzr_mysql-6.0-falcon-wlad"          => "falcon_team",
+	 "bzr_mysql-6.0-falcon-chris"         => "falcon_team",
+	 "bzr_mysql-6.0-falcon-kevin"         => "falcon_team",
 	);
 
       foreach my $dir ( reverse splitdir($glob_basedir) )
@@ -2726,7 +2727,7 @@ sub ndbd_start ($$$) {
   mtr_add_arg($args, "$extra_args");
 
   my $nodeid= $cluster->{'ndbds'}->[$idx]->{'nodeid'};
-  my $path_ndbd_log= "$cluster->{'data_dir'}/ndb_${nodeid}.log";
+  my $path_ndbd_log= "$cluster->{'data_dir'}/ndb_${nodeid}_out.log";
   $pid= mtr_spawn($exe_ndbd, $args, "",
 		  $path_ndbd_log,
 		  $path_ndbd_log,
@@ -3813,7 +3814,6 @@ sub mysqld_arguments ($$$$) {
       mtr_add_arg($args, "%s--slave-allow-batching", $prefix);
       if ( $mysql_version_id >= 50100 )
       {
-	mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
 	mtr_add_arg($args, "%s--ndb-log-orig", $prefix);
       }
     }
@@ -3881,7 +3881,6 @@ sub mysqld_arguments ($$$$) {
       mtr_add_arg($args, "%s--slave-allow-batching", $prefix);
       if ( $mysql_version_id >= 50100 )
       {
-	mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
 	mtr_add_arg($args, "%s--ndb-log-orig", $prefix);
       }
     }
@@ -4451,22 +4450,6 @@ sub run_testcase_start_servers($) {
 	 $tinfo->{'master_num'} > 1 )
     {
       # Test needs cluster, start an extra mysqld connected to cluster
-
-      if ( $mysql_version_id >= 50100 )
-      {
-	# First wait for first mysql server to have created ndb system
-	# tables ok FIXME This is a workaround so that only one mysqld
-	# create the tables
-	if ( ! sleep_until_file_created(
-		  "$master->[0]->{'path_myddir'}/mysql/ndb_apply_status.ndb",
-					$master->[0]->{'start_timeout'},
-					$master->[0]->{'pid'}))
-	{
-
-	  $tinfo->{'comment'}= "Failed to create 'mysql/ndb_apply_status' table";
-	  return 1;
-	}
-      }
       mysqld_start($master->[1],$tinfo->{'master_opt'},[]);
     }
 
@@ -4733,15 +4716,11 @@ sub run_mysqltest ($) {
 
   # ----------------------------------------------------------------------
   # If embedded server, we create server args to give mysqltest to pass on
-  # and remove existing falcon tables
   # ----------------------------------------------------------------------
-  
+
   if ( $glob_use_embedded_server )
   {
     mysqld_arguments($args,$master->[0],$tinfo->{'master_opt'},[]);
-    #Remove  falcon tables before each test, otherwise every start might fail
-    #if there is an error in falcon recovery
-    rm_falcon_tables($master->[0]->{'path_myddir'});
   }
 
   # ----------------------------------------------------------------------

=== removed file 'mysql-test/r/innodb_bug34053.result'
--- a/mysql-test/r/innodb_bug34053.result	2008-09-15 21:33:05 +0000
+++ b/mysql-test/r/innodb_bug34053.result	1970-01-01 00:00:00 +0000
@@ -1 +0,0 @@
-SET storage_engine=InnoDB;

=== removed file 'mysql-test/r/rpl_slave_exec_mode_basic.result.moved'
--- a/mysql-test/r/rpl_slave_exec_mode_basic.result.moved	2008-10-15 01:19:02 +0000
+++ b/mysql-test/r/rpl_slave_exec_mode_basic.result.moved	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-SET @start_value = @@global.slave_exec_mode;
-'This variable is not supported in version 5.1.22. It is introduced in 5.1.24'

=== renamed file 'mysql-test/r/rpl_slave_allow_batching_basic.result.moved' =>
'mysql-test/r/slave_allow_batching_basic.result'
--- a/mysql-test/r/rpl_slave_allow_batching_basic.result.moved	2008-12-11 18:04:55 +0000
+++ b/mysql-test/r/slave_allow_batching_basic.result	2008-12-13 11:02:16 +0000
@@ -1,5 +1,7 @@
 SET @global_start_value = @@global.slave_allow_batching;
-'Bug: This variable is not supported in mysql version 5.1.22'
+SELECT @global_start_value;
+@global_start_value
+0
 '#--------------------FN_DYNVARS_145_01------------------------#'
 SET @@global.slave_allow_batching = 1;
 SET @@global.slave_allow_batching = DEFAULT;
@@ -73,7 +75,6 @@ SELECT @@global.slave_allow_batching;
 SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE
VARIABLE_NAME='slave_allow_batching';
 VARIABLE_VALUE
 ON
-'Bug: value in information schema does not match'
 '#---------------------FN_DYNVARS_145_08-------------------------#'
 SET @@global.slave_allow_batching = OFF;
 SELECT @@global.slave_allow_batching;

=== renamed file 'mysql-test/r/rpl_slave_compressed_protocol_basic.result.moved' =>
'mysql-test/r/slave_compressed_protocol_basic.result'
=== renamed file 'mysql-test/r/rpl_slave_net_timeout_basic.result.moved' =>
'mysql-test/r/slave_net_timeout_basic.result'
=== modified file 'mysql-test/r/sp-error.result'
--- a/mysql-test/r/sp-error.result	2008-09-30 10:10:32 +0000
+++ b/mysql-test/r/sp-error.result	2008-12-09 14:22:54 +0000
@@ -1666,3 +1666,15 @@ end|
 call p1(1);
 set @@max_sp_recursion_depth = @old_recursion_depth;
 drop procedure p1;
+drop procedure if exists proc_8759;
+create procedure proc_8759()
+begin
+declare should_be_illegal condition for sqlstate '00000';
+declare continue handler for should_be_illegal set @x=0;
+end$$
+ERROR 42000: Bad SQLSTATE: '00000'
+create procedure proc_8759()
+begin
+declare continue handler for sqlstate '00000' set @x=0;
+end$$
+ERROR 42000: Bad SQLSTATE: '00000'

=== modified file 'mysql-test/suite/backup/r/backup.result'
--- a/mysql-test/suite/backup/r/backup.result	2008-12-04 23:14:30 +0000
+++ b/mysql-test/suite/backup/r/backup.result	2008-12-10 15:53:06 +0000
@@ -132,22 +132,41 @@ tasking	CREATE TABLE `tasking` (
   `project_number` char(9) DEFAULT NULL,
   `hours_worked` double(10,2) DEFAULT NULL
 ) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1
-SELECT validity_point_time = @vp_time FROM mysql.backup_history
-WHERE backup_id = @bid;
-validity_point_time = @vp_time
-1
-SELECT binlog_file = @vp_file FROM mysql.backup_history
-WHERE backup_id = @bid;
-binlog_file = @vp_file
-1
-SELECT binlog_pos = @vp_pos FROM mysql.backup_history
-WHERE backup_id = @bid;
+SELECT validity_point_time = @vp_time, 
+binlog_file = @vp_file, 
 binlog_pos = @vp_pos
-1
+FROM mysql.backup_history
+WHERE backup_id = @bid;
+validity_point_time = @vp_time	binlog_file = @vp_file	binlog_pos = @vp_pos
+1	1	1
 DROP DATABASE db1;
 DROP DATABASE db2;
 DROP DATABASE db3;
 SET DEBUG_SYNC= 'RESET';
+CREATE DATABASE db1;
+BACKUP DATABASE db1 TO 'db1.bkp';
+backup_id
+#
+SELECT MAX(backup_id) FROM mysql.backup_history INTO @bid;
+SELECT validity_point_time FROM mysql.backup_history
+WHERE backup_id = @bid INTO @vp_time;
+SELECT binlog_file FROM mysql.backup_history
+WHERE backup_id = @bid INTO @vp_file;
+SELECT binlog_pos FROM mysql.backup_history
+WHERE backup_id = @bid INTO @vp_pos;
+DROP DATABASE db1;
+RESTORE FROM 'db1.bkp';
+backup_id
+#
+SELECT MAX(backup_id) FROM mysql.backup_history INTO @bid;
+SELECT validity_point_time = @vp_time,
+binlog_file = @vp_file,
+binlog_pos = @vp_pos
+FROM mysql.backup_history
+WHERE backup_id = @bid;
+validity_point_time = @vp_time	binlog_file = @vp_file	binlog_pos = @vp_pos
+1	1	1
+DROP DATABASE db1;
 DROP DATABASE IF EXISTS bup_default;
 CREATE DATABASE bup_default;
 CREATE TABLE bup_default.wide (

=== modified file 'mysql-test/suite/backup/r/backup_backupdir.result'
--- a/mysql-test/suite/backup/r/backup_backupdir.result	2008-11-21 15:14:47 +0000
+++ b/mysql-test/suite/backup/r/backup_backupdir.result	2008-12-12 08:02:27 +0000
@@ -42,13 +42,13 @@ backup_id
 Ensure backup image file went to the correct location
 Try a backup to an invalid relative path.
 BACKUP DATABASE bup_backupdir TO '../not/there/bup_backupdir5.bak';
-ERROR HY000: Can't write to backup location '../not/there/bup_backupdir5.bak' (file
already exists?)
+ERROR HY000: Can't create/write to file
'MYSQLTEST_VARDIR/tmp/not/there/bup_backupdir5.bak' (Errcode: #)
 
 Try a backup to an invalid hard path.
 *Actual BACKUP DATABASE command not printed due to non-deterministic path.
 *Performing: 
 *BACKUP DATABASE bup_backupdir TO
'$MYSQLTEST_VARDIR/master_data/not/there/either/bup_backupdir6.bak';
-ERROR HY000: Can't write to backup location
'$MYSQLTEST_VARDIR/master_data/not/there/either/bup_backupdir6.bak' (file already
exists?)
+ERROR HY000: Can't create/write to file
'MYSQLTEST_VARDIR/master_data/not/there/either/bup_backupdir6.bak' (Errcode: #)
 
 Attempt to set the backupdir to something invalid.
 SET @@global.backupdir = 'This_is_really_stupid/not/there/at/all';

=== modified file 'mysql-test/suite/backup/r/backup_default.result'
--- a/mysql-test/suite/backup/r/backup_default.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_default.result	2008-12-04 13:04:16 +0000
@@ -29,33 +29,20 @@ id	name	city
 DROP DATABASE db1;
 
 Server should not crash for backup using default driver 
-Partitioned Falcon tables
-Test for bug#33566, bug#36792 
+Mix of tables
 
 CREATE DATABASE db1;
 USE db1;
 CREATE TABLE partition_table (
 int_column int(11), 
 char_column char(5))
-engine=falcon
+ENGINE=myisam
 PARTITION BY HASH (int_column);
 INSERT INTO partition_table VALUES (0,'pVtIa');
 INSERT INTO partition_table VALUES (5,'jTfSg');
 INSERT INTO partition_table VALUES (20,'UezFi');
 INSERT INTO partition_table VALUES (25,'cxmeH');
 INSERT INTO partition_table VALUES (65,'lIuNS');
-testing content in restored tables
-SELECT * FROM partition_table ORDER BY int_column;
-int_column	char_column
-0	pVtIa
-5	jTfSg
-20	UezFi
-25	cxmeH
-65	lIuNS
-
-Server should not crash for backup using default driver 
-Mix of tables
-
 CREATE TABLE csv_table(
 id int NOT NULL,
 name char(20) NOT NULL,
@@ -67,6 +54,33 @@ i int,
 v varchar(20))
 ENGINE=myisam;
 INSERT INTO myisam_table VALUES(1,'v1'),(2,'v2'),(3,'v3');
+backup on mixed table database
+BACKUP DATABASE db1 to 'bup_mixed.bak';
+backup_id
+#
+DROP DATABASE db1;
+restore on mixed table database
+RESTORE FROM 'bup_mixed.bak';
+backup_id
+#
+testing content in restored tables
+SELECT * FROM partition_table ORDER BY int_column;
+int_column	char_column
+0	pVtIa
+5	jTfSg
+20	UezFi
+25	cxmeH
+65	lIuNS
+SELECT * FROM csv_table ORDER BY id;
+id	name	city
+1	aa1	bb1
+2	aa2	bb2
+3	aa3	bb3
+SELECT * FROM myisam_table ORDER BY i;
+i	v
+1	v1
+2	v2
+3	v3
 
 ***  CLEANUP  ****
 

=== modified file 'mysql-test/suite/backup/r/backup_errors.result'
--- a/mysql-test/suite/backup/r/backup_errors.result	2008-12-04 23:14:30 +0000
+++ b/mysql-test/suite/backup/r/backup_errors.result	2008-12-10 15:53:06 +0000
@@ -1,25 +1,44 @@
 DROP DATABASE IF EXISTS adb;
 DROP DATABASE IF EXISTS bdb;
 RESTORE FROM 'test.bak';
-ERROR HY000: Can't read backup location 'test.bak'
+ERROR HY000: File 'MYSQLTEST_VARDIR/master-data/test.bak' not found (Errcode: #)
 CREATE DATABASE adb;
 CREATE DATABASE bdb;
 CREATE TABLE bdb.t1(a int) ENGINE=MEMORY;
 BACKUP DATABASE adb TO '';
 ERROR HY000: Malformed file path ''
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Malformed file path ''
 BACKUP DATABASE adb TO "bdb/t1.frm";
-ERROR HY000: Can't write to backup location 'bdb/t1.frm' (file already exists?)
+ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/bdb/t1.frm'
(Errcode: #)
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Can't create/write to file 'MYSQLTEST_VARDIR/master-data/bdb/t1.frm' (Errcode: #)
+Error	#	Can't write to backup location 'bdb/t1.frm'
 BACKUP DATABASE adb TO "test.bak";
 backup_id
 #
+SHOW WARNINGS;
+Level	Code	Message
 BACKUP DATABASE adb TO "test.bak";
-ERROR HY000: Can't write to backup location 'test.bak' (file already exists?)
+ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/test.bak' (Errcode:
#)
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Can't create/write to file 'MYSQLTEST_VARDIR/master-data/test.bak' (Errcode: #)
+Error	#	Can't write to backup location 'test.bak'
 DROP DATABASE IF EXISTS foo;
 DROP DATABASE IF EXISTS bar;
 BACKUP DATABASE foo TO 'test.bak';
 ERROR 42000: Unknown database 'foo'
+SHOW WARNINGS;
+Level	Code	Message
+Error	1049	Unknown database 'foo'
 BACKUP DATABASE test,foo,bdb,bar TO 'test.bak';
 ERROR 42000: Unknown database 'foo,bar'
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Unknown database 'foo,bar'
 BACKUP DATABASE foo,test,bar,foo TO 'test.bak';
 ERROR 42000: Not unique database: 'foo'
 use adb;
@@ -49,21 +68,39 @@ DROP DATABASE bdb;
 Backup of mysql, information_schema scenario 1
 BACKUP DATABASE mysql TO 't.bak';
 ERROR HY000: Database 'mysql' cannot be included in a backup
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Database 'mysql' cannot be included in a backup
 Backup of mysql, information_schema scenario 2
 BACKUP DATABASE information_schema TO 't.bak';
 ERROR HY000: Database 'information_schema' cannot be included in a backup
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Database 'information_schema' cannot be included in a backup
 Backup of mysql, information_schema scenario 3
 BACKUP DATABASE mysql, information_schema TO 't.bak';
 ERROR HY000: Database 'mysql' cannot be included in a backup
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Database 'mysql' cannot be included in a backup
 Backup of mysql, information_schema scenario 4
 BACKUP DATABASE mysql, test TO 't.bak';
 ERROR HY000: Database 'mysql' cannot be included in a backup
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Database 'mysql' cannot be included in a backup
 Backup of mysql, information_schema scenario 5
 BACKUP DATABASE information_schema, test TO 't.bak';
 ERROR HY000: Database 'information_schema' cannot be included in a backup
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Database 'information_schema' cannot be included in a backup
 Backup of mysql, information_schema scenario 6
 BACKUP DATABASE mysql, information_schema, test TO 't.bak';
 ERROR HY000: Database 'mysql' cannot be included in a backup
+SHOW WARNINGS;
+Level	Code	Message
+Error	#	Database 'mysql' cannot be included in a backup
 Making copies of progress tables.
 CREATE TABLE IF NOT EXISTS test.ob_copy LIKE mysql.backup_history;
 CREATE TABLE IF NOT EXISTS test.obp_copy LIKE mysql.backup_progress;
@@ -78,7 +115,7 @@ DROP TABLE mysql.backup_history;
 Backup the database;
 BACKUP DATABASE test_ob_error TO 'ob_err.bak';
 ERROR HY000: Can't open the backup logs as tables. Check 'mysql.backup_history' and
'mysql.backup_progress' or run mysql_upgrade to repair.
-SHOW ERRORS;
+SHOW WARNINGS;
 Level	Code	Message
 Error	#	Table 'mysql.backup_history' doesn't exist
 Error	#	Cannot create backup/restore execution context
@@ -89,7 +126,7 @@ DROP TABLE mysql.backup_progress;
 Backup the database;
 BACKUP DATABASE test_ob_error TO 'ob_err.bak';
 ERROR HY000: Can't open the backup logs as tables. Check 'mysql.backup_history' and
'mysql.backup_progress' or run mysql_upgrade to repair.
-SHOW ERRORS;
+SHOW WARNINGS;
 Level	Code	Message
 Error	#	Table 'mysql.backup_progress' doesn't exist
 Error	#	Cannot create backup/restore execution context

=== modified file 'mysql-test/suite/backup/r/backup_views.result'
--- a/mysql-test/suite/backup/r/backup_views.result	2008-11-26 13:46:42 +0000
+++ b/mysql-test/suite/backup/r/backup_views.result	2008-12-10 15:53:06 +0000
@@ -277,10 +277,10 @@ DROP DATABASE bup_db2;
 Restore database.
 restore database with view dependency to other, non-existing db
 RESTORE FROM 'bup_objectview1.bak';
-ERROR HY000: Could not restore view `bup_db1`.`v5`. Please check the view definition for
possible missing dependencies.
+ERROR 42S02: Table 'bup_db2.t2' doesn't exist
 DROP DATABASE bup_db1;
 RESTORE FROM 'bup_objectview2.bak';
-ERROR HY000: Could not restore view `bup_db2`.`student_details`. Please check the view
definition for possible missing dependencies.
+ERROR 42S02: Table 'bup_db1.t3' doesn't exist
 DROP DATABASE bup_db2;
 RESTORE FROM 'bup_objectview.bak';
 backup_id

=== modified file 'mysql-test/suite/backup/t/backup.test'
--- a/mysql-test/suite/backup/t/backup.test	2008-11-17 09:57:51 +0000
+++ b/mysql-test/suite/backup/t/backup.test	2008-12-08 10:30:21 +0000
@@ -1,4 +1,5 @@
 --source include/have_innodb.inc
+--source include/have_blackhole.inc
 --source include/not_embedded.inc
 --source include/have_debug_sync.inc
 --source include/have_log_bin.inc
@@ -180,11 +181,10 @@ SHOW CREATE TABLE tasking;
 
 # check that VP info was correctly read and reported
 
-SELECT validity_point_time = @vp_time FROM mysql.backup_history
-WHERE backup_id = @bid; 
-SELECT binlog_file = @vp_file FROM mysql.backup_history
-WHERE backup_id = @bid; 
-SELECT binlog_pos = @vp_pos FROM mysql.backup_history
+SELECT validity_point_time = @vp_time, 
+       binlog_file = @vp_file, 
+       binlog_pos = @vp_pos
+FROM mysql.backup_history
 WHERE backup_id = @bid; 
 
 DROP DATABASE db1;
@@ -193,6 +193,51 @@ DROP DATABASE db3;
 SET DEBUG_SYNC= 'RESET';
 
 #
+# Check that PTR data (such as VP time and binlog positon) is correctly stored and read
+# when there are no tables to backup (BUG#40262). 
+#
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/db1.bkp
+CREATE DATABASE db1;
+
+--replace_column 1 #
+BACKUP DATABASE db1 TO 'db1.bkp';
+# get backup_id of the BACKUP operation. 
+SELECT MAX(backup_id) FROM mysql.backup_history INTO @bid;
+
+# store VP time and binlog position
+
+SELECT validity_point_time FROM mysql.backup_history
+WHERE backup_id = @bid INTO @vp_time;
+SELECT binlog_file FROM mysql.backup_history
+WHERE backup_id = @bid INTO @vp_file;
+SELECT binlog_pos FROM mysql.backup_history
+WHERE backup_id = @bid INTO @vp_pos;
+
+DROP DATABASE db1;
+
+# wait few seconds so that restore time != backup time
+--sleep 2
+
+--replace_column 1 #
+RESTORE FROM 'db1.bkp';
+# determine id of RESTORE operation
+SELECT MAX(backup_id) FROM mysql.backup_history INTO @bid;
+
+# check that VP info was correctly read and reported
+
+SELECT validity_point_time = @vp_time,
+       binlog_file = @vp_file,
+       binlog_pos = @vp_pos
+FROM mysql.backup_history
+WHERE backup_id = @bid; 
+
+DROP DATABASE db1;
+--remove_file $MYSQLTEST_VARDIR/master-data/db1.bkp
+
+
+#
 # This test is for the default and snapshot online backup drivers
 #
 

=== modified file 'mysql-test/suite/backup/t/backup_backupdir.test'
--- a/mysql-test/suite/backup/t/backup_backupdir.test	2008-11-17 09:57:51 +0000
+++ b/mysql-test/suite/backup/t/backup_backupdir.test	2008-12-08 11:24:51 +0000
@@ -74,7 +74,9 @@ BACKUP DATABASE bup_backupdir TO '../../
 --file_exists $MYSQLTEST_VARDIR/bup_backupdir4.bak
 
 --echo Try a backup to an invalid relative path.
---error ER_BACKUP_WRITE_LOC
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+--error 1
 BACKUP DATABASE bup_backupdir TO '../not/there/bup_backupdir5.bak';
 
 --echo 
@@ -86,8 +88,9 @@ BACKUP DATABASE bup_backupdir TO '../not
 # Do not print the SQL command to result file because dir is not deterministic across
hosts
 --disable_query_log
 # Replace actual dir in error message because $MYSQLTEST_VARDIR is not deterministic
-replace_regex /(location ').*'/location
'$MYSQLTEST_VARDIR\/master_data\/not\/there\/either\/bup_backupdir6.bak'/ ;
---error ER_BACKUP_WRITE_LOC
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+--error 1
 --eval BACKUP DATABASE bup_backupdir TO
'$MYSQLTEST_VARDIR/master_data/not/there/either/bup_backupdir6.bak';
 --enable_query_log
 

=== modified file 'mysql-test/suite/backup/t/backup_default.test'
--- a/mysql-test/suite/backup/t/backup_default.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_default.test	2008-12-04 13:04:16 +0000
@@ -43,17 +43,17 @@ DROP DATABASE db1;
 
 --echo
 --echo Server should not crash for backup using default driver 
---echo Partitioned Falcon tables
---echo Test for bug#33566, bug#36792 
+--echo Mix of tables
 --echo 
 
 CREATE DATABASE db1;
 USE db1;
 
+# create partitioned MyISAM table - will use default driver
 CREATE TABLE partition_table (
   int_column int(11), 
   char_column char(5))
-engine=falcon
+ENGINE=myisam
 PARTITION BY HASH (int_column);
 
 INSERT INTO partition_table VALUES (0,'pVtIa');
@@ -62,30 +62,7 @@ INSERT INTO partition_table VALUES (20,'
 INSERT INTO partition_table VALUES (25,'cxmeH');
 INSERT INTO partition_table VALUES (65,'lIuNS');
 
-#
-# This portion of the test has been disabled. See BUG#39017
-#
-#--echo backup on partitioned falcon
-#--replace_column 1 #
-#BACKUP DATABASE db1 to 'bup_falcon.bak';
-#
-#DROP DATABASE db1;
-#
-#--echo restore on partitioned falcon
-#--replace_column 1 #
-#RESTORE FROM 'bup_falcon.bak';
-
---echo testing content in restored tables
-SELECT * FROM partition_table ORDER BY int_column;
-
-
---echo
---echo Server should not crash for backup using default driver 
---echo Mix of tables
---echo 
-
-# partition_table already exists in the database
-# re-create the csv_table
+# create CSV table - will use default driver
 CREATE TABLE csv_table(
    id int NOT NULL,
    name char(20) NOT NULL,
@@ -102,23 +79,20 @@ ENGINE=myisam;
 
 INSERT INTO myisam_table VALUES(1,'v1'),(2,'v2'),(3,'v3');
 
-#
-# This portion of the test has been disabled. See BUG#39017
-#
-#--echo backup on mixed table database
-#--replace_column 1 #
-#BACKUP DATABASE db1 to 'bup_mixed.bak';
-#
-#DROP DATABASE db1;
-#
-#--echo restore on mixed table database
-#--replace_column 1 #
-#RESTORE FROM 'bup_mixed.bak';
-#
-#--echo testing content in restored tables
-#SELECT * FROM partition_table ORDER BY int_column;
-#SELECT * FROM csv_table ORDER BY id;
-#SELECT * FROM myisam_table ORDER BY i;
+--echo backup on mixed table database
+--replace_column 1 #
+BACKUP DATABASE db1 to 'bup_mixed.bak';
+
+DROP DATABASE db1;
+
+--echo restore on mixed table database
+--replace_column 1 #
+RESTORE FROM 'bup_mixed.bak';
+
+--echo testing content in restored tables
+SELECT * FROM partition_table ORDER BY int_column;
+SELECT * FROM csv_table ORDER BY id;
+SELECT * FROM myisam_table ORDER BY i;
 
 
 # Test cleanup section

=== modified file 'mysql-test/suite/backup/t/backup_errors.test'
--- a/mysql-test/suite/backup/t/backup_errors.test	2008-12-04 23:14:30 +0000
+++ b/mysql-test/suite/backup/t/backup_errors.test	2008-12-10 15:53:06 +0000
@@ -15,7 +15,9 @@ DROP DATABASE IF EXISTS bdb;
 --enable_warnings
 
 # non-existent backup archive
---error ER_BACKUP_READ_LOC
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+--error 29
 RESTORE FROM 'test.bak';
 
 CREATE DATABASE adb;
@@ -25,17 +27,33 @@ CREATE TABLE bdb.t1(a int) ENGINE=MEMORY
 # invalid location
 --error ER_BAD_PATH
 BACKUP DATABASE adb TO '';
+--replace_column 2 #
+SHOW WARNINGS;
 
 # don't overwrite existing files
---error ER_BACKUP_WRITE_LOC
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+--error 1
 BACKUP DATABASE adb TO "bdb/t1.frm";
+--replace_column 2 #
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+SHOW WARNINGS;
 
 --replace_column 1 #
 BACKUP DATABASE adb TO "test.bak";
+--replace_column 2 #
+SHOW WARNINGS;
 
 # don't overwrite existing backup image
---error ER_BACKUP_WRITE_LOC
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+--error 1
 BACKUP DATABASE adb TO "test.bak";
+--replace_column 2 #
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /Errcode: [0-9]+/Errcode: #/
+SHOW WARNINGS;
 
 --remove_file $MYSQLTEST_VARDIR/master-data/test.bak
 
@@ -47,8 +65,11 @@ DROP DATABASE IF EXISTS bar;
 
 -- error ER_BAD_DB_ERROR
 BACKUP DATABASE foo TO 'test.bak';
+SHOW WARNINGS;
 -- error ER_BAD_DB_ERROR
 BACKUP DATABASE test,foo,bdb,bar TO 'test.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 # repeated database
 -- error ER_NONUNIQ_DB
@@ -117,6 +138,8 @@ DROP DATABASE bdb;
 --echo Backup of mysql, information_schema scenario 1
 --error ER_BACKUP_CANNOT_INCLUDE_DB
 BACKUP DATABASE mysql TO 't.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 --error 0, 1
 --remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -125,6 +148,8 @@ BACKUP DATABASE mysql TO 't.bak';
 --echo Backup of mysql, information_schema scenario 2
 --error ER_BACKUP_CANNOT_INCLUDE_DB
 BACKUP DATABASE information_schema TO 't.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 --error 0, 1
 --remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -133,6 +158,8 @@ BACKUP DATABASE information_schema TO 't
 --echo Backup of mysql, information_schema scenario 3
 --error ER_BACKUP_CANNOT_INCLUDE_DB
 BACKUP DATABASE mysql, information_schema TO 't.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 --error 0, 1
 --remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -141,6 +168,8 @@ BACKUP DATABASE mysql, information_schem
 --echo Backup of mysql, information_schema scenario 4
 --error ER_BACKUP_CANNOT_INCLUDE_DB
 BACKUP DATABASE mysql, test TO 't.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 --error 0, 1
 --remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -149,6 +178,8 @@ BACKUP DATABASE mysql, test TO 't.bak';
 --echo Backup of mysql, information_schema scenario 5
 --error ER_BACKUP_CANNOT_INCLUDE_DB
 BACKUP DATABASE information_schema, test TO 't.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 --error 0, 1
 --remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -157,6 +188,8 @@ BACKUP DATABASE information_schema, test
 --echo Backup of mysql, information_schema scenario 6
 --error ER_BACKUP_CANNOT_INCLUDE_DB
 BACKUP DATABASE mysql, information_schema, test TO 't.bak';
+--replace_column 2 #
+SHOW WARNINGS;
 
 --error 0, 1
 --remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -190,7 +223,7 @@ BACKUP DATABASE test_ob_error TO 'ob_err
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/ob_err.bak
 --replace_column 2 #
-SHOW ERRORS;
+SHOW WARNINGS;
 
 # Restore the table
 --echo Restoring the table
@@ -207,7 +240,7 @@ BACKUP DATABASE test_ob_error TO 'ob_err
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/ob_err.bak
 --replace_column 2 #
-SHOW ERRORS;
+SHOW WARNINGS;
 
 # Restore the table
 --echo Restoring the table

=== modified file 'mysql-test/suite/backup/t/backup_myisam1.test'
--- a/mysql-test/suite/backup/t/backup_myisam1.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_myisam1.test	2008-11-25 17:44:19 +0000
@@ -24,5 +24,7 @@ BACKUP DATABASE mysqltest TO 'test.ba';
 # Cleanup from this test case
 #
 DROP DATABASE mysqltest;
+# Note: The backup file should not exist as BACKUP command failed.
+--error 1
 --remove_file $MYSQLTEST_VARDIR/master-data/test.ba
 

=== modified file 'mysql-test/suite/backup/t/backup_views.test'
--- a/mysql-test/suite/backup/t/backup_views.test	2008-11-26 13:46:42 +0000
+++ b/mysql-test/suite/backup/t/backup_views.test	2008-12-10 15:53:06 +0000
@@ -205,14 +205,14 @@ DROP DATABASE bup_db2;
 
 --echo restore database with view dependency to other, non-existing db
 
---error ER_BACKUP_CANT_RESTORE_VIEW
+--error ER_NO_SUCH_TABLE
 RESTORE FROM 'bup_objectview1.bak';
 
 # An incomplete bup_db1 was created by the failing restore operation.
 # Remove it before trying restore of bup_db2.
 DROP DATABASE bup_db1;
 
---error ER_BACKUP_CANT_RESTORE_VIEW
+--error ER_NO_SUCH_TABLE
 RESTORE FROM 'bup_objectview2.bak';
 
 # An incomplete bup_db2 was created by the failing restore operation.

=== modified file 'mysql-test/suite/backup/t/disabled.def'
--- a/mysql-test/suite/backup/t/disabled.def	2008-12-08 12:51:35 +0000
+++ b/mysql-test/suite/backup/t/disabled.def	2008-12-10 15:53:06 +0000
@@ -16,3 +16,5 @@ backup_no_data                : Bug#4100
 backup_ddl_blocker            : Bug#41008 2008-12-08 alik union.test does not cleanup
 backup                        : Bug#40807 2008-11-18 hakank Test fails on big-endian
architecture
 backup_timeout                : Bug#40808 2008-11-18 hakank Test fails on big-endian
architecture
+backup_errors                 : Bug#41359 2008-12-10 ingo Test fails after merge of main
and backup trees
+backup_views                  : Bug#41360 2008-12-10 ingo Test fails after merge of main
and backup trees

=== added file 'mysql-test/suite/backup_engines/r/backup_partition.result'
--- a/mysql-test/suite/backup_engines/r/backup_partition.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_engines/r/backup_partition.result	2008-12-04 13:04:16 +0000
@@ -0,0 +1,43 @@
+#
+# Creating databases
+#
+CREATE DATABASE backup_part;
+CREATE TABLE backup_part.t1 (
+t1_autoinc INTEGER NOT NULL AUTO_INCREMENT,
+t1_uuid CHAR(36),
+PRIMARY KEY (t1_autoinc))
+PARTITION BY HASH (t1_autoinc);
+INSERT INTO backup_part.t1(t1_uuid) VALUES ('aaa'),('bbb'),('ccc'),('ddd');
+# Show content
+SELECT * FROM backup_part.t1 ORDER BY t1_autoinc;
+t1_autoinc	t1_uuid
+1	aaa
+2	bbb
+3	ccc
+4	ddd
+#
+# Perform backup
+#
+# Show drivers. 
+
+SELECT count(*) FROM mysql.backup_history WHERE drivers LIKE 'FILTERED DRIVER' AND
backup_id=FILTERED ID;
+count(*)
+1
+
+#
+# Restore and show content
+#  
+RESTORE FROM 'partition.bak' OVERWRITE;
+backup_id
+#
+
+SELECT * FROM backup_part.t1 ORDER BY t1_autoinc;
+t1_autoinc	t1_uuid
+1	aaa
+2	bbb
+3	ccc
+4	ddd
+#
+# Cleanup
+#  
+DROP DATABASE backup_part;

=== added file 'mysql-test/suite/backup_engines/t/backup_partition.test'
--- a/mysql-test/suite/backup_engines/t/backup_partition.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_engines/t/backup_partition.test	2008-12-05 07:30:27 +0000
@@ -0,0 +1,70 @@
+#
+# This test is designed to test that BACKUP selects the best available
+# driver for partitioned tables. The storage engines should use these
+# drivers:
+#
+#   Partitioned Falcon table      -> Snapshot
+#   Partitioned InnoDB table      -> Snapshot
+#   All other partitioned tables  -> Default
+#
+
+--source include/have_partition.inc
+--source include/not_embedded.inc
+
+# Find expected backup driver for the current storage engine.
+
+let $exp_drv= Default;
+if (`select @@storage_engine = 'falcon'`) { let $exp_drv= Snapshot; }
+if (`select @@storage_engine = 'innodb'`) { let $exp_drv= Snapshot; }
+
+# Uncomment the line below and run the test with --force flag
+# if you want to verify that expected driver is correct
+#echo $exp_drv;
+
+--echo #
+--echo # Creating databases
+--echo #
+CREATE DATABASE backup_part;
+
+CREATE TABLE backup_part.t1 (
+  t1_autoinc INTEGER NOT NULL AUTO_INCREMENT,
+  t1_uuid CHAR(36),
+  PRIMARY KEY (t1_autoinc))
+PARTITION BY HASH (t1_autoinc);
+
+INSERT INTO backup_part.t1(t1_uuid) VALUES ('aaa'),('bbb'),('ccc'),('ddd'); 
+
+--echo # Show content
+SELECT * FROM backup_part.t1 ORDER BY t1_autoinc;
+
+--echo #
+--echo # Perform backup
+--replace_column 1 #
+let $bup_id= `BACKUP DATABASE backup_part TO 'partition.bak'`;
+
+--echo #
+--echo # Show drivers. 
+
+--echo
+# Count of expected driver for this backup_id should be 1
+# Replace exp_drv and backup_id in query because it will vary
+replace_regex /'.*'.*/'FILTERED DRIVER' AND backup_id=FILTERED ID/ ;
+--eval SELECT count(*) FROM mysql.backup_history WHERE drivers LIKE '$exp_drv' AND
backup_id=$bup_id
+--echo
+
+--echo #
+--echo # Restore and show content
+--echo #  
+
+--replace_column 1 #
+RESTORE FROM 'partition.bak' OVERWRITE;
+--echo
+SELECT * FROM backup_part.t1 ORDER BY t1_autoinc;
+
+--echo #
+--echo # Cleanup
+--echo #  
+
+DROP DATABASE backup_part;
+
+--remove_file $MYSQLTEST_VARDIR/master-data/partition.bak

=== renamed file 'mysql-test/suite/funcs_1/r/is_collation_charset_applic.result' =>
'mysql-test/suite/funcs_1/r/is_collation_character_set_applicability.result'
=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_1011ext.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_1011ext.result	2008-06-02 19:57:11 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_1011ext.result	2008-10-13 07:01:21 +0000
@@ -363,7 +363,7 @@ create table t4 (f4 tinyint) engine = <e
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `f1` int(11) default NULL
+  `f1` int(11) DEFAULT NULL
 ) ENGINE=<engine_to_be_used> DEFAULT CHARSET=latin1
 insert into t1 values (1);
 create trigger tr1 after insert on t1
@@ -375,7 +375,7 @@ for each row insert into t4 (f4) values 
 set autocommit=0;
 start transaction;
 insert into t1 values (1);
-ERROR 22003: Out of range value adjusted for column 'f4' at row 1
+ERROR 22003: Out of range value for column 'f4' at row 1
 commit;
 select * from t1 order by f1;
 f1

=== modified file 'mysql-test/suite/funcs_1/t/disabled.def'
--- a/mysql-test/suite/funcs_1/t/disabled.def	2008-07-23 08:52:08 +0000
+++ b/mysql-test/suite/funcs_1/t/disabled.def	2008-12-09 18:59:54 +0000
@@ -10,4 +10,5 @@
 #
 ##############################################################################
 
-ndb_trig_1011ext:  Bug#32656 NDB: Duplicate key error aborts transaction in handler.
Doesn't talk back to SQL
+ndb_storedproc:		Something's not right in the test... also this test does not exist in
5.1
+ndb_views:		Bug #40860 funcs_1.ndb_views fail

=== renamed file 'mysql-test/suite/funcs_1/t/is_collation_charset_applic.test' =>
'mysql-test/suite/funcs_1/t/is_collation_character_set_applicability.test'
=== modified file 'mysql-test/suite/ndb/r/ndb_alter_table_online.result'
--- a/mysql-test/suite/ndb/r/ndb_alter_table_online.result	2008-08-18 05:43:50 +0000
+++ b/mysql-test/suite/ndb/r/ndb_alter_table_online.result	2008-12-13 11:02:16 +0000
@@ -672,62 +672,14 @@ CREATE TABLE t1
 ENGINE=NDB;
 Warnings:
 Warning	1478	Row format FIXED incompatible with dynamic attribute b
--- t1 --
-Version: #
-Fragment type: 5
-K Value: 6
-Min load factor: 78
-Max load factor: 80
-Temporary table: no
-Number of attributes: 2
-Number of primary keys: 1
-Length of frm data: (compressed frm size)
-Row Checksum: 1
-Row GCI: 1
-SingleUserMode: 0
-ForceVarPart: 0
-TableStatus: Retrieved
--- Attributes -- 
 pk1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Int NULL AT=FIXED ST=MEMORY DYNAMIC
-
--- Indexes -- 
-PRIMARY KEY(pk1) - UniqueHashIndex
-PRIMARY(pk1) - OrderedIndex
-
-
-NDBT_ProgramExit: 0 - OK
-
 DROP TABLE t1;
 CREATE TABLE t1
 (pk1 INT NOT NULL COLUMN_FORMAT FIXED PRIMARY KEY, 
 b INT COLUMN_FORMAT FIXED)ROW_FORMAT=DYNAMIC ENGINE=NDB;
--- t1 --
-Version: #
-Fragment type: 5
-K Value: 6
-Min load factor: 78
-Max load factor: 80
-Temporary table: no
-Number of attributes: 2
-Number of primary keys: 1
-Length of frm data: (compressed frm size)
-Row Checksum: 1
-Row GCI: 1
-SingleUserMode: 0
-ForceVarPart: 1
-TableStatus: Retrieved
--- Attributes -- 
 pk1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 b Int NULL AT=FIXED ST=MEMORY
-
--- Indexes -- 
-PRIMARY KEY(pk1) - UniqueHashIndex
-PRIMARY(pk1) - OrderedIndex
-
-
-NDBT_ProgramExit: 0 - OK
-
 ********************
 * Cleanup Section
 ********************

=== modified file 'mysql-test/suite/ndb/r/ndb_alter_table_online2.result'
--- a/mysql-test/suite/ndb/r/ndb_alter_table_online2.result	2007-11-19 12:59:12 +0000
+++ b/mysql-test/suite/ndb/r/ndb_alter_table_online2.result	2008-10-15 12:14:27 +0000
@@ -94,3 +94,4 @@ truncate ndb_show_tables_results;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 drop table t1;
+drop database mysqlslap;

=== modified file 'mysql-test/suite/ndb/r/ndb_basic.result'
--- a/mysql-test/suite/ndb/r/ndb_basic.result	2008-08-16 05:15:49 +0000
+++ b/mysql-test/suite/ndb/r/ndb_basic.result	2008-10-15 12:14:27 +0000
@@ -924,4 +924,24 @@ create table if not exists t1 (a int not
 create table t2 like t1;
 rename table t1 to t10, t2 to t20;
 drop table t10,t20;
+#
+# bug #39872 - explain causes segv
+# (ndb_index_stat_enable=1 must be set to trigger bug)
+#
+set ndb_index_stat_enable=1;
+CREATE TABLE `t1` (
+`id` int(11) NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (`id`)
+) ENGINE=ndbcluster DEFAULT CHARSET=utf8;
+CREATE TABLE `t2` (
+`id` int(11) NOT NULL,
+`obj_id` int(11) DEFAULT NULL,
+UNIQUE KEY `id` (`id`),
+KEY `obj_id` (`obj_id`)
+) ENGINE=ndbcluster DEFAULT CHARSET=utf8;
+# here we used to segv
+explain SELECT t1.id FROM t1 INNER JOIN t2 ON t1.id = t2.id WHERE t2.obj_id=1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const
tables
+drop table t1, t2;
 End of 5.1 tests

=== modified file 'mysql-test/suite/ndb/r/ndb_cache.result'
--- a/mysql-test/suite/ndb/r/ndb_cache.result	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/ndb/r/ndb_cache.result	2008-10-21 22:53:32 +0000
@@ -188,4 +188,183 @@ drop table t1;
 show status like "Qcache_queries_in_cache";
 Variable_name	Value
 Qcache_queries_in_cache	0
+reset query cache;
+flush status;
+create table t1 (a int primary key,
+b text,
+c int,
+key(c))
+engine=ndb;
+insert into t1 values (1,'Alexandra', 1), (2,'Palace', 2);
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	0
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	0
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	0
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 order by a;
+a	b	c
+1	Alexandra	1
+2	Palace	2
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	1
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	1
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	0
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 order by a;
+a	b	c
+1	Alexandra	1
+2	Palace	2
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	1
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	1
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	1
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 force index(c) where c < 2 order by c;
+a	b	c
+1	Alexandra	1
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	2
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	2
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	1
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 force index(c) where c < 2 order by c;
+a	b	c
+1	Alexandra	1
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	2
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	2
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	2
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+drop table t1;
+CREATE LOGFILE GROUP lfg
+ADD UNDOFILE 'myundo.log'
+INITIAL_SIZE 16M
+UNDO_BUFFER_SIZE = 1M
+ENGINE=NDB;
+CREATE TABLESPACE tbsp
+ADD DATAFILE 'mydatafile.fil'
+USE LOGFILE GROUP lfg
+INITIAL_SIZE 12M
+ENGINE=NDB;
+create table t1 (a int primary key,
+b text,
+c int,
+key(c))
+storage disk tablespace tbsp engine ndb;
+insert into t1 values (1,'Alexandra', 1), (2,'Palace', 2);
+reset query cache;
+flush status;
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	0
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	0
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	0
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 order by a;
+a	b	c
+1	Alexandra	1
+2	Palace	2
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	1
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	1
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	0
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 order by a;
+a	b	c
+1	Alexandra	1
+2	Palace	2
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	1
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	1
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	1
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 force index (c) where c < 2 order by c;
+a	b	c
+1	Alexandra	1
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	2
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	2
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	1
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+select * from t1 force index (c) where c < 2 order by c;
+a	b	c
+1	Alexandra	1
+show status like "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	2
+show status like "Qcache_inserts";
+Variable_name	Value
+Qcache_inserts	2
+show status like "Qcache_hits";
+Variable_name	Value
+Qcache_hits	2
+show status like "Qcache_not_cached";
+Variable_name	Value
+Qcache_not_cached	0
+drop table t1;
+alter tablespace tbsp drop datafile 'mydatafile.fil' engine ndb;
+drop tablespace tbsp engine ndb;
+drop logfile group lfg engine ndb;
 SET GLOBAL query_cache_size=0;

=== added file 'mysql-test/suite/ndb/r/ndb_dbug_lock.result'
--- a/mysql-test/suite/ndb/r/ndb_dbug_lock.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_dbug_lock.result	2008-10-29 13:09:15 +0000
@@ -0,0 +1,44 @@
+drop table if exists t1;
+#
+# Test that alter during lock table aborts with error if
+# global schema lock already exists
+#
+create table t1 (a int key) engine ndb row_format dynamic;
+set session debug="+d,sleep_after_global_schema_lock";
+alter table t1 add column (b int);
+lock tables t1 write;
+alter table t1 add column (c int);
+ERROR HY000: Can't execute the given command because you have active locked tables or an
active transaction
+alter table t1 add column (c int);
+ERROR HY000: Can't execute the given command because you have active locked tables or an
active transaction
+alter table t1 add column (c int);
+ERROR HY000: Can't execute the given command because you have active locked tables or an
active transaction
+unlock tables;
+#
+# Test that alter during lock works without global schema lock
+# and that an alter done in parallell test serialized
+#
+lock tables t1 write;
+# delay is still set after lock
+alter table t1 add column (c int);
+# issue alter in parallell, which should be hanging waiting on
+alter table t1 add column (d int);
+# check thread state which should be:
+# "Waiting for allowed to take ndbcluster global schema lock"
+# _not_ "Waiting for ndbcluster global schema lock"
+select state from information_schema.processlist where info = "alter table t1 add column
(d int)";
+state
+Waiting for allowed to take ndbcluster global schema lock
+unlock tables;
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) NOT NULL,
+  `b` int(11) DEFAULT NULL,
+  `c` int(11) DEFAULT NULL,
+  `d` int(11) DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
+# Cleanup
+set session debug="-d,sleep_after_global_schema_lock";
+drop table t1;

=== modified file 'mysql-test/suite/ndb/r/ndb_dd_ddl.result'
--- a/mysql-test/suite/ndb/r/ndb_dd_ddl.result	2008-07-25 18:44:20 +0000
+++ b/mysql-test/suite/ndb/r/ndb_dd_ddl.result	2008-10-17 08:37:23 +0000
@@ -308,6 +308,7 @@ ENGINE = NDB;
 
 DROP USER mysqltest_u1@localhost;
 DROP USER mysqltest_u2@localhost;
+DROP DATABASE mysqltest2;
 
 # -----------------------------------------------------------------
 # End 6.0 test

=== renamed file 'mysql-test/suite/ndb_team/r/ndb_dd_restore_compat.result' =>
'mysql-test/suite/ndb/r/ndb_dd_restore_compat.result'
=== added file 'mysql-test/suite/ndb/r/ndb_discover_db.result'
--- a/mysql-test/suite/ndb/r/ndb_discover_db.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_discover_db.result	2008-09-30 09:14:44 +0000
@@ -0,0 +1,7 @@
+drop database if exists discover_db;
+drop database if exists discover_db_2;
+create database discover_db;
+create table discover_db.t1 (a int key, b int) engine ndb;
+create database discover_db_2;
+alter database discover_db_2 character set binary;
+create table discover_db_2.t1 (a int key, b int) engine ndb;

=== added file 'mysql-test/suite/ndb/r/ndb_discover_db2.result'
--- a/mysql-test/suite/ndb/r/ndb_discover_db2.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_discover_db2.result	2008-09-30 09:14:44 +0000
@@ -0,0 +1,28 @@
+show create database discover_db;
+Database	Create Database
+discover_db	CREATE DATABASE `discover_db` /*!40100 DEFAULT CHARACTER SET latin1 */
+show create database discover_db_2;
+Database	Create Database
+discover_db_2	CREATE DATABASE `discover_db_2` /*!40100 DEFAULT CHARACTER SET binary */
+reset master;
+insert into discover_db.t1 values (1,1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin1.000001	#	Query	102	#	BEGIN
+master-bin1.000001	#	Table_map	102	#	table_id: # (discover_db.t1)
+master-bin1.000001	#	Table_map	102	#	table_id: # (mysql.ndb_apply_status)
+master-bin1.000001	#	Write_rows	102	#	table_id: #
+master-bin1.000001	#	Write_rows	102	#	table_id: # flags: STMT_END_F
+master-bin1.000001	#	Query	102	#	COMMIT
+reset master;
+insert into discover_db_2.t1 values (1,1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin1.000001	#	Query	102	#	BEGIN
+master-bin1.000001	#	Table_map	102	#	table_id: # (discover_db_2.t1)
+master-bin1.000001	#	Table_map	102	#	table_id: # (mysql.ndb_apply_status)
+master-bin1.000001	#	Write_rows	102	#	table_id: #
+master-bin1.000001	#	Write_rows	102	#	table_id: # flags: STMT_END_F
+master-bin1.000001	#	Query	102	#	COMMIT
+drop database discover_db;
+drop database discover_db_2;

=== modified file 'mysql-test/suite/ndb/r/ndb_insert.result'
--- a/mysql-test/suite/ndb/r/ndb_insert.result	2007-11-05 20:11:15 +0000
+++ b/mysql-test/suite/ndb/r/ndb_insert.result	2008-12-10 09:05:07 +0000
@@ -419,8 +419,8 @@ COUNT(*)
 INSERT INTO t1 VALUES (1,1,1);
 ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 INSERT INTO t1 VALUES 
-(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
-(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
+(-1,-1,-1),(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
+(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10),(9999,9999,9999);
 ERROR 23000: Can't write; duplicate key in table 't1'
 select count(*) from t1;
 count(*)
@@ -440,8 +440,7 @@ INSERT INTO t1 VALUES 
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 ERROR 23000: Can't write; duplicate key in table 't1'
-commit;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
+rollback;
 select * from t1 where pk1=1;
 pk1	b	c
 1	1	1
@@ -477,8 +476,13 @@ INSERT INTO t1 VALUES 
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 ERROR 23000: Can't write; duplicate key in table 't1'
+SHOW WARNINGS;
+Level	Code	Message
+Warning	1296	Got error 630 'Tuple already existed when attempting to insert' from NDB
+Error	1022	Can't write; duplicate key in table 't1'
 SELECT * FROM t1 WHERE pk1=10;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
+pk1	b	c
+10	10	10
 rollback;
 select * from t1 where pk1=1;
 pk1	b	c
@@ -498,11 +502,12 @@ INSERT INTO t1 VALUES 
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 ERROR 23000: Can't write; duplicate key in table 't1'
 SELECT * FROM t1 WHERE pk1=10;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
+pk1	b	c
+10	10	10
 SELECT * FROM t1 WHERE pk1=10;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
+pk1	b	c
+10	10	10
 commit;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
 select * from t1 where pk1=1;
 pk1	b	c
 1	1	1
@@ -521,7 +526,6 @@ INSERT INTO t1 VALUES 
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 ERROR 23000: Can't write; duplicate key in table 't1'
 INSERT INTO t1 values (4000, 40, 44);
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
 rollback;
 select * from t1 where pk1=1;
 pk1	b	c

=== modified file 'mysql-test/suite/ndb/r/ndb_single_user.result'
--- a/mysql-test/suite/ndb/r/ndb_single_user.result	2008-07-15 00:06:43 +0000
+++ b/mysql-test/suite/ndb/r/ndb_single_user.result	2008-10-17 08:52:55 +0000
@@ -111,8 +111,7 @@ update t1 set b=b+100 where a=3;
 COMMIT;
 update t1 set b=b+100 where a=4;
 ERROR HY000: Got error 299 'Operation not allowed or aborted due to single user mode'
from NDBCLUSTER
-COMMIT;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
+ROLLBACK;
 create table t2 (a int) engine myisam;
 alter table t2 add column (b int);
 drop table t2;

=== modified file 'mysql-test/suite/ndb/t/ndb_alter_table_online.test'
--- a/mysql-test/suite/ndb/t/ndb_alter_table_online.test	2008-10-15 01:19:02 +0000
+++ b/mysql-test/suite/ndb/t/ndb_alter_table_online.test	2008-12-13 11:02:16 +0000
@@ -708,8 +708,7 @@ CREATE TABLE t1
 (pk1 INT NOT NULL PRIMARY KEY, b INT COLUMN_FORMAT DYNAMIC)ROW_FORMAT=FIXED
 ENGINE=NDB;
 
---replace_regex /Length of frm data: [0-9]+/Length of frm data: (compressed frm
size)//Version: [0-9]+/Version: #/
---exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep 'AT='
 
 DROP TABLE t1;
 
@@ -717,8 +716,7 @@ CREATE TABLE t1
 (pk1 INT NOT NULL COLUMN_FORMAT FIXED PRIMARY KEY, 
 b INT COLUMN_FORMAT FIXED)ROW_FORMAT=DYNAMIC ENGINE=NDB;
 
---replace_regex /Length of frm data: [0-9]+/Length of frm data: (compressed frm
size)//Version: [0-9]+/Version: #/
---exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep 'AT='
 
 --echo ********************
 --echo * Cleanup Section

=== modified file 'mysql-test/suite/ndb/t/ndb_alter_table_online2.test'
--- a/mysql-test/suite/ndb/t/ndb_alter_table_online2.test	2008-04-20 21:25:28 +0000
+++ b/mysql-test/suite/ndb/t/ndb_alter_table_online2.test	2008-10-15 12:14:27 +0000
@@ -166,3 +166,4 @@ truncate ndb_show_tables_results;
 
 # drop the table
 drop table t1;
+drop database mysqlslap;

=== modified file 'mysql-test/suite/ndb/t/ndb_basic.test'
--- a/mysql-test/suite/ndb/t/ndb_basic.test	2007-11-12 12:25:34 +0000
+++ b/mysql-test/suite/ndb/t/ndb_basic.test	2008-10-15 12:14:27 +0000
@@ -858,4 +858,23 @@ create table t2 like t1;
 rename table t1 to t10, t2 to t20;
 drop table t10,t20;
 
+--echo #
+--echo # bug #39872 - explain causes segv
+--echo # (ndb_index_stat_enable=1 must be set to trigger bug)
+--echo #
+set ndb_index_stat_enable=1;
+CREATE TABLE `t1` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`id`)
+) ENGINE=ndbcluster DEFAULT CHARSET=utf8;
+CREATE TABLE `t2` (
+  `id` int(11) NOT NULL,
+  `obj_id` int(11) DEFAULT NULL,
+  UNIQUE KEY `id` (`id`),
+  KEY `obj_id` (`obj_id`)
+) ENGINE=ndbcluster DEFAULT CHARSET=utf8;
+--echo # here we used to segv
+explain SELECT t1.id FROM t1 INNER JOIN t2 ON t1.id = t2.id WHERE t2.obj_id=1;
+drop table t1, t2;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/suite/ndb/t/ndb_cache.test'
--- a/mysql-test/suite/ndb/t/ndb_cache.test	2007-07-04 20:38:53 +0000
+++ b/mysql-test/suite/ndb/t/ndb_cache.test	2008-10-21 22:53:32 +0000
@@ -117,6 +117,132 @@ drop table t1;
 
 show status like "Qcache_queries_in_cache";
 
+# End of 4.1 tests
+
+# Bug#39295 cluster table with TEXT column cannot be cached in query cache
+# Disk table scans and Ordered index scans with locks were resulting
+# in the table's commit_count being incremented, making the query cache
+# ineffective 
+
+reset query cache;
+flush status;
+
+create table t1 (a int primary key,
+                 b text,
+                 c int,
+                 key(c))
+                 engine=ndb;
+
+insert into t1 values (1,'Alexandra', 1), (2,'Palace', 2);
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# Normal, ACC sourced scan #1, should insert in cache
+select * from t1 order by a;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# Normal, ACC sourced scan #2, should hit in cache
+select * from t1 order by a;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# TUX sourced scan #1, should insert in cache
+select * from t1 force index(c) where c < 2 order by c;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# TUX sourced scan #2, should hit in cache
+select * from t1 force index(c) where c < 2 order by c;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+drop table t1;
+
+
+# Now test with TUP-sourced scan with DD
+CREATE LOGFILE GROUP lfg
+ADD UNDOFILE 'myundo.log'
+INITIAL_SIZE 16M
+UNDO_BUFFER_SIZE = 1M
+ENGINE=NDB;
+
+CREATE TABLESPACE tbsp
+ADD DATAFILE 'mydatafile.fil'
+USE LOGFILE GROUP lfg
+INITIAL_SIZE 12M
+ENGINE=NDB;
+
+create table t1 (a int primary key,
+                 b text,
+                 c int,
+                 key(c))
+                 storage disk tablespace tbsp engine ndb;
+
+insert into t1 values (1,'Alexandra', 1), (2,'Palace', 2);
+
+reset query cache;
+flush status;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# Normal, TUP sourced scan #1, should insert in cache
+select * from t1 order by a;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# Normal, TUP sourced scan #2, should hit in cache
+select * from t1 order by a;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# TUX sourced scan #1 should insert in cache
+select * from t1 force index (c) where c < 2 order by c;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# TUX sourced scan #2 should hit in cache
+select * from t1 force index (c) where c < 2 order by c;
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_inserts";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+drop table t1;
+alter tablespace tbsp drop datafile 'mydatafile.fil' engine ndb;
+drop tablespace tbsp engine ndb;
+drop logfile group lfg engine ndb;
+
+# end of tests for bug#39395
+
 SET GLOBAL query_cache_size=0;
 
-# End of 4.1 tests
+

=== modified file 'mysql-test/suite/ndb/t/ndb_cache2.test'
--- a/mysql-test/suite/ndb/t/ndb_cache2.test	2007-07-04 20:38:53 +0000
+++ b/mysql-test/suite/ndb/t/ndb_cache2.test	2008-10-21 22:53:32 +0000
@@ -63,6 +63,9 @@ show status like "Qcache_hits";
 
 # Update the table and make sure the correct data is returned
 update t1 set a1=3 where pk=1;
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
+
 select * from t1;
 show status like "Qcache_inserts";
 show status like "Qcache_hits";
@@ -70,6 +73,9 @@ show status like "Qcache_hits";
 # Insert a new record and make sure the correct data is returned
 insert into t1 value (2, 7, 8, 'Second row');
 insert into t1 value (4, 5, 6, 'Fourth row');
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
+
 select * from t1 order by pk desc;
 show status like "Qcache_inserts";
 show status like "Qcache_hits";
@@ -87,6 +93,8 @@ show status like "Qcache_hits";
 
 # Delete from the table
 delete from t1 where c1='Fourth row';
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
 show status like "Qcache_queries_in_cache";
 select * from t1 where b1=3;
 show status like "Qcache_hits";
@@ -101,6 +109,9 @@ show status like "Qcache_hits";
 
 # Update the table and switch to other connection
 update t1 set a1=4 where b1=3;
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
+
 connect (con2,localhost,root,,);
 connection con2;
 use test;
@@ -133,6 +144,8 @@ connection con1;
 flush status;
 begin;
 update t1 set a1=5 where pk=1;
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
 show status like "Qcache_queries_in_cache";
 show status like "Qcache_inserts";
 show status like "Qcache_hits";
@@ -166,6 +179,8 @@ connection con1;
 flush status;
 begin;
 update t1 set a1=6 where pk=1;
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
 show status like "Qcache_queries_in_cache";
 show status like "Qcache_inserts";
 show status like "Qcache_hits";
@@ -207,6 +222,8 @@ connection con1;
 flush status;
 begin;
 insert into t1 set pk=5, a1=6, b1=3, c1="New row";
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
 show status like "Qcache_queries_in_cache";
 show status like "Qcache_inserts";
 show status like "Qcache_hits";
@@ -245,6 +262,8 @@ connection con1;
 flush status;
 begin;
 delete from t1 where pk=2;
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
 show status like "Qcache_queries_in_cache";
 show status like "Qcache_inserts";
 show status like "Qcache_hits";
@@ -287,6 +306,8 @@ update t2 set a2=9 where pk=1;
 update t3 set a3=9 where pk=1;
 update t4 set a4=9 where a4=2;
 update t5 set a5=9 where pk=1;
+# Sleep to give Qcache thread time to detect change
+--real_sleep 1
 show status like "Qcache_queries_in_cache";
 show status like "Qcache_inserts";
 show status like "Qcache_hits";

=== added file 'mysql-test/suite/ndb/t/ndb_dbug_lock.test'
--- a/mysql-test/suite/ndb/t/ndb_dbug_lock.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_dbug_lock.test	2008-11-06 18:54:30 +0000
@@ -0,0 +1,71 @@
+-- source include/have_ndb.inc
+# We are using some debug-only features in this test
+--source include/have_debug.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+--connect (another_con, localhost, root,,)
+--connect (yet_another_con, localhost, root,,)
+
+--echo #
+--echo # Test that alter during lock table aborts with error if
+--echo # global schema lock already exists
+--echo #
+--connection default
+create table t1 (a int key) engine ndb row_format dynamic;
+# delay after lock
+set session debug="+d,sleep_after_global_schema_lock";
+--send alter table t1 add column (b int)
+--sleep 2
+
+--connection another_con
+lock tables t1 write;
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+alter table t1 add column (c int);
+# make sure it continues to block
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+alter table t1 add column (c int);
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+alter table t1 add column (c int);
+unlock tables;
+
+--connection default
+--reap
+
+--echo #
+--echo # Test that alter during lock works without global schema lock
+--echo # and that an alter done in parallell test serialized
+--echo #
+--connection default
+lock tables t1 write;
+--echo # delay is still set after lock
+--send alter table t1 add column (c int)
+--sleep 2
+
+--echo # issue alter in parallell, which should be hanging waiting on
+--connection another_con
+--send alter table t1 add column (d int)
+--sleep 1
+
+--echo # check thread state which should be:
+--echo # "Waiting for allowed to take ndbcluster global schema lock"
+--echo # _not_ "Waiting for ndbcluster global schema lock"
+--connection yet_another_con
+select state from information_schema.processlist where info = "alter table t1 add column
(d int)";
+
+# wait for alter to complete
+--connection default
+--reap
+unlock tables;
+
+--connection another_con
+--reap
+
+show create table t1;
+
+--echo # Cleanup
+--connection default
+set session debug="-d,sleep_after_global_schema_lock";
+drop table t1;

=== modified file 'mysql-test/suite/ndb/t/ndb_dd_ddl.test'
--- a/mysql-test/suite/ndb/t/ndb_dd_ddl.test	2008-07-24 07:44:21 +0000
+++ b/mysql-test/suite/ndb/t/ndb_dd_ddl.test	2008-10-17 08:37:23 +0000
@@ -463,6 +463,8 @@ ENGINE = NDB;
 DROP USER mysqltest_u1@localhost;
 DROP USER mysqltest_u2@localhost;
 
+DROP DATABASE mysqltest2;
+
 --echo
 --echo # -----------------------------------------------------------------
 --echo # End 6.0 test

=== modified file 'mysql-test/suite/ndb/t/ndb_dd_dump.test'
--- a/mysql-test/suite/ndb/t/ndb_dd_dump.test	2008-09-04 09:22:16 +0000
+++ b/mysql-test/suite/ndb/t/ndb_dd_dump.test	2008-12-09 14:22:54 +0000
@@ -259,6 +259,7 @@ CREATE TABLE test.t (
 
  SELECT count(*) FROM test.t;
  LOAD DATA INFILE 't_backup' INTO TABLE test.t;
+ --remove_file $MYSQLTEST_VARDIR/master-data/test/t_backup
 
  SELECT * FROM test.t order by a;
 

=== renamed file 'mysql-test/suite/ndb_team/t/ndb_dd_restore_compat.test' =>
'mysql-test/suite/ndb/t/ndb_dd_restore_compat.test'
=== added file 'mysql-test/suite/ndb/t/ndb_discover_db.test'
--- a/mysql-test/suite/ndb/t/ndb_discover_db.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_discover_db.test	2008-09-30 09:14:44 +0000
@@ -0,0 +1,33 @@
+-- source include/have_multi_ndb.inc
+-- source include/have_binlog_format_mixed_or_row.inc
+
+-- disable_warnings
+drop database if exists discover_db;
+drop database if exists discover_db_2;
+-- enable_warnings
+
+#
+# Prepare for testing database discovery by creating
+# databases, and removing them on one mysqld
+# The discovery happens in ndb_discover_db2.test
+#
+
+# check that created database is discovered
+create database discover_db;
+create table discover_db.t1 (a int key, b int) engine ndb;
+
+# check that altered database is discovered
+create database discover_db_2;
+alter database discover_db_2 character set binary;
+create table discover_db_2.t1 (a int key, b int) engine ndb;
+
+-- remove_file $MYSQLTEST_VARDIR/master1-data/discover_db/t1.frm
+-- remove_file $MYSQLTEST_VARDIR/master1-data/discover_db/t1.ndb
+-- remove_file $MYSQLTEST_VARDIR/master1-data/discover_db/db.opt
+-- rmdir $MYSQLTEST_VARDIR/master1-data/discover_db
+
+-- remove_file $MYSQLTEST_VARDIR/master1-data/discover_db_2/t1.frm
+-- remove_file $MYSQLTEST_VARDIR/master1-data/discover_db_2/t1.ndb
+-- remove_file $MYSQLTEST_VARDIR/master1-data/discover_db_2/db.opt
+-- rmdir $MYSQLTEST_VARDIR/master1-data/discover_db_2
+

=== added file 'mysql-test/suite/ndb/t/ndb_discover_db2-master.opt'
--- a/mysql-test/suite/ndb/t/ndb_discover_db2-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_discover_db2-master.opt	2008-09-30 09:14:44 +0000
@@ -0,0 +1 @@
+--skip-external-locking

=== added file 'mysql-test/suite/ndb/t/ndb_discover_db2.test'
--- a/mysql-test/suite/ndb/t/ndb_discover_db2.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_discover_db2.test	2008-09-30 09:14:44 +0000
@@ -0,0 +1,21 @@
+-- source include/have_multi_ndb.inc
+-- source include/have_binlog_format_mixed_or_row.inc
+
+#
+# When this test started there no database on disk for server2
+# Check that table has been discovered correctly, and that the
+# binlog is updated correctly
+#
+
+-- connection server2
+show create database discover_db;
+show create database discover_db_2;
+reset master;
+insert into discover_db.t1 values (1,1);
+--source include/show_binlog_events2.inc
+reset master;
+insert into discover_db_2.t1 values (1,1);
+--source include/show_binlog_events2.inc
+
+drop database discover_db;
+drop database discover_db_2;

=== modified file 'mysql-test/suite/ndb/t/ndb_insert.test'
--- a/mysql-test/suite/ndb/t/ndb_insert.test	2007-11-05 20:11:15 +0000
+++ b/mysql-test/suite/ndb/t/ndb_insert.test	2008-10-15 12:24:10 +0000
@@ -438,8 +438,8 @@ INSERT INTO t1 VALUES (1,1,1);
 
 --error 1022
 INSERT INTO t1 VALUES 
-(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
-(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
+(-1,-1,-1),(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
+(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10),(9999,9999,9999);
 
 select count(*) from t1;
 
@@ -465,8 +465,7 @@ INSERT INTO t1 VALUES 
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 
---error 1296
-commit;
+rollback;
 
 select * from t1 where pk1=1;
 select * from t1 where pk1=10;
@@ -503,9 +502,13 @@ begin;
 INSERT INTO t1 VALUES 
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
---error 1296
+# check that we get a warning that transaction has rolled back
+SHOW WARNINGS;
+
+# transaction has rolled back, no error
 SELECT * FROM t1 WHERE pk1=10;
 
+# transaction has rolled back, no error
 rollback;
 
 select * from t1 where pk1=1;
@@ -525,13 +528,13 @@ INSERT INTO t1 VALUES 
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 
---error 1296
+# transaction has rolled back, no error
 SELECT * FROM t1 WHERE pk1=10;
 
---error 1296
+# transaction has rolled back, no error
 SELECT * FROM t1 WHERE pk1=10;
 
---error 1296
+# transaction has rolled back, no error
 commit;
 
 select * from t1 where pk1=1;
@@ -551,9 +554,10 @@ INSERT INTO t1 VALUES 
 (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
 (6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10);
 
---error 1296
+# transaction has rolled back, no error
 INSERT INTO t1 values (4000, 40, 44);
 
+# transaction has rolled back, no error
 rollback;
 
 select * from t1 where pk1=1;

=== modified file 'mysql-test/suite/ndb/t/ndb_single_user.test'
--- a/mysql-test/suite/ndb/t/ndb_single_user.test	2007-07-14 17:35:43 +0000
+++ b/mysql-test/suite/ndb/t/ndb_single_user.test	2008-10-15 12:24:10 +0000
@@ -150,8 +150,7 @@ COMMIT;
 --connection server2
 --error 1296
 update t1 set b=b+100 where a=4;
---error 1296
-COMMIT;
+ROLLBACK;
 
 # Bug #25275 SINGLE USER MODE prevents ALTER on non-ndb
 # tables for other mysqld nodes

=== added file 'mysql-test/suite/ndb_binlog/t/ndb_binlog_restore-master.opt'
--- a/mysql-test/suite/ndb_binlog/t/ndb_binlog_restore-master.opt	1970-01-01 00:00:00
+0000
+++ b/mysql-test/suite/ndb_binlog/t/ndb_binlog_restore-master.opt	2008-11-20 17:19:02
+0000
@@ -0,0 +1,2 @@
+--lower_case_table_names=0
+

=== modified file 'mysql-test/suite/ndb_team/r/ndb_autodiscover3.result'
--- a/mysql-test/suite/ndb_team/r/ndb_autodiscover3.result	2007-09-05 17:13:36 +0000
+++ b/mysql-test/suite/ndb_team/r/ndb_autodiscover3.result	2008-10-15 12:24:10 +0000
@@ -4,8 +4,7 @@ begin;
 insert into t1 values (1);
 insert into t1 values (2);
 ERROR HY000: Got temporary error 4025 'Node failure caused abort of transaction' from
NDBCLUSTER
-commit;
-ERROR HY000: Got error 4350 'Transaction already aborted' from NDBCLUSTER
+rollback;
 drop table t1;
 create table t2 (a int, b int, primary key(a,b)) engine=ndbcluster;
 insert into t2 values (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1);

=== modified file 'mysql-test/suite/ndb_team/t/ndb_autodiscover3.test'
--- a/mysql-test/suite/ndb_team/t/ndb_autodiscover3.test	2008-03-14 12:37:00 +0000
+++ b/mysql-test/suite/ndb_team/t/ndb_autodiscover3.test	2008-10-17 08:52:55 +0000
@@ -39,8 +39,7 @@ insert into t1 values (1);
 --connection server1
 --error 1297
 insert into t1 values (2);
---error 1296
-commit;
+rollback;
 
 drop table t1;
 

=== modified file 'mysql-test/suite/parts/r/partition_engine_ndb.result'
--- a/mysql-test/suite/parts/r/partition_engine_ndb.result	2008-11-04 11:30:00 +0000
+++ b/mysql-test/suite/parts/r/partition_engine_ndb.result	2008-12-09 18:59:54 +0000
@@ -213,7 +213,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -670,7 +670,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -1131,7 +1131,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -1655,7 +1655,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -2155,7 +2155,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -2616,7 +2616,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -3074,7 +3074,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -3535,7 +3535,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;
@@ -3999,7 +3999,7 @@ ERROR 22012: Division by 0
 COMMIT;
 	
 # check transactions-8 success: 	1
-# INFO: Storage engine used for t1 seems to be unable to revert
+# INFO: Storage engine used for t1 seems to be able to revert
 #       changes made by the failing statement.
 SET @@session.sql_mode = '';
 SET AUTOCOMMIT= 1;

=== modified file 'mysql-test/suite/rpl/r/rpl_heartbeat.result'
--- a/mysql-test/suite/rpl/r/rpl_heartbeat.result	2008-06-04 08:40:49 +0000
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat.result	2008-10-17 12:28:40 +0000
@@ -11,13 +11,13 @@ Variable_name	Slave_heartbeat_period
 Value	5.000
 change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root',
master_heartbeat_period= 0.0009999;
 Warnings:
-Warning	1671	The requested value for the heartbeat period  is less than 1 msec.  The
period is reset to zero which means no heartbeats will be sending
+Warning	1672	The requested value for the heartbeat period  is less than 1 msec.  The
period is reset to zero which means no heartbeats will be sending
 show status like 'Slave_heartbeat_period';;
 Variable_name	Slave_heartbeat_period
 Value	0.000
 change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root',
master_heartbeat_period= 4294967;
 Warnings:
-Warning	1671	The requested value for the heartbeat period  exceeds the value of
`slave_net_timeout' sec.  A sensible value for the period should be less than the
timeout.
+Warning	1672	The requested value for the heartbeat period  exceeds the value of
`slave_net_timeout' sec.  A sensible value for the period should be less than the
timeout.
 show status like 'Slave_heartbeat_period';;
 Variable_name	Slave_heartbeat_period
 Value	4294967.000
@@ -29,7 +29,7 @@ reset slave;
 set @@global.slave_net_timeout= 5;
 change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root',
master_heartbeat_period= 5.001;
 Warnings:
-Warning	1671	The requested value for the heartbeat period  exceeds the value of
`slave_net_timeout' sec.  A sensible value for the period should be less than the
timeout.
+Warning	1672	The requested value for the heartbeat period  exceeds the value of
`slave_net_timeout' sec.  A sensible value for the period should be less than the
timeout.
 show status like 'Slave_heartbeat_period';;
 Variable_name	Slave_heartbeat_period
 Value	5.001
@@ -41,7 +41,7 @@ Variable_name	Slave_heartbeat_period
 Value	4.000
 set @@global.slave_net_timeout= 3 /* must be a warning */;
 Warnings:
-Warning	1671	The currect value for master_heartbeat_period exceeds the new value of
`slave_net_timeout' sec. A sensible value for the period should be less than the timeout.
+Warning	1672	The currect value for master_heartbeat_period exceeds the new value of
`slave_net_timeout' sec. A sensible value for the period should be less than the timeout.
 reset slave;
 drop table if exists t1;
 set @@global.slave_net_timeout= 10;

=== modified file 'mysql-test/suite/rpl/r/rpl_locktrans_innodb.result'
--- a/mysql-test/suite/rpl/r/rpl_locktrans_innodb.result	2008-06-26 18:56:36 +0000
+++ b/mysql-test/suite/rpl/r/rpl_locktrans_innodb.result	2008-10-17 12:28:40 +0000
@@ -101,12 +101,12 @@ ERROR 42000: You have an error in your S
 # Implicit lock method conversion due to mix in statement.
 LOCK TABLE t1 READ, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 't2'
+Warning	1616	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 # Lock t1 share (converted to read), t2 write.
 LOCK TABLE t1 IN SHARE MODE, t2 WRITE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 't1'
+Warning	1616	Converted to non-transactional lock on 't1'
 # Show t1 is read locked, t2 write locked.
 INSERT INTO t1 SELECT * FROM t2;
 ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
@@ -117,8 +117,8 @@ INSERT INTO t2 SELECT * FROM t1;
 # Lock t1 exclusive (converted to write), t2 share (converted to read).
 LOCK TABLE t1 IN EXCLUSIVE MODE, t2 IN SHARE MODE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 't1'
-Warning	1615	Converted to non-transactional lock on 't2'
+Warning	1616	Converted to non-transactional lock on 't1'
+Warning	1616	Converted to non-transactional lock on 't2'
 # Show t1 is write locked, t2 read locked.
 INSERT INTO t1 SELECT * FROM t2;
 INSERT INTO t2 SELECT * FROM t1;
@@ -142,8 +142,8 @@ ERROR HY000: Cannot convert to non-trans
 ## Error is reported on first table only. Show both errors:
 SHOW WARNINGS;
 Level	Code	Message
-Error	1616	Cannot convert to non-transactional lock in strict mode on 't1'
-Error	1616	Cannot convert to non-transactional lock in strict mode on 't2'
+Error	1617	Cannot convert to non-transactional lock in strict mode on 't1'
+Error	1617	Cannot convert to non-transactional lock in strict mode on 't2'
 UNLOCK TABLES;
 SET @@SQL_MODE= @wl3561_save_sql_mode;
 #
@@ -163,7 +163,7 @@ CREATE TABLE t4 (c4 INT) ENGINE= MyISAM;
 # Request a transactional lock, which is converted to non-transactional.
 LOCK TABLE t4 IN SHARE MODE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 't4'
+Warning	1616	Converted to non-transactional lock on 't4'
 # Try a conflict with the existing non-transactional lock.
 INSERT INTO t4 VALUES(444);
 ERROR HY000: Table 't4' was locked with a READ lock and can't be updated
@@ -180,8 +180,8 @@ CREATE VIEW v1 AS SELECT * FROM t3, t4 W
 # Request a share lock on the view, which is converted to read locks.
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 't3'
-Warning	1615	Converted to non-transactional lock on 't4'
+Warning	1616	Converted to non-transactional lock on 't3'
+Warning	1616	Converted to non-transactional lock on 't4'
 # Show that read locks on the base tables prohibit writing ...
 INSERT INTO t3 SELECT * FROM t4;
 ERROR HY000: Table 't3' was locked with a READ lock and can't be updated
@@ -197,7 +197,7 @@ COUNT(*)
 ## Report conversion on view due to existing non-transactional locks.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 'v1'
+Warning	1616	Converted to non-transactional lock on 'v1'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);
@@ -206,8 +206,8 @@ UNLOCK TABLES;
 ## Now report conversion on base table again.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1615	Converted to non-transactional lock on 't3'
-Warning	1615	Converted to non-transactional lock on 't4'
+Warning	1616	Converted to non-transactional lock on 't3'
+Warning	1616	Converted to non-transactional lock on 't4'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);

=== modified file 'mysql-test/suite/rpl/t/rpl_row_basic_2myisam.test'
--- a/mysql-test/suite/rpl/t/rpl_row_basic_2myisam.test	2007-06-27 12:29:10 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_basic_2myisam.test	2008-11-24 18:51:19 +0000
@@ -4,3 +4,4 @@
 let $type= 'MYISAM' ;
 let $extra_index= ;
 -- source extra/rpl_tests/rpl_row_basic.test
+-- source extra/rpl_tests/rpl_row_basic_no_pk.test

=== modified file 'mysql-test/suite/rpl/t/rpl_row_basic_3innodb.test'
--- a/mysql-test/suite/rpl/t/rpl_row_basic_3innodb.test	2007-06-27 12:29:10 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_basic_3innodb.test	2008-11-24 18:51:19 +0000
@@ -5,4 +5,4 @@
 let $type= 'INNODB' ;
 let $extra_index= ;
 -- source extra/rpl_tests/rpl_row_basic.test
-
+-- source extra/rpl_tests/rpl_row_basic_no_pk.test

=== renamed file 'mysql-test/suite/rpl_ndb_big/r/rpl_ndb_add_column.result' =>
'mysql-test/suite/rpl_ndb/r/rpl_ndb_add_column.result'
=== modified file 'mysql-test/suite/rpl_ndb/t/disabled.def'
--- a/mysql-test/suite/rpl_ndb/t/disabled.def	2008-12-11 17:29:35 +0000
+++ b/mysql-test/suite/rpl_ndb/t/disabled.def	2008-12-13 11:02:16 +0000
@@ -12,5 +12,4 @@
 
 # the below testcase have been reworked to avoid the bug, test contains comment, keep bug
open
 
-rpl_ndb_innodb2ndb      : Bug#34725 2008-02-26 hakank Currently failing.
 rpl_ndb_extraCol	: Bug#41369 2008-12-10 alik

=== renamed file 'mysql-test/suite/rpl_ndb_big/t/rpl_ndb_add_column.test' =>
'mysql-test/suite/rpl_ndb/t/rpl_ndb_add_column.test'
=== modified file 'mysql-test/suite/rpl_ndb_big/r/rpl_ndb_apply_status.result'
--- a/mysql-test/suite/rpl_ndb_big/r/rpl_ndb_apply_status.result	2008-10-15 01:19:02 +0000
+++ b/mysql-test/suite/rpl_ndb_big/r/rpl_ndb_apply_status.result	2008-12-13 11:02:16 +0000
@@ -12,7 +12,7 @@ count(*)
 create table t1 (a int key, b int) engine ndb;
 insert into t1 values (1,1);
 *** on master it should be empty ***
-select * from mysql.ndb_apply_status;
+select * from mysql.ndb_apply_status where server_id <> 0;
 server_id	epoch	log_name	start_pos	end_pos
 *** on slave there should be one row ***
 select count(*) from mysql.ndb_apply_status;

=== modified file 'mysql-test/suite/rpl_ndb_big/r/rpl_row_basic_7ndb.result'
--- a/mysql-test/suite/rpl_ndb_big/r/rpl_row_basic_7ndb.result	2008-12-08 21:15:06 +0000
+++ b/mysql-test/suite/rpl_ndb_big/r/rpl_row_basic_7ndb.result	2008-12-13 11:02:16 +0000
@@ -527,115 +527,3 @@ ERROR 23000: Duplicate entry '10' for ke
 INSERT INTO t1 VALUES (4);
 Comparing tables master:test.t1 and slave:test.t1
 drop table t1;
-DROP TABLE IF EXISTS t1, t2;
-CREATE TABLE t1 (
-`pk` int(11) NOT NULL AUTO_INCREMENT,
-`int_nokey` int(11) NOT NULL,
-`int_key` int(11) NOT NULL,
-`date_key` date NOT NULL,
-`date_nokey` date NOT NULL,
-`time_key` time NOT NULL,
-`time_nokey` time NOT NULL,
-`datetime_key` datetime NOT NULL,
-`datetime_nokey` datetime NOT NULL,
-`varchar_key` varchar(1) NOT NULL,
-`varchar_nokey` varchar(1) NOT NULL,
-PRIMARY KEY (`pk`),
-KEY `int_key` (`int_key`),
-KEY `date_key` (`date_key`),
-KEY `time_key` (`time_key`),
-KEY `datetime_key` (`datetime_key`),
-KEY `varchar_key` (`varchar_key`)
-) ENGINE='NDB' ;
-INSERT INTO t1 VALUES (1,8,5,'0000-00-00','0000-00-00','10:37:38','10:37:38','0000-00-00
00:00:00','0000-00-00
00:00:00','p','p'),(2,0,9,'0000-00-00','0000-00-00','00:00:00','00:00:00','2007-10-14
00:00:00','2007-10-14 00:00:00','d','d');
-CREATE TABLE t2 (
-`pk` int(11) NOT NULL AUTO_INCREMENT,
-`int_nokey` int(11) NOT NULL,
-`int_key` int(11) NOT NULL,
-`date_key` date NOT NULL,
-`date_nokey` date NOT NULL,
-`time_key` time NOT NULL,
-`time_nokey` time NOT NULL,
-`datetime_key` datetime NOT NULL,
-`datetime_nokey` datetime NOT NULL,
-`varchar_key` varchar(1) NOT NULL,
-`varchar_nokey` varchar(1) NOT NULL,
-PRIMARY KEY (`pk`),
-KEY `int_key` (`int_key`),
-KEY `date_key` (`date_key`),
-KEY `time_key` (`time_key`),
-KEY `datetime_key` (`datetime_key`),
-KEY `varchar_key` (`varchar_key`)
-) ENGINE='NDB' ;
-INSERT INTO t2 VALUES (1,1,6,'2005-12-23','2005-12-23','02:24:28','02:24:28','0000-00-00
00:00:00','0000-00-00
00:00:00','g','g'),(2,0,3,'2009-09-14','2009-09-14','00:00:00','00:00:00','2000-01-30
16:39:40','2000-01-30
16:39:40','q','q'),(3,0,3,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','c','c'),(4,1,6,'2007-03-29','2007-03-29','15:49:00','15:49:00','0000-00-00
00:00:00','0000-00-00
00:00:00','m','m'),(5,4,0,'2002-12-04','2002-12-04','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','o','o'),(6,9,0,'2005-01-28','2005-01-28','00:00:00','00:00:00','2001-05-18
00:00:00','2001-05-18
00:00:00','w','w'),(7,6,0,'0000-00-00','0000-00-00','06:57:25','06:57:25','0000-00-00
00:00:00','0000-00-00
00:00:00','m','m'),(8,0,0,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00
00:00:00','0000-00-00
00:00:00','z','z'),(9,4,6,'2006-08-15','2006-08-15','00:00:00','00:00:00','2002-04-12
14:44:25','2002-04-12 14:44:25','j',
 'j'),(10,0,5,'2006-12-20','2006-12-20','10:13:53','10:13:53','2008-07-22
00:00:00','2008-07-22
00:00:00','y','y'),(11,9,7,'0000-00-00','0000-00-00','00:00:00','00:00:00','2004-07-05
00:00:00','2004-07-05
00:00:00','{','{'),(12,4,3,'2007-01-26','2007-01-26','23:00:51','23:00:51','2001-05-16
00:00:00','2001-05-16
00:00:00','f','f'),(13,7,0,'2004-03-27','2004-03-27','00:00:00','00:00:00','2005-01-24
03:30:37','2005-01-24
03:30:37','',''),(14,6,0,'2006-07-26','2006-07-26','18:43:57','18:43:57','0000-00-00
00:00:00','0000-00-00
00:00:00','{','{'),(15,0,6,'2000-01-14','2000-01-14','00:00:00','00:00:00','2000-09-21
00:00:00','2000-09-21
00:00:00','o','o'),(16,9,8,'0000-00-00','0000-00-00','21:15:08','21:15:08','0000-00-00
00:00:00','0000-00-00
00:00:00','a','a'),(17,2,0,'2004-10-27','2004-10-27','00:00:00','00:00:00','2004-03-24
22:13:43','2004-03-24
22:13:43','',''),(18,7,4,'0000-00-00','0000-00-00','08:38:27','08:38:27','2002-03-18
19:51:44','2002-03-18 19:51:44','t','t'),(19,5,3
 ,'2008-03-07','2008-03-07','03:29:07','03:29:07','2007-12-01 18:44:44','2007-12-01
18:44:44','t','t'),(20,0,0,'2002-04-09','2002-04-09','16:06:03','16:06:03','2009-04-22
00:00:00','2009-04-22 00:00:00','n','n');
-DELETE FROM t2 WHERE `int_key` < 3 LIMIT 1;
-UPDATE t1 SET `int_key` = 3 ORDER BY `pk` LIMIT 4;
-DELETE FROM t2 WHERE `int_key` < 3 LIMIT 1;
-DELETE FROM t2 WHERE `pk` < 6 LIMIT 1;
-UPDATE t1 SET `int_key` = 6 ORDER BY `pk` LIMIT 3;
-DELETE FROM t2 WHERE `pk` < 6 LIMIT 1;
-UPDATE t1 SET `pk` = 6 ORDER BY `int_key` LIMIT 6;
-ERROR 23000: Duplicate entry '6' for key 'PRIMARY'
-DELETE FROM t2 WHERE `pk` < 7 LIMIT 1;
-UPDATE t1 SET `int_key` = 4 ORDER BY `pk` LIMIT 6;
-*** results: t2 must be consistent ****
-Comparing tables master:test.t2 and master:test.t2
-DROP TABLE t1, t2;
-EOF OF TESTS
-CREATE TABLE t1 (a int) ENGINE='NDB' ;
-INSERT IGNORE INTO t1 VALUES (NULL);
-INSERT INTO t1 ( a ) VALUES ( 0 );
-INSERT INTO t1 ( a ) VALUES ( 9 );
-INSERT INTO t1 ( a ) VALUES ( 2 );
-INSERT INTO t1 ( a ) VALUES ( 9 );
-INSERT INTO t1 ( a ) VALUES ( 5 );
-UPDATE t1 SET a = 5 WHERE a = 9;
-DELETE FROM t1 WHERE a < 6;
-UPDATE t1 SET a = 9 WHERE a < 3;
-INSERT INTO t1 ( a ) VALUES ( 3 );
-UPDATE t1 SET a = 0 WHERE a < 4;
-UPDATE t1 SET a = 8 WHERE a < 5;
-Comparing tables master:test.t1 and slave:test.t1
-drop table t1;
-CREATE TABLE t1 (a bit) ENGINE='NDB' ;
-INSERT IGNORE INTO t1 VALUES (NULL);
-INSERT INTO t1 ( a ) VALUES ( 0 );
-UPDATE t1 SET a = 0 WHERE a = 1 LIMIT 3;
-INSERT INTO t1 ( a ) VALUES ( 5 );
-DELETE FROM t1 WHERE a < 2 LIMIT 4;
-DELETE FROM t1 WHERE a < 9 LIMIT 4;
-INSERT INTO t1 ( a ) VALUES ( 9 );
-UPDATE t1 SET a = 8 WHERE a = 0 LIMIT 6;
-INSERT INTO t1 ( a ) VALUES ( 8 );
-UPDATE t1 SET a = 0 WHERE a < 6 LIMIT 0;
-INSERT INTO t1 ( a ) VALUES ( 4 );
-INSERT INTO t1 ( a ) VALUES ( 3 );
-UPDATE t1 SET a = 0 WHERE a = 7 LIMIT 6;
-DELETE FROM t1 WHERE a = 4 LIMIT 7;
-UPDATE t1 SET a = 9 WHERE a < 2 LIMIT 9;
-UPDATE t1 SET a = 0 WHERE a < 9 LIMIT 2;
-DELETE FROM t1 WHERE a < 0 LIMIT 5;
-INSERT INTO t1 ( a ) VALUES ( 5 );
-UPDATE t1 SET a = 4 WHERE a < 6 LIMIT 4;
-INSERT INTO t1 ( a ) VALUES ( 5 );
-UPDATE t1 SET a = 9 WHERE a < 5 LIMIT 8;
-DELETE FROM t1 WHERE a < 8 LIMIT 8;
-INSERT INTO t1 ( a ) VALUES ( 6 );
-DELETE FROM t1 WHERE a < 6 LIMIT 7;
-UPDATE t1 SET a = 7 WHERE a = 3 LIMIT 7;
-UPDATE t1 SET a = 8 WHERE a = 0 LIMIT 6;
-INSERT INTO t1 ( a ) VALUES ( 7 );
-DELETE FROM t1 WHERE a < 9 LIMIT 4;
-INSERT INTO t1 ( a ) VALUES ( 7 );
-INSERT INTO t1 ( a ) VALUES ( 6 );
-UPDATE t1 SET a = 8 WHERE a = 3 LIMIT 4;
-DELETE FROM t1 WHERE a = 2 LIMIT 9;
-DELETE FROM t1 WHERE a = 1 LIMIT 4;
-UPDATE t1 SET a = 4 WHERE a = 2 LIMIT 7;
-INSERT INTO t1 ( a ) VALUES ( 0 );
-DELETE FROM t1 WHERE a < 3 LIMIT 0;
-UPDATE t1 SET a = 8 WHERE a = 5 LIMIT 2;
-INSERT INTO t1 ( a ) VALUES ( 1 );
-UPDATE t1 SET a = 9 WHERE a < 5 LIMIT 3;
-Comparing tables master:test.t1 and slave:test.t1
-drop table t1;

=== modified file 'mysql-test/suite/rpl_ndb_big/t/disabled.def'
--- a/mysql-test/suite/rpl_ndb_big/t/disabled.def	2008-06-27 12:39:40 +0000
+++ b/mysql-test/suite/rpl_ndb_big/t/disabled.def	2008-12-10 14:32:27 +0000
@@ -10,7 +10,6 @@
 #
 ##############################################################################
 
-# the below testcase have been reworked to avoid the bug, test contains comment, keep bug
open
+rpl_ndb_circular_simplex : Bug#33849 COMMIT event missing in cluster circular
replication.
 
-rpl_ndb_myisam2ndb       : Bug#34725 2008-02-26 hakank Currently failing.
-rpl_ndb_sync             : Bug#34923 2008-02-28 hakank Currently failing.
+# the below testcase have been reworked to avoid the bug, test contains comment, keep bug
open

=== modified file 'mysql-test/suite/rpl_ndb_big/t/rpl_ndb_apply_status.test'
--- a/mysql-test/suite/rpl_ndb_big/t/rpl_ndb_apply_status.test	2008-10-15 01:19:02 +0000
+++ b/mysql-test/suite/rpl_ndb_big/t/rpl_ndb_apply_status.test	2008-12-13 11:02:16 +0000
@@ -32,7 +32,8 @@ connection master;
 create table t1 (a int key, b int) engine ndb;
 insert into t1 values (1,1);
 echo *** on master it should be empty ***;
-select * from mysql.ndb_apply_status;
+#filter away stuff put there with server_id = 0 (from ndb_restore)
+select * from mysql.ndb_apply_status where server_id <> 0;
 
 sync_slave_with_master;
 echo *** on slave there should be one row ***;

=== modified file 'mysql-test/suite/rpl_ndb_big/t/rpl_row_basic_7ndb.test'
--- a/mysql-test/suite/rpl_ndb_big/t/rpl_row_basic_7ndb.test	2008-09-11 08:01:28 +0000
+++ b/mysql-test/suite/rpl_ndb_big/t/rpl_row_basic_7ndb.test	2008-12-09 18:59:54 +0000
@@ -5,4 +5,3 @@
 let $type= 'NDB' ;
 let $extra_index= ;
 -- source extra/rpl_tests/rpl_row_basic.test
--- source include/master-slave-end.inc

=== removed file 'mysql-test/t/innodb_bug34053.test'
--- a/mysql-test/t/innodb_bug34053.test	2008-09-15 21:33:05 +0000
+++ b/mysql-test/t/innodb_bug34053.test	1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
-#
-# Make sure http://bugs.mysql.com/34053 remains fixed.
-#
-
--- source include/not_embedded.inc
--- source include/have_innodb.inc
-
-SET storage_engine=InnoDB;
-
-# we do not really care about what gets printed, we are only
-# interested in getting success or failure according to our
-# expectations
--- disable_query_log
--- disable_result_log
-
-GRANT USAGE ON *.* TO 'shane'@'localhost' IDENTIFIED BY '12345';
-FLUSH PRIVILEGES;
-
--- connect (con1,localhost,shane,12345,)
-
--- connection con1
--- error ER_SPECIFIC_ACCESS_DENIED_ERROR
-CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB;
--- error ER_SPECIFIC_ACCESS_DENIED_ERROR
-CREATE TABLE innodb_mem_validate (a INT) ENGINE=INNODB;
-CREATE TABLE innodb_monitorx (a INT) ENGINE=INNODB;
-DROP TABLE innodb_monitorx;
-CREATE TABLE innodb_monito (a INT) ENGINE=INNODB;
-DROP TABLE innodb_monito;
-CREATE TABLE xinnodb_monitor (a INT) ENGINE=INNODB;
-DROP TABLE xinnodb_monitor;
-CREATE TABLE nnodb_monitor (a INT) ENGINE=INNODB;
-DROP TABLE nnodb_monitor;
-
--- connection default
-CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB;
-CREATE TABLE innodb_mem_validate (a INT) ENGINE=INNODB;
-
--- connection con1
--- error ER_SPECIFIC_ACCESS_DENIED_ERROR
-DROP TABLE innodb_monitor;
--- error ER_SPECIFIC_ACCESS_DENIED_ERROR
-DROP TABLE innodb_mem_validate;
-
--- connection default
-DROP TABLE innodb_monitor;
-DROP TABLE innodb_mem_validate;
-DROP USER 'shane'@'localhost';
-
--- disconnect con1

=== removed file 'mysql-test/t/rpl_slave_exec_mode_basic.test.moved'
--- a/mysql-test/t/rpl_slave_exec_mode_basic.test.moved	2008-10-15 01:19:02 +0000
+++ b/mysql-test/t/rpl_slave_exec_mode_basic.test.moved	1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
-############## mysql-test\t\slave_exec_mode_basic.test #########################
-#                                                                              #
-# Variable Name: slave_exec_mode                                               #
-# Scope: GLOBAL & SESSION                                                      #
-# Access Type: Dynamic                                                         #
-# Data Type: Numeric                                                           #
-# Default Value: 1                                                             #
-# Range: 1 - 65536                                                             #
-#                                                                              #
-#                                                                              #
-# Creation Date: 2008-02-07                                                    #
-# Author:  Rizwan Maredia                                                      #
-#                                                                              #
-# Description: Test Cases of Dynamic System Variable slave_exec_mode           #
-#              that checks the behavior of this variable in the following ways #
-#              * Default Value                                                 #
-#              * Valid & Invalid values                                        #
-#              * Scope & Access method                                         #
-#              * Data Integrity                                                #
-#                                                                              #
-# Reference: http://dev.mysql.com/doc/refman/5.1/en/                           #
-#  server-system-variables.html                                                #
-#                                                                              #
-################################################################################
-
---source include/have_log_bin.inc
---source include/load_sysvars.inc
-
-######################################################################## 
-#                    START OF slave_exec_mode TESTS                    #
-######################################################################## 
-
-
-######################################################################## 
-#     Saving initial value of slave_exec_mode in a temporary variable  #
-######################################################################## 
-SET @start_value = @@global.slave_exec_mode;
---echo 'This variable is not supported in version 5.1.22. It is introduced in 5.1.24'
-
-######################################################################## 
-#                    END OF slave_exec_mode TESTS                      #
-######################################################################## 

=== renamed file 'mysql-test/t/rpl_slave_allow_batching_basic.test.moved' =>
'mysql-test/t/slave_allow_batching_basic.test'
--- a/mysql-test/t/rpl_slave_allow_batching_basic.test.moved	2008-12-11 18:04:55 +0000
+++ b/mysql-test/t/slave_allow_batching_basic.test	2008-12-13 11:02:16 +0000
@@ -23,9 +23,8 @@
 #                                                                              #
 ################################################################################
 
---source include/have_log_bin.inc
+--source include/not_embedded.inc
 --source include/load_sysvars.inc
-
 ######################################################################## 
 #                    START OF slave_allow_batching TESTS               #
 ######################################################################## 
@@ -36,8 +35,7 @@
 ################################################################################ 
 
 SET @global_start_value = @@global.slave_allow_batching;
-
---echo 'Bug: This variable is not supported in mysql version 5.1.22'
+SELECT @global_start_value;
 
 --echo '#--------------------FN_DYNVARS_145_01------------------------#'
 ######################################################################## 
@@ -133,7 +131,6 @@ SELECT count(VARIABLE_VALUE) FROM INFORM
 SELECT IF(@@global.slave_allow_batching, "ON", "OFF") = VARIABLE_VALUE FROM
INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='slave_allow_batching';
 SELECT @@global.slave_allow_batching;
 SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE
VARIABLE_NAME='slave_allow_batching';
---echo 'Bug: value in information schema does not match'
 
 --echo '#---------------------FN_DYNVARS_145_08-------------------------#'
 ################################################################### 

=== renamed file 'mysql-test/t/rpl_slave_compressed_protocol_basic.test.moved' =>
'mysql-test/t/slave_compressed_protocol_basic.test'
=== renamed file 'mysql-test/t/rpl_slave_net_timeout_basic.test.moved' =>
'mysql-test/t/slave_net_timeout_basic.test'
=== modified file 'mysql-test/t/sp-error.test'
--- a/mysql-test/t/sp-error.test	2008-09-30 06:05:34 +0000
+++ b/mysql-test/t/sp-error.test	2008-12-09 14:22:54 +0000
@@ -2460,6 +2460,32 @@ set @@max_sp_recursion_depth = @old_recu
 drop procedure p1;
 
 #
+# Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal)
+#
+
+--disable_warnings
+drop procedure if exists proc_8759;
+--enable_warnings
+
+delimiter $$;
+
+--error ER_SP_BAD_SQLSTATE
+create procedure proc_8759()
+begin
+  declare should_be_illegal condition for sqlstate '00000';
+  declare continue handler for should_be_illegal set @x=0;
+end$$
+
+--error ER_SP_BAD_SQLSTATE
+create procedure proc_8759()
+begin
+  declare continue handler for sqlstate '00000' set @x=0;
+end$$
+
+delimiter ;$$
+
+
+#
 # BUG#NNNN: New bug synopsis
 #
 #--disable_warnings

=== modified file 'mysql-test/t/subselect3.test'
--- a/mysql-test/t/subselect3.test	2008-12-08 21:15:06 +0000
+++ b/mysql-test/t/subselect3.test	2008-12-13 11:02:16 +0000
@@ -662,6 +662,7 @@ DROP TABLE t1;
 create table t1 (a int);
 select 1 as res from dual where (1) in (select * from t1);
 drop table t1;
+
 #
 # BUG#36135 "void Diagnostics_area::set_eof_status(THD*): Assertion `!is_set()' failed."
 #
@@ -718,4 +719,3 @@ select * from t0 where t0.a in (select t
 set join_cache_level=@save_join_cache_level;
 drop table t0, t1;
 
-

=== modified file 'mysys/Makefile.am'
--- a/mysys/Makefile.am	2008-12-08 21:15:06 +0000
+++ b/mysys/Makefile.am	2008-12-13 11:02:16 +0000
@@ -35,7 +35,7 @@ nodist_EXTRA_libmysys_la_SOURCES = dummy
 # creates an unneccesary linking dependency on -lwrap
 noinst_LTLIBRARIES =	libmysyslt.la libmysyswrap.la
 libmysyswrap_la_SOURCES = my_libwrap.c
-noinst_HEADERS =	mysys_priv.h my_static.h my_safehash.h my_handler_errors.h
+noinst_HEADERS =	mysys_priv.h my_static.h my_handler_errors.h my_safehash.h
 libmysyslt_la_SOURCES =	my_init.c my_getwd.c mf_getdate.c my_mmap.c \
 			mf_path.c mf_loadpath.c my_file.c \
 			my_open.c my_create.c my_dup.c my_seek.c my_read.c \
@@ -70,8 +70,8 @@ libmysyslt_la_SOURCES =	my_init.c my_get
 			my_gethostbyname.c rijndael.c my_aes.c sha1.c \
 			my_handler.c my_netware.c my_largepage.c \
 			my_memmem.c stacktrace.c \
-			my_windac.c my_access.c base64.c \
-			wqueue.c
+			my_windac.c my_access.c base64.c my_libwrap.c \
+		        wqueue.c
 if THREAD
 libmysyslt_la_SOURCES+=	thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
 			thr_mutex.c thr_rwlock.c waiting_threads.c
@@ -79,10 +79,6 @@ endif
 EXTRA_DIST =		CMakeLists.txt mf_soundex.c \
 			my_conio.c my_wincond.c my_winthread.c my_winerr.c my_winfile.c
 
-# test_dir_DEPENDENCIES=	$(LIBRARIES)
-# testhash_DEPENDENCIES=	$(LIBRARIES)
-# test_charset_DEPENDENCIES=	$(LIBRARIES)
-# charset2html_DEPENDENCIES=	$(LIBRARIES)
 DEFS =			-DDEFAULT_BASEDIR=\"$(prefix)\" \
 			-DDATADIR="\"$(MYSQLDATAdir)\"" \
 			-DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \
@@ -92,6 +88,5 @@ DEFS =			-DDEFAULT_BASEDIR=\"$(prefix)\"
 			-DDEFAULT_SYSCONFDIR="\"$(sysconfdir)\"" \
                         @DEFS@
 
-
 # Don't update the files from bitkeeper
 %::SCCS/s.%

=== modified file 'mysys/hash.c'
--- a/mysys/hash.c	2008-10-01 17:19:49 +0000
+++ b/mysys/hash.c	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2008-12-11 18:04:55 +0000
+++ b/sql/Makefile.am	2008-12-13 11:02:16 +0000
@@ -79,6 +79,7 @@ noinst_HEADERS =	item.h item_func.h item
 			ha_ndbcluster.h ha_ndbcluster_cond.h \
 			ha_ndbcluster_binlog.h ha_ndbcluster_tables.h \
 			ha_ndbcluster_connection.h ha_ndbcluster_connection.h \
+			ha_ndbcluster_lock_ext.h \
 			ha_partition.h rpl_constants.h \
 			opt_range.h protocol.h rpl_tblmap.h rpl_utility.h \
 			rpl_reporting.h \

=== modified file 'sql/backup/backup_info.cc'
--- a/sql/backup/backup_info.cc	2008-12-04 23:14:30 +0000
+++ b/sql/backup/backup_info.cc	2008-12-10 15:53:06 +0000
@@ -8,6 +8,7 @@
 */
 
 #include "../mysql_priv.h"
+#include "../ha_partition.h"
 
 #include "backup_info.h"
 #include "backup_kernel.h"
@@ -34,6 +35,50 @@ storage_engine_ref get_storage_engine(TH
   if (table)
   {
     se= plugin_ref_to_se_ref(table->s->db_plugin);
+
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+    /*
+      Further check for underlying storage engine is needed
+      if table is partitioned
+    */
+
+    storage_engine_ref se_tmp= NULL;
+
+    if (table->part_info)
+    {
+      partition_info *p_info=  table->part_info;
+      List_iterator<partition_element> p_it(p_info->partitions);
+      partition_element *p_el;
+      
+      while ((p_el= p_it++))
+      {
+        if (!se_tmp)
+        {
+          se_tmp= hton2plugin[p_el->engine_type->slot];
+          ::handlerton *h= se_hton(se_tmp);
+
+          /* 
+             Native drivers don't support partitioning. Let Falcon and
+             InnoDB use Snapshot driver; all other storage engines use
+             Default.
+          */
+          if (h->start_consistent_snapshot == NULL) 
+            goto close; // This is not a Falcon or InnoDB storage engine
+
+          continue;
+        }
+
+        // use Default driver if partitions have different storage engines
+        if (se_tmp != hton2plugin[p_el->engine_type->slot])
+          goto close;
+      };
+      
+      se= se_tmp;
+    }
+#endif
+
+ close:
+  
     ::intern_close_table(table);
     my_free(table, MYF(0));
   }
@@ -87,11 +132,11 @@ Backup_info::find_backup_engine(const ba
 
   // See if table has native backup engine
 
-  storage_engine_ref se= get_storage_engine(m_ctx.m_thd, tbl);
+  storage_engine_ref se= get_storage_engine(m_thd, tbl);
   
   if (!se)
   {
-    m_ctx.fatal_error(ER_NO_STORAGE_ENGINE, tbl.describe(buf));
+    m_log.report_error(ER_NO_STORAGE_ENGINE, tbl.describe(buf));
     DBUG_RETURN(NULL);
   }
   
@@ -126,7 +171,7 @@ Backup_info::find_backup_engine(const ba
   if (!snap)
     if (has_native_backup(se))
     {
-      Native_snapshot *nsnap= new Native_snapshot(m_ctx, se);
+      Native_snapshot *nsnap= new Native_snapshot(m_log, se);
 
       /*
         Check if the snapshot object is valid - in particular has successfully
@@ -175,7 +220,7 @@ Backup_info::find_backup_engine(const ba
   }
 
   if (!snap)
-    m_ctx.fatal_error(ER_BACKUP_NO_BACKUP_DRIVER,tbl.describe(buf));
+    m_log.report_error(ER_BACKUP_NO_BACKUP_DRIVER,tbl.describe(buf));
   
   DBUG_RETURN(snap);
 }
@@ -295,13 +340,16 @@ Backup_info::Dep_node::get_key(const uch
 
 /**
   Create @c Backup_info instance and prepare it for populating with objects.
- 
+  
+  @param[in] log     A logger used to report errors
+  @param[in] thd     THD handle
+
   Snapshots created by the built-in backup engines are added to @c snapshots
   list to be used in the backup engine selection algorithm in 
   @c find_backup_engine().
  */
-Backup_info::Backup_info(Backup_restore_ctx &ctx)
-  :m_ctx(ctx), m_state(Backup_info::ERROR), native_snapshots(8),
+Backup_info::Backup_info(backup::Logger &log, THD *thd)
+  :m_log(log), m_thd(thd), m_state(Backup_info::ERROR), native_snapshots(8),
    m_dep_list(NULL), m_dep_end(NULL), 
    m_srout_end(NULL), m_view_end(NULL), m_trigger_end(NULL), m_event_end(NULL)
 {
@@ -318,7 +366,7 @@ Backup_info::Backup_info(Backup_restore_
                 Dep_node::get_key, Dep_node::free, MYF(0)))
   {
     // Allocation failed. Error has been reported, but not logged to backup logs
-    m_ctx.log_error(ER_OUT_OF_RESOURCES);
+    m_log.log_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
@@ -328,10 +376,10 @@ Backup_info::Backup_info(Backup_restore_
     element on that list, as a "catch all" entry. 
    */
 
-  snap= new Nodata_snapshot(m_ctx);             // logs errors
+  snap= new Nodata_snapshot(m_log);             // logs errors
   if (!snap)
   {
-    m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    m_log.report_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
@@ -341,14 +389,14 @@ Backup_info::Backup_info(Backup_restore_
   if (snapshots.push_back(snap))
   {
     // Allocation failed. Error has been reported, but not logged to backup logs
-    m_ctx.log_error(ER_OUT_OF_RESOURCES);
+    m_log.log_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
-  snap= new CS_snapshot(m_ctx);                 // logs errors
+  snap= new CS_snapshot(m_log);                 // logs errors
   if (!snap)
   {
-    m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    m_log.report_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
@@ -358,14 +406,14 @@ Backup_info::Backup_info(Backup_restore_
   if (snapshots.push_back(snap))
   {
     // Allocation failed. Error has been reported, but not logged to backup logs
-    m_ctx.log_error(ER_OUT_OF_RESOURCES);
+    m_log.log_error(ER_OUT_OF_RESOURCES);
     return;                                   // Error has been logged
   }
 
-  snap= new Default_snapshot(m_ctx);            // logs errors
+  snap= new Default_snapshot(m_log);            // logs errors
   if (!snap)
   {
-    m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    m_log.report_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
@@ -375,7 +423,7 @@ Backup_info::Backup_info(Backup_restore_
   if (snapshots.push_back(snap))
   {
     // Allocation failed. Error has been reported, but not logged to backup logs
-    m_ctx.log_error(ER_OUT_OF_RESOURCES);
+    m_log.log_error(ER_OUT_OF_RESOURCES);
     return;                                   // Error has been logged
   }
 
@@ -417,7 +465,7 @@ int Backup_info::close()
   // report backup drivers used in the image
   
   for (ushort n=0; n < snap_count(); ++n)
-    m_ctx.report_driver(m_snap[n]->name());
+    m_log.report_driver(m_snap[n]->name());
   
   m_state= CLOSED;
   return 0;
@@ -465,7 +513,7 @@ backup::Image_info::Ts* Backup_info::add
 
   if (!ts)
   {
-    m_ctx.fatal_error(ER_BACKUP_CATALOG_ADD_TS, name);
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_TS, name);
     return NULL;
   }
 
@@ -479,7 +527,7 @@ backup::Image_info::Ts* Backup_info::add
 
   if (!n1)
   {
-    m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    m_log.report_error(ER_OUT_OF_RESOURCES);
     return NULL;
   }
 
@@ -513,7 +561,7 @@ backup::Image_info::Db* Backup_info::add
   
   if (!db)
   {
-    m_ctx.fatal_error(ER_BACKUP_CATALOG_ADD_DB, name->ptr());
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_DB, name->ptr());
     return NULL;
   }
 
@@ -550,7 +598,7 @@ int Backup_info::add_dbs(THD *thd, List<
     
     if (is_internal_db_name(&db_name))
     {
-      m_ctx.fatal_error(ER_BACKUP_CANNOT_INCLUDE_DB, db_name.c_ptr());
+      m_log.report_error(ER_BACKUP_CANNOT_INCLUDE_DB, db_name.c_ptr());
       goto error;
     }
     
@@ -589,7 +637,7 @@ int Backup_info::add_dbs(THD *thd, List<
 
   if (!unknown_dbs.is_empty())
   {
-    m_ctx.fatal_error(ER_BAD_DB_ERROR, unknown_dbs.c_ptr());
+    m_log.report_error(ER_BAD_DB_ERROR, unknown_dbs.c_ptr());
     goto error;
   }
 
@@ -614,11 +662,11 @@ int Backup_info::add_all_dbs()
   using namespace obs;
 
   int res= 0;
-  Obj_iterator *dbit= get_databases(m_ctx.m_thd);
+  Obj_iterator *dbit= get_databases(m_thd);
   
   if (!dbit)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DBS);
+    m_log.report_error(ER_BACKUP_LIST_DBS);
     return ERROR;
   }
   
@@ -701,11 +749,11 @@ int Backup_info::add_db_items(Db &db)
 
   // Add tables.
 
-  Obj_iterator *it= get_db_tables(m_ctx.m_thd, &db.name());
+  Obj_iterator *it= get_db_tables(m_thd, &db.name());
 
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_TABLES, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_TABLES, db.name().ptr());
     return ERROR;
   }
   
@@ -731,7 +779,7 @@ int Backup_info::add_db_items(Db &db)
 
     // If this table uses a tablespace, add this tablespace to the catalogue.
 
-    obj= find_tablespace_for_table(m_ctx.m_thd, &db.name(), &tbl->name());
+    obj= find_tablespace_for_table(m_thd, &db.name(), &tbl->name());
 
     if (obj)
     {
@@ -748,11 +796,11 @@ int Backup_info::add_db_items(Db &db)
   // Add other objects.
 
   delete it;  
-  it= get_db_stored_procedures(m_ctx.m_thd, &db.name());
+  it= get_db_stored_procedures(m_thd, &db.name());
   
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_SROUT, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_SROUT, db.name().ptr());
     goto error;
   }
   
@@ -760,11 +808,11 @@ int Backup_info::add_db_items(Db &db)
     goto error;
 
   delete it;
-  it= get_db_stored_functions(m_ctx.m_thd, &db.name());
+  it= get_db_stored_functions(m_thd, &db.name());
 
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_SROUT, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_SROUT, db.name().ptr());
     goto error;
   }
   
@@ -772,11 +820,11 @@ int Backup_info::add_db_items(Db &db)
     goto error;
 
   delete it;
-  it= get_db_views(m_ctx.m_thd, &db.name());
+  it= get_db_views(m_thd, &db.name());
 
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_VIEWS, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_VIEWS, db.name().ptr());
     goto error;
   }
   
@@ -784,11 +832,11 @@ int Backup_info::add_db_items(Db &db)
     goto error;
 
   delete it;
-  it= get_db_events(m_ctx.m_thd, &db.name());
+  it= get_db_events(m_thd, &db.name());
 
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_EVENTS, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_EVENTS, db.name().ptr());
     goto error;
   }
   
@@ -796,11 +844,11 @@ int Backup_info::add_db_items(Db &db)
     goto error;
   
   delete it;
-  it= get_db_triggers(m_ctx.m_thd, &db.name());
+  it= get_db_triggers(m_thd, &db.name());
 
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_TRIGGERS, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_TRIGGERS, db.name().ptr());
     goto error;
   }
   
@@ -808,11 +856,11 @@ int Backup_info::add_db_items(Db &db)
     goto error;
   
   delete it;
-  it= get_all_db_grants(m_ctx.m_thd, &db.name());
+  it= get_all_db_grants(m_thd, &db.name());
 
   if (!it)
   {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_PRIV, db.name().ptr());
+    m_log.report_error(ER_BACKUP_LIST_DB_PRIV, db.name().ptr());
     goto error;
   }
 
@@ -889,8 +937,8 @@ backup::Image_info::Table* Backup_info::
   
   if (!tbl)
   {
-    m_ctx.fatal_error(ER_BACKUP_CATALOG_ADD_TABLE, 
-                      dbi.name().ptr(), t.name().ptr());
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_TABLE, 
+                       dbi.name().ptr(), t.name().ptr());
     return NULL;
   }
 
@@ -943,7 +991,7 @@ int Backup_info::add_view_deps(obs::Obj 
   
   // Get an iterator to iterate over base views of the given one.
 
-  obs::Obj_iterator *it= obs::get_view_base_views(m_ctx.m_thd, db_name, name);
+  obs::Obj_iterator *it= obs::get_view_base_views(m_thd, db_name, name);
 
   if (!it)
     return ERROR;
@@ -1069,7 +1117,7 @@ Backup_info::add_db_object(Db &db, const
   
   if (res == get_dep_node_res::ERROR)
   {
-    m_ctx.fatal_error(error, db.name().ptr(), obj->get_name()->ptr());
+    m_log.report_error(error, db.name().ptr(), obj->get_name()->ptr());
     return NULL;
   }
 
@@ -1084,7 +1132,7 @@ Backup_info::add_db_object(Db &db, const
     if (type == BSTREAM_IT_VIEW)
       if (add_view_deps(*obj))
       {
-        m_ctx.fatal_error(error, db.name().ptr(), obj->get_name()->ptr());
+        m_log.report_error(error, db.name().ptr(), obj->get_name()->ptr());
         return NULL;
       } 
 
@@ -1105,7 +1153,7 @@ Backup_info::add_db_object(Db &db, const
  
   if (!o)
   {
-    m_ctx.fatal_error(error, db.name().ptr(), obj->get_name()->ptr());
+    m_log.report_error(error, db.name().ptr(), obj->get_name()->ptr());
     return NULL;
   }
 
@@ -1325,7 +1373,7 @@ int Backup_info::Global_iterator::init()
   if (!m_it)
   {
     const Backup_info* info= static_cast<const Backup_info*>(&m_info);
-    return info->m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    return info->m_log.report_error(ER_OUT_OF_RESOURCES);
   }
   next();                                       // Never errors
 
@@ -1371,7 +1419,7 @@ Backup_info::Global_iterator::next()
     if (!m_it)
     {
       const Backup_info* info= static_cast<const Backup_info*>(&m_info);
-      info->m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+      info->m_log.report_error(ER_OUT_OF_RESOURCES);
       mode= DONE;
       return FALSE;
     }
@@ -1454,7 +1502,7 @@ backup::Image_info::Iterator* Backup_inf
   Global_iterator* it = new Global_iterator(*this);
   if (it == NULL) 
   {
-    m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    m_log.report_error(ER_OUT_OF_RESOURCES);
     return NULL;
   }    
   if (it->init())                               // Error has been logged
@@ -1471,7 +1519,7 @@ backup::Image_info::Iterator* Backup_inf
   Perdb_iterator* it = new Perdb_iterator(*this);
   if (it == NULL) 
   {
-    m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    m_log.report_error(ER_OUT_OF_RESOURCES);
     return NULL;
   }    
   if (it->init())                               // Error has been logged

=== modified file 'sql/backup/backup_info.h'
--- a/sql/backup/backup_info.h	2008-12-04 23:14:30 +0000
+++ b/sql/backup/backup_info.h	2008-12-10 15:53:06 +0000
@@ -31,9 +31,8 @@ class Backup_info: public backup::Image_
 {
  public:
 
-  Backup_restore_ctx &m_ctx;
+  backup::Logger &m_log;
 
-  Backup_info(Backup_restore_ctx&);
   ~Backup_info();
 
   bool is_valid();
@@ -48,10 +47,18 @@ class Backup_info: public backup::Image_
 
  private:
 
+  /*
+    Note: constructor is private because instances of this class are supposed
+    to be created only with Backup_restore_ctx::prepare_for_backup() method.
+  */
+  Backup_info(backup::Logger&, THD*);
+
   // Prevent copying/assignments
   Backup_info(const Backup_info&);
   Backup_info& operator=(const Backup_info&);
 
+  THD *m_thd;
+
   class Global_iterator; ///< Iterates over global items (for which meta-data is
stored).
   class Perdb_iterator;  ///< Iterates over all per-database objects (except tables).
 
@@ -169,6 +176,7 @@ class Backup_info: public backup::Image_
   friend int ::bcat_get_item_create_query(st_bstream_image_header *catalogue,
                                struct st_bstream_item_info *item,
                                bstream_blob *stmt);
+  friend class Backup_restore_ctx;  // Needs access to the constructor.
 };
 
 /// Check if instance is correctly created.

=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h	2008-11-17 09:57:51 +0000
+++ b/sql/backup/backup_kernel.h	2008-11-25 17:44:19 +0000
@@ -75,8 +75,6 @@ class Backup_restore_ctx: public backup:
 
   int do_backup();
   int do_restore(bool overwrite);
-  int fatal_error(int, ...);
-  int log_error(int, ...);
 
   int close();
 
@@ -102,7 +100,8 @@ class Backup_restore_ctx: public backup:
   /** 
     @brief State of a context object. 
     
-    Backup/restore can be performed only if object is prepared for that operation.
+    Backup/restore can be performed only if object is prepared for that 
+    operation.
    */
   enum { CREATED,
          PREPARED_FOR_BACKUP,
@@ -111,10 +110,22 @@ class Backup_restore_ctx: public backup:
 
   ulonglong m_thd_options;  ///< For saving thd->options.
   /**
-    If backup/restore was interrupted by an error, this member stores the error 
-    number.
-   */ 
+    @brief Tells if context object is in error state.
+
+    In case of fatal error, the context object is put into an error state 
+    by setting @m_error to non-zero value. This can be the code of
+    the detected error but currently the exact value is not used.
+
+    When in error state, public methods of Backup_restore_ctx do not try
+    to perform their operations but report an error instead. @c Is_valid() 
+    will return FALSE for an object in error state.
+
+    @note The error state is an internal state of the context object. The
+    object can enter this state only as a result of executing one of its 
+    methods.
+  */
   int m_error;
+  int fatal_error(int);
   
   ::String  m_path;   ///< Path to where the backup image file is located.
 
@@ -149,8 +160,6 @@ class Backup_restore_ctx: public backup:
   
   int report_stream_open_failure(int open_error, const LEX_STRING *location);
 
-  friend class Backup_info;
-  friend class Restore_info;
   friend int backup_init();
   friend void backup_shutdown();
   friend bstream_byte* bstream_alloc(unsigned long int);
@@ -179,32 +188,31 @@ void Backup_restore_ctx::disable_fkey_co
 }
 
 /**
-  Report error and move context object into error state.
+  Move context object into error state.
   
   After this method is called the context object is in error state and
-  cannot be normally used. It still can be examined for saved error messages.
-  The code of the error reported here is saved in m_error member.
+  cannot be normally used. The provided error code is saved in m_error 
+  member.
   
   Only one fatal error can be reported. If context is already in error
   state when this method is called, it does nothing.
+
+  @note Context object should enter error state only as a result of executing
+  one of its methods. Thus this private helper method is intended to be used 
+  only from within Backup_restore_ctx class.  
   
   @return error code given as input or stored in the context object if
-  a fatal error was reported before.
+  it is already in error state.
  */ 
 inline
-int Backup_restore_ctx::fatal_error(int error_code, ...)
+int Backup_restore_ctx::fatal_error(int error_code)
 {
+  m_remove_loc= TRUE;
+
   if (m_error)
     return m_error;
 
-  va_list args;
-
   m_error= error_code;
-  m_remove_loc= TRUE;
-
-  va_start(args,error_code);
-  v_report_error(backup::log_level::ERROR, error_code, args);
-  va_end(args);
 
   return error_code;
 }

=== modified file 'sql/backup/data_backup.cc'
--- a/sql/backup/data_backup.cc	2008-10-30 20:02:15 +0000
+++ b/sql/backup/data_backup.cc	2008-12-13 11:02:16 +0000
@@ -248,7 +248,7 @@ class Scheduler
  private:
 
   LIST   *m_pumps, *m_last;
-  Logger *m_log;        ///< used to report errors if not NULL
+  Logger &m_log;        ///< for reporting errors          
   uint   m_count;       ///< current number of pumps
   size_t m_total;       ///< accumulated position of all drivers
   size_t m_init_left;   ///< how much of init data is left (estimate)
@@ -256,7 +256,7 @@ class Scheduler
   Output_stream &m_str; ///< stream to which we write
   bool   cancelled;     ///< true if backup process was cancelled
 
-  Scheduler(Output_stream &s, Logger *log)
+  Scheduler(Output_stream &s, Logger &log)
     :init_count(0), prepare_count(0), finish_count(0),
     m_pumps(NULL), m_last(NULL), m_log(log),
     m_count(0), m_total(0), m_init_left(0), m_known_count(0),
@@ -412,6 +412,70 @@ int unblock_commits(THD *thd)
 }
 
 /**
+  Store information about validity point in @c Backup_info structure.
+  
+  @note This function is called in a time critical synchronization phase
+  of the backup process. Therefore it should not perform any time consuming
+  or potentially waiting operations such as I/O.
+
+  @returns 0 on success.
+*/
+static
+int save_vp_info(Backup_info &info)
+{
+  LOG_INFO binlog_pos;
+  int ret=0;
+
+  /*
+    Save VP creation time.
+  */
+  info.save_vp_time(my_time(0));
+
+  /*
+    Save current binlog position if it is enabled.
+  */
+  if (mysql_bin_log.is_open())
+    if (mysql_bin_log.get_current_log(&binlog_pos))
+    {
+      info.m_log.report_error(ER_BACKUP_BINLOG);
+      ret= TRUE;
+    }
+    else
+      info.save_binlog_pos(binlog_pos);
+
+  /*
+    Save master's binlog information if we are a connected slave.
+  */
+  if (obs::is_slave() && active_mi)
+    info.save_master_pos(*active_mi);
+
+  return ret;
+}
+
+/**
+  Log validity point information.
+
+  Information such as validity point time is logged using backup logger which,
+  in particular, writes it to backup history and progress logs.
+  
+  @note Logging the information may involve time consuming I/O. Therefore this
+  function should not be called in the time critical synchronization phase, but
+  after the synchronisation has been done.
+*/ 
+static
+void report_vp_info(Backup_info &info)
+{
+  info.m_log.report_vp_time(info.get_vp_time(), 
+                            TRUE // = also write to progress log
+                           );
+  if (info.flags & BSTREAM_FLAG_BINLOG)
+    info.m_log.report_binlog_pos(info.binlog_pos);
+  if (info.master_pos.pos)
+    info.m_log.report_master_binlog_pos(info.master_pos);
+}
+
+
+/**
   Save data from tables being backed up.
 
   Function initializes and controls backup drivers which create the image
@@ -424,17 +488,30 @@ int write_table_data(THD* thd, Backup_in
 {
   DBUG_ENTER("backup::write_table_data");
 
+  /*
+    If there are no tables to backup, there is nothing to do in this function
+    except for storing and reporting the validity point info.
+    
+    Note that since DDLs are disabled and backup image contains no table data, 
+    any time during backup operation is a good validity time -- there is no 
+    issue of synchronising the data stored in the image with the data in the 
+    rest of the server.
+  */ 
   if (info.snap_count() == 0 || info.table_count() == 0) // nothing to backup
-    DBUG_RETURN(0);
+  {
+    int res= save_vp_info(info);    // logs errors
+    if (!res)
+      report_vp_info(info);
+    DBUG_RETURN(res);
+  }
 
-  Scheduler   sch(s, &info.m_ctx);          // scheduler instance
+  Logger      &log= info.m_log;
+  Scheduler   sch(s, log);          // scheduler instance
   List<Scheduler::Pump>  inactive;  // list of images not yet being created
 
   // keeps maximal init size for images in inactive list
   size_t      max_init_size=0;
 
-  time_t      vp_time;              // to store validity point time
-
   DBUG_PRINT("backup_data",("initializing scheduler"));
 
   // add unknown "at end" drivers to scheduler, rest to inactive list
@@ -448,9 +525,15 @@ int write_table_data(THD* thd, Backup_in
 
     Scheduler::Pump *p= new Scheduler::Pump(*i, s);
 
-    if (!p || !p->is_valid())
+    if (!p)
     {
-      info.m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+      log.report_error(ER_OUT_OF_RESOURCES);
+      goto error;
+    }
+    if (!p->is_valid())
+    {
+      log.report_error(ER_BACKUP_CREATE_BACKUP_DRIVER,p->m_name);
+      delete p;
       goto error;
     }
 
@@ -458,7 +541,7 @@ int write_table_data(THD* thd, Backup_in
 
     if (init_size == Driver::UNKNOWN_SIZE)
     {
-      if (sch.add(p))
+      if (sch.add(p))    // logs errors
         goto error;
     }
     else
@@ -471,7 +554,7 @@ int write_table_data(THD* thd, Backup_in
         /* Allocation failed. 
            Error has been reported, but not logged to backup logs.
         */
-        info.m_ctx.log_error(ER_OUT_OF_RESOURCES);
+        log.log_error(ER_OUT_OF_RESOURCES);
         goto error;
       }
     }
@@ -529,7 +612,7 @@ int write_table_data(THD* thd, Backup_in
 
     // poll drivers
 
-    if (sch.step())
+    if (sch.step())    // logs errors
       goto error;
   }
 
@@ -571,7 +654,7 @@ int write_table_data(THD* thd, Backup_in
     if (error)
       goto error;
 
-    if (sch.prepare())
+    if (sch.prepare())    // logs errors
       goto error;
 
     while (sch.prepare_count > 0)
@@ -582,9 +665,7 @@ int write_table_data(THD* thd, Backup_in
     
     DBUG_PRINT("backup_data",("-- SYNC PHASE --"));
 
-    LOG_INFO binlog_pos;
-    
-    info.m_ctx.report_state(BUP_VALIDITY_POINT);
+    log.report_state(BUP_VALIDITY_POINT);
     /*
       This breakpoint is used to assist in testing state changes for
       the backup progress. It is not to be used to indicate actual
@@ -597,39 +678,13 @@ int write_table_data(THD* thd, Backup_in
     */
 
     DEBUG_SYNC(thd, "before_backup_data_lock");
-    if (sch.lock())
+    if (sch.lock())    // logs errors
       goto error;
 
-    /*
-      Save binlog information for point in time recovery on restore.
-    */
-    if (mysql_bin_log.is_open())
-      if (mysql_bin_log.get_current_log(&binlog_pos))
-      {
-        info.m_ctx.fatal_error(ER_BACKUP_BINLOG);
-        goto error;
-      }
-
-    /*
-      If we are a connected slave, write master's binlog information to
-      the progress log for later use.
-    */
-    st_bstream_binlog_pos master_pos;
-    master_pos.pos= 0;
-    master_pos.file= 0;
-    if (obs::is_slave() && active_mi)
-    {
-      master_pos.pos= (ulong)active_mi->master_log_pos;
-      master_pos.file= active_mi->master_log_name;
-    }
-
-    /*
-      Save VP creation time.
-    */
-    vp_time= my_time(0);
+    save_vp_info(info);
 
     DEBUG_SYNC(thd, "before_backup_data_unlock");
-    if (sch.unlock())
+    if (sch.unlock())    // logs errors
       goto error;
 
     /*
@@ -640,25 +695,10 @@ int write_table_data(THD* thd, Backup_in
     if (error)
       goto error;
 
-    // Report and save information about VP
 
-    info.save_vp_time(vp_time);
-    info.m_ctx.report_vp_time(vp_time, TRUE); // TRUE = also write to progress log
+    report_vp_info(info);
 
-    if (mysql_bin_log.is_open())
-    {
-      info.save_binlog_pos(binlog_pos);
-      info.m_ctx.report_binlog_pos(info.binlog_pos);
-    }
-
-    /*
-      If we are a slave and the master's binlog position has been recorded
-      write it to the log.
-    */
-    if (obs::is_slave() && master_pos.pos)
-      info.m_ctx.report_master_binlog_pos(master_pos);
-
-    info.m_ctx.report_state(BUP_RUNNING);
+    log.report_state(BUP_RUNNING);
     DEBUG_SYNC(thd, "after_backup_binlog");
 
     /**** VP creation (end) ********************************************/
@@ -819,9 +859,6 @@ int Scheduler::step()
 
     case backup_state::ERROR:
       remove_pump(p);   // Note: never errors.
-      if (res)
-        cancel_backup(); // we hit an error - bail out
-                         // Note: cancel_backup() never errors.
       break;
 
     default: break;
@@ -846,11 +883,14 @@ int Scheduler::add(Pump *p)
   if (!p)  // no pump to add
     return 0;
 
-  p->set_logger(m_log);
+  p->set_logger(&m_log);
   p->start_pos= avg;
 
-  if (p->begin())
-    goto error;
+  if (p->begin())  // logs errors
+  {
+    delete p;
+    return ERROR;
+  }
 
   // in case of error, above call should return non-zero code (and report error)
   DBUG_ASSERT(p->state != backup_state::ERROR);
@@ -894,12 +934,6 @@ int Scheduler::add(Pump *p)
                             (unsigned long)m_init_left));
 
   return 0;
-
- error:
-
-  delete p;
-  cancel_backup();
-  return ERROR;
 }
 
 /// Move backup pump to the end of scheduler's list.
@@ -971,9 +1005,9 @@ int Scheduler::prepare()
 
   for (Pump_iterator it(*this); it; ++it)
   {
-    if (it->prepare())
+    if (it->prepare())  // logs errors
     {
-      cancel_backup();  // Note: never errors.
+      remove_pump(it);  // Note: never errors.
       return ERROR;
     }
     if (it->state == backup_state::PREPARING)
@@ -994,9 +1028,9 @@ int Scheduler::lock()
   DBUG_PRINT("backup_data",("calling lock() for all drivers"));
 
   for (Pump_iterator it(*this); it; ++it)
-   if (it->lock())
+   if (it->lock())    // logs errors
    {
-     cancel_backup();  // Note: never errors.
+     remove_pump(it);  // Note: never errors.
      return ERROR;
    }
 
@@ -1013,9 +1047,9 @@ int Scheduler::unlock()
 
   for(Pump_iterator it(*this); it; ++it)
   {
-    if (it->unlock())
+    if (it->unlock())   // logs errors
     {
-      cancel_backup();  // Note: never errors.
+      remove_pump(it);  // Note: never errors.
       return ERROR;
     }
     if (it->state == backup_state::FINISHING)
@@ -1072,9 +1106,7 @@ int Backup_pump::begin()
   if (ERROR == m_drv->begin(m_bw.buf_size))
   {
     state= backup_state::ERROR;
-    // We check if logger is always setup. Later the assertion can
-    // be replaced with "if (m_log)"
-    DBUG_ASSERT(m_log);
+    if (m_log)
       m_log->report_error(ER_BACKUP_INIT_BACKUP_DRIVER, m_name);
     return ERROR;
   }
@@ -1092,7 +1124,7 @@ int Backup_pump::end()
     if (ERROR == m_drv->end())
     {
       state= backup_state::ERROR;
-      DBUG_ASSERT(m_log);
+      if (m_log)
         m_log->report_error(ER_BACKUP_STOP_BACKUP_DRIVER, m_name);
       return ERROR;
     }
@@ -1121,9 +1153,9 @@ int Backup_pump::prepare()
   case ERROR:
   default:
     state= backup_state::ERROR;
-    DBUG_ASSERT(m_log);
+    if (m_log)
       m_log->report_error(ER_BACKUP_PREPARE_DRIVER, m_name);
-      return ERROR;
+    return ERROR;
   }
 
   DBUG_PRINT("backup_data",(" preparing %s, goes to %s state",
@@ -1138,7 +1170,7 @@ int Backup_pump::lock()
   if (ERROR == m_drv->lock())
   {
     state= backup_state::ERROR;
-    DBUG_ASSERT(m_log);
+    if (m_log)
       m_log->report_error(ER_BACKUP_CREATE_VP, m_name);
     return ERROR;
   }
@@ -1154,7 +1186,7 @@ int Backup_pump::unlock()
   if (ERROR == m_drv->unlock())
   {
     state= backup_state::ERROR;
-    DBUG_ASSERT(m_log);
+    if (m_log)
       m_log->report_error(ER_BACKUP_UNLOCK_DRIVER, m_name);
     return ERROR;
   }
@@ -1167,7 +1199,7 @@ int Backup_pump::cancel()
   if (ERROR == m_drv->cancel())
   {
     state= backup_state::ERROR;
-    DBUG_ASSERT(m_log);
+    if (m_log)
       m_log->report_error(ER_BACKUP_CANCEL_BACKUP, m_name);
     return ERROR;
   }
@@ -1248,7 +1280,7 @@ int Backup_pump::pump(size_t *howmuch)
 
         case Block_writer::ERROR:
         default:
-          DBUG_ASSERT(m_log);
+          if (m_log)
             m_log->report_error(ER_BACKUP_GET_BUF);
           state= backup_state::ERROR;
           return ERROR;
@@ -1293,7 +1325,7 @@ int Backup_pump::pump(size_t *howmuch)
 
       case ERROR:
       default:
-        DBUG_ASSERT(m_log);
+        if (m_log)
           m_log->report_error(ER_BACKUP_GET_DATA, m_name);
         state= backup_state::ERROR;
         return ERROR;
@@ -1328,7 +1360,7 @@ int Backup_pump::pump(size_t *howmuch)
 
       case Block_writer::ERROR:
 
-        DBUG_ASSERT(m_log);
+        if (m_log)
           m_log->report_error(ER_BACKUP_WRITE_DATA, m_name, m_buf.table_num);
         state= backup_state::ERROR;
         return ERROR;
@@ -1364,18 +1396,50 @@ namespace backup {
  */
 int restore_table_data(THD *thd, Restore_info &info, Input_stream &s)
 {
+  st_bstream_data_chunk chunk_info; // For reading chunks from the stream.
+
   DBUG_ENTER("restore::restore_table_data");
 
   enum { READING, SENDING, DONE, ERROR } state= READING;
 
+  /*
+    If there are no tables stored in the image, there is nothing to do in this
+    function. However, we must call bstream_rd_data_chunk() which will absorb
+    the 0x00 byte signalling end of (the empty) table data chunk sequence.
+  */ 
   if (info.snap_count() == 0 || info.table_count() == 0) // nothing to restore
+  {
+    int res= bstream_rd_data_chunk(&s, &chunk_info);
+    if (res != BSTREAM_EOC)
+    {
+       info.m_log.report_error(res == BSTREAM_ERROR ?
+                                        ER_BACKUP_READ_DATA :
+                                        ER_BACKUP_UNEXPECTED_DATA);
+       DBUG_RETURN(ERROR);
+    }
     DBUG_RETURN(0);
+  }
 
-  Restore_driver* drv[256];
+  Logger &log= info.m_log;
 
-  if (info.snap_count() > 256)
+  /* Drv[n] points at restore driver used to process snapshot n. */
+  Restore_driver* drv[MAX_SNAP_COUNT];
+  /*
+    Active[n] is not NULL if driver drv[n] has been activated. Such driver needs 
+    an end() or cancel() call to shut it down properly.
+  */ 
+  Restore_driver* active[MAX_SNAP_COUNT];
+  /*
+    Bad_drivers string for holding comma separated list of drivers which
+    signalled errors during shutdown. If non-empty, an error will be logged
+    at the end of the function (finish: label).
+   */   
+  String bad_drivers;
+
+  if (info.snap_count() > MAX_SNAP_COUNT)
   {
-    info.m_ctx.fatal_error(ER_BACKUP_TOO_MANY_IMAGES, info.snap_count(), 256);
+    log.report_error(ER_BACKUP_TOO_MANY_IMAGES,
+                     info.snap_count(), MAX_SNAP_COUNT);
     DBUG_RETURN(ERROR);
   }
 
@@ -1384,7 +1448,7 @@ int restore_table_data(THD *thd, Restore
 
   for (uint n=0; n < info.snap_count(); ++n)
   {
-    drv[n]= NULL;
+    active[n]= drv[n]= NULL;
 
     Snapshot_info *snap= info.m_snap[n];
 
@@ -1395,7 +1459,7 @@ int restore_table_data(THD *thd, Restore
     res= snap->get_restore_driver(drv[n]);
     if (res == backup::ERROR)
     {
-      info.m_ctx.fatal_error(ER_BACKUP_CREATE_RESTORE_DRIVER, snap->name());
+      log.report_error(ER_BACKUP_CREATE_RESTORE_DRIVER, snap->name());
       goto error;
     };   
  }
@@ -1406,9 +1470,11 @@ int restore_table_data(THD *thd, Restore
     res= drv[n]->begin(0);
     if (res == backup::ERROR)
     {
-      info.m_ctx.fatal_error(ER_BACKUP_INIT_RESTORE_DRIVER, info.m_snap[n]->name());
+      log.report_error(ER_BACKUP_INIT_RESTORE_DRIVER, info.m_snap[n]->name());
       goto error;
     }
+    
+    active[n]= drv[n];
   }
 
   DEBUG_SYNC(thd, "restore_in_progress");
@@ -1426,8 +1492,6 @@ int restore_table_data(THD *thd, Restore
 
     // main data reading loop
 
-    st_bstream_data_chunk chunk_info;
-
     while ( state != DONE && state != ERROR )
     {
       switch (state) {
@@ -1449,9 +1513,8 @@ int restore_table_data(THD *thd, Restore
           break;
 
         case BSTREAM_ERROR:
-          info.m_ctx.fatal_error(ER_BACKUP_READ_DATA);
+          log.report_error(ER_BACKUP_READ_DATA);
         default:
-          state= ERROR;
           goto error;
 
         }
@@ -1491,7 +1554,8 @@ int restore_table_data(THD *thd, Restore
          */
         DBUG_ASSERT(snap && drvr);
 
-        switch( drvr->send_data(buf) ) {
+        ret= drvr->send_data(buf);
+        switch (ret) {
 
         case backup::OK:
           info.data_size += buf.size;
@@ -1504,8 +1568,13 @@ int restore_table_data(THD *thd, Restore
         case backup::ERROR:
           if( errors > MAX_ERRORS )
           {
-            info.m_ctx.fatal_error(ER_BACKUP_SEND_DATA, buf.table_num, snap->name());
-            state= ERROR;
+            log.report_error(ER_BACKUP_SEND_DATA, buf.table_num, snap->name());
+            /*
+              If driver signals error then it is not active any longer - neither 
+              ->end() nor ->cancel() should be called on it, only ->free(). 
+              This is why we need to remove it from active[] array.
+            */
+            active[snap_num]= NULL;
             goto error;
           }
           errors++;
@@ -1516,8 +1585,7 @@ int restore_table_data(THD *thd, Restore
         default:
           if( repeats > MAX_REPEATS )
           {
-            info.m_ctx.fatal_error(ER_BACKUP_SEND_DATA_RETRY, repeats, snap->name());
-            state= ERROR;
+            log.report_error(ER_BACKUP_SEND_DATA_RETRY, repeats, snap->name());
             goto error;
           }
           repeats++;
@@ -1526,7 +1594,7 @@ int restore_table_data(THD *thd, Restore
 
       default:
         break;
-      } // switch(state)
+      } // switch(ret)
 
     } // main reading loop
 
@@ -1536,49 +1604,69 @@ int restore_table_data(THD *thd, Restore
   }
 
   DEBUG_SYNC(::current_thd, "restore_table_data_before_end");
-  
-  { // Shutting down drivers
 
-    String bad_drivers;
+  // Call end() for all active drivers.
 
-    for (uint n=0; n < info.snap_count(); ++n)
-    {
-      if (!drv[n])
-        continue;
+  for (uint n=0; n < info.snap_count(); ++n)
+  {
+    if (!active[n])
+      continue;
 
-      DBUG_PRINT("restore",("Shutting down restore driver %s",
-                            info.m_snap[n]->name()));
-      res= drv[n]->end();
-      if (res == backup::ERROR)
-      {
-        state= ERROR;
+    DBUG_PRINT("restore",("Shutting down restore driver %s",
+                           info.m_snap[n]->name()));
+    res= active[n]->end();
+    if (res == backup::ERROR)
+    {
+      state= ERROR;
 
-        if (!bad_drivers.is_empty())
-          bad_drivers.append(",");
-        bad_drivers.append(info.m_snap[n]->name());
-      }
-      drv[n]->free();                           // Never errors
+      if (!bad_drivers.is_empty())
+        bad_drivers.append(",");
+      bad_drivers.append(info.m_snap[n]->name());
     }
-
-    if (!bad_drivers.is_empty())
-      info.m_ctx.report_error(ER_BACKUP_STOP_RESTORE_DRIVERS, bad_drivers.c_ptr());
   }
 
-  DBUG_RETURN(state == ERROR ? backup::ERROR : 0);
+  goto finish;
 
- error:
+error:
+
+  state= ERROR;
 
   DBUG_PRINT("restore",("Cancelling restore process"));
 
+  // Call cancel() for all active drivers
+
   for (uint n=0; n < info.snap_count(); ++n)
   {
-    if (!drv[n])
+    if (!active[n])
       continue;
 
+    DBUG_PRINT("restore",("Cancelling restore driver %s",
+                           info.m_snap[n]->name()));
+    res= active[n]->cancel();
+
+    if (res)
+    {
+      if (!bad_drivers.is_empty())
+        bad_drivers.append(",");
+      bad_drivers.append(info.m_snap[n]->name());
+    }
+  }
+
+finish:  
+
+  if (!bad_drivers.is_empty())
+    log.report_error(ER_BACKUP_STOP_RESTORE_DRIVERS, bad_drivers.c_ptr());
+
+  // Call free() for all existing drivers
+
+  for (uint n=0; n < info.snap_count(); ++n)
+  {
+    if (!drv[n])
+      continue;
     drv[n]->free();                             // Never errors
   }
 
-  DBUG_RETURN(backup::ERROR);
+  DBUG_RETURN(state == ERROR ? backup::ERROR : 0);
 }
 
 

=== modified file 'sql/backup/image_info.cc'
--- a/sql/backup/image_info.cc	2008-11-05 09:41:15 +0000
+++ b/sql/backup/image_info.cc	2008-11-26 10:05:19 +0000
@@ -1,4 +1,5 @@
 #include "../mysql_priv.h"
+#include "../rpl_mi.h"
 
 #include "image_info.h"
 #include "be_native.h"
@@ -50,6 +51,7 @@ Image_info::Image_info()
 #endif
 
   bzero(m_snap, sizeof(m_snap));
+  bzero(&master_pos, sizeof(master_pos));
 }
 
 Image_info::~Image_info()
@@ -169,8 +171,7 @@ int Image_info::add_snapshot(Snapshot_in
 {
   uint num= st_bstream_image_header::snap_count++;
 
-  // The limit of 256 snapshots is imposed by backup stream format.  
-  if (num > 256)
+  if (num > MAX_SNAP_COUNT)
     return -1;
   
   m_snap[num]= &snap;
@@ -384,6 +385,14 @@ Image_info::Obj *find_obj(const Image_in
   }
 }
 
+void Image_info::save_master_pos(const ::Master_info &mi)
+{
+  // store binlog coordinates
+  master_pos.pos=  static_cast<unsigned long int>(mi.master_log_pos);
+  master_pos.file= const_cast<char*>(mi.master_log_name);
+}
+
+
 } // backup namespace
 
 template class Map<uint, backup::Image_info::Db>;

=== modified file 'sql/backup/image_info.h'
--- a/sql/backup/image_info.h	2008-12-04 23:14:30 +0000
+++ b/sql/backup/image_info.h	2008-12-10 15:53:06 +0000
@@ -10,6 +10,16 @@
 #include <backup_stream.h> // for st_bstream_* types
 #include <backup/backup_aux.h>  // for Map template
 
+/**
+  @brief The maximal number of table data snapshots per backup image.
+  
+  @note This limit is determined by the backup image format used and can
+  not be changed. Currently we use version 1 of the image format in which
+  one byte is used to store snapshot numbers, hence the limit is 256.
+*/ 
+#define MAX_SNAP_COUNT  256
+
+
 class Backup_restore_ctx;
 
 namespace backup {
@@ -75,6 +85,7 @@ public: // public interface
    // info about image (most of it is in the st_bstream_image_header base
 
    size_t     data_size;      ///< How much of table data is saved in the image.
+   st_bstream_binlog_pos  master_pos; ///< To store master position info.
 
    ulong      table_count() const;
    uint       db_count() const;
@@ -101,12 +112,8 @@ public: // public interface
    /**
      Pointers to @c Snapshot_info objects corresponding to the snapshots
      present in the image.
-     
-     We can have at most 256 different snapshots which is a limitation imposed
-     by the backup stream library (the number of snapshots is stored inside 
-     backup image using one byte field).
     */ 
-   Snapshot_info *m_snap[256];
+   Snapshot_info *m_snap[MAX_SNAP_COUNT];
    
    // save timing & binlog info 
    
@@ -115,6 +122,7 @@ public: // public interface
    void save_vp_time(const time_t time);   
 
    void save_binlog_pos(const ::LOG_INFO&);
+   void save_master_pos(const ::Master_info&);
 
    time_t get_vp_time() const;
 

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2008-12-05 23:47:51 +0000
+++ b/sql/backup/kernel.cc	2008-12-10 15:53:06 +0000
@@ -156,11 +156,8 @@ execute_backup_command(THD *thd, LEX *le
     folders in the path could have been moved, deleted, etc.
   */
   if (backupdir->length() && my_access(backupdir->c_ptr(), (F_OK|W_OK)))
-  {
-    context.fatal_error(ER_BACKUP_BACKUPDIR, backupdir->c_ptr());
     DBUG_RETURN(send_error(context, ER_BACKUP_BACKUPDIR, backupdir->c_ptr()));
-  }
-
+ 
   switch (lex->sql_command) {
 
   case SQLCOM_BACKUP:
@@ -180,13 +177,9 @@ execute_backup_command(THD *thd, LEX *le
     // select objects to backup
 
     if (lex->db_list.is_empty())
-    {
-      context.write_message(log_level::INFO, "Backing up all databases");
       res= info->add_all_dbs(); // backup all databases
-    }
     else
     {
-      context.write_message(log_level::INFO, "Backing up selected databases");
       /* Backup databases specified by user. */
       res= info->add_dbs(thd, lex->db_list);
     }
@@ -198,7 +191,7 @@ execute_backup_command(THD *thd, LEX *le
 
     if (info->db_count() == 0)
     {
-      context.fatal_error(ER_BACKUP_NOTHING_TO_BACKUP);
+      context.report_error(ER_BACKUP_NOTHING_TO_BACKUP);
       DBUG_RETURN(send_error(context, ER_BACKUP_NOTHING_TO_BACKUP));
     }
 
@@ -257,23 +250,21 @@ execute_backup_command(THD *thd, LEX *le
 }
 
 /**
-  Report errors.
+  Sends error notification after failed backup/restore operation.
 
-  Current implementation reports the last error saved in the logger if it exist.
-  Otherwise it reports error given by @c error_code.
+  @param[in]  ctx  The context of the backup/restore operation.
+  @param[in]  error_code  Error to be reported if no errors reported yet.
 
-  @returns 0 on success, error code otherwise.
- */
-int send_error(Backup_restore_ctx &log, int error_code, ...)
+  If an error has been already reported then nothing is done - the first 
+  logged error will be send to the client. Otherwise, if no errors were 
+  reported yet, the given error is sent to the client (but not reported).
+  
+  @returns The error code given as argument.
+*/
+static
+int send_error(Backup_restore_ctx &context, int error_code, ...)
 {
-  util::SAVED_MYSQL_ERROR *error= log.last_saved_error();
-
-  if (error && !util::report_mysql_error(log.thd(), error, error_code))
-  {
-    if (error->code)
-      error_code= error->code;
-  }
-  else // there are no error information in the logger - report error_code
+  if (!context.error_reported())
   {
     char buf[ERRMSGSIZE + 20];
     va_list args;
@@ -285,8 +276,8 @@ int send_error(Backup_restore_ctx &log, 
     va_end(args);
   }
 
-  if (log.backup::Logger::m_state == backup::Logger::RUNNING)
-    log.report_stop(my_time(0), FALSE); // FASLE = no success
+  if (context.backup::Logger::m_state == backup::Logger::RUNNING)
+    context.report_stop(my_time(0), FALSE); // FASLE = no success
   return error_code;
 }
 
@@ -297,6 +288,8 @@ int send_error(Backup_restore_ctx &log, 
   Currently the id of the operation is returned to the client. It can
   be used to select correct entries from the backup progress tables.
 
+  @note If an error has been reported, send_error() is invoked instead.
+
   @returns 0 on success, error code otherwise.
 */
 int send_reply(Backup_restore_ctx &context)
@@ -307,6 +300,9 @@ int send_reply(Backup_restore_ctx &conte
 
   DBUG_ENTER("send_reply");
 
+  if (context.error_reported())
+    return send_error(context, ER_UNKNOWN_ERROR);
+
   /*
     Send field list.
   */
@@ -337,9 +333,9 @@ int send_reply(Backup_restore_ctx &conte
   DBUG_RETURN(0);
 
  err:
-  DBUG_RETURN(context.fatal_error(ER_BACKUP_SEND_REPLY,
-                                  context.m_type == backup::Logger::BACKUP
-                                  ? "BACKUP" : "RESTORE"));
+  DBUG_RETURN(context.report_error(ER_BACKUP_SEND_REPLY,
+                                   context.m_type == backup::Logger::BACKUP
+                                   ? "BACKUP" : "RESTORE"));
 }
 
 
@@ -497,23 +493,18 @@ int Backup_restore_ctx::prepare(String *
 {
   if (m_error)
     return m_error;
-  
-  // Prepare error reporting context.
-  
-  m_thd->warning_info->opt_clear_warning_info(m_thd->query_id); // Never errors
-  m_thd->no_warnings_for_error= FALSE;
-
-  save_errors();                                // Never errors
 
+  int ret= 0;
 
   /*
     Check access for SUPER rights. If user does not have SUPER, fail with error.
+
+    In case of error, we write only to backup logs, because check_global_access()
+    pushes the same error on the error stack.
   */
-  if (check_global_access(m_thd, SUPER_ACL))
-  {
-    fatal_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, "SUPER");
-    return m_error;
-  }
+  ret= check_global_access(m_thd, SUPER_ACL);
+  if (ret)
+    return fatal_error(log_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, "SUPER"));
 
   /*
     Check if another BACKUP/RESTORE is running and if not, register 
@@ -530,7 +521,10 @@ int Backup_restore_ctx::prepare(String *
   pthread_mutex_unlock(&run_lock);
 
   if (m_error)
+  {
+    report_error(ER_BACKUP_RUNNING);
     return m_error;
+  }
 
   // check if location is valid (we assume it is a file path)
 
@@ -552,10 +546,7 @@ int Backup_restore_ctx::prepare(String *
 #endif
 
   if (bad_filename)
-  {
-    fatal_error(ER_BAD_PATH, location.str);
-    return m_error;
-  }
+    return fatal_error(report_error(ER_BAD_PATH, location.str));
 
   /*
     Computer full path to backup file.
@@ -570,18 +561,13 @@ int Backup_restore_ctx::prepare(String *
   mem_alloc= new Mem_allocator();
 
   if (!mem_alloc)
-  {
-    fatal_error(ER_OUT_OF_RESOURCES);
-    return m_error;
-  }
+    return fatal_error(report_error(ER_OUT_OF_RESOURCES));
 
   // Freeze all meta-data. 
 
-  if (obs::ddl_blocker_enable(m_thd))
-  {
-    fatal_error(ER_DDL_BLOCK);
-    return m_error;
-  }
+  ret= obs::ddl_blocker_enable(m_thd);
+  if (ret)
+    return fatal_error(report_error(ER_DDL_BLOCK));
 
   return 0;
 }
@@ -615,7 +601,7 @@ Backup_restore_ctx::prepare_for_backup(S
   if (m_error)
     return NULL;
   
-  if (Logger::init(BACKUP, query))
+  if (Logger::init(BACKUP, query))      // Logs errors
   {
     fatal_error(ER_BACKUP_LOGGER_INIT);
     return NULL;
@@ -641,10 +627,13 @@ Backup_restore_ctx::prepare_for_backup(S
   
   if (!s)
   {
-    fatal_error(ER_OUT_OF_RESOURCES);
+    fatal_error(report_error(ER_OUT_OF_RESOURCES));
     return NULL;
   }
-  
+
+  // Mark that the file should be removed unless operation completes successfuly
+  m_remove_loc= TRUE;
+
   int my_open_status= s->open();
   if (my_open_status != 0)
   {
@@ -656,16 +645,20 @@ Backup_restore_ctx::prepare_for_backup(S
     Create backup catalogue.
    */
 
-  Backup_info *info= new Backup_info(*this);    // Logs errors
+  Backup_info *info= new Backup_info(*this, m_thd);    // Logs errors
 
   if (!info)
   {
-    fatal_error(ER_OUT_OF_RESOURCES);
+    fatal_error(report_error(ER_OUT_OF_RESOURCES));
     return NULL;
   }
 
   if (!info->is_valid())
-    return NULL;    // Error has been logged by Backup_Info constructor
+  {
+    // Error has been logged by Backup_info constructor
+    fatal_error(ER_BACKUP_BACKUP_PREPARE);
+    return NULL;    
+  }
 
   /*
     If binlog is enabled, set BSTREAM_FLAG_BINLOG in the header to indicate
@@ -736,7 +729,7 @@ Backup_restore_ctx::prepare_for_restore(
   
   if (!s)
   {
-    fatal_error(ER_OUT_OF_RESOURCES);
+    fatal_error(report_error(ER_OUT_OF_RESOURCES));
     return NULL;
   }
   
@@ -751,45 +744,57 @@ Backup_restore_ctx::prepare_for_restore(
     Create restore catalogue.
    */
 
-  Restore_info *info= new Restore_info(*this);  // reports errors
+  Restore_info *info= new Restore_info(*this, m_thd);  // reports errors
 
   if (!info)
   {
-    fatal_error(ER_OUT_OF_RESOURCES);
+    fatal_error(report_error(ER_OUT_OF_RESOURCES));
     return NULL;
   }
 
   if (!info->is_valid())
+  {
+    // Errors are logged by Restore_info constructor. 
+    fatal_error(ER_BACKUP_RESTORE_PREPARE); 
     return NULL;
+  }
 
   info->save_start_time(when);
   m_catalog= info;
 
+  int ret;
+
   /*
-    Read catalogue from the input stream.
+    Read header and catalogue from the input stream.
    */
 
-  if (read_header(*info, *s))
+  ret= read_header(*info, *s);  // Can log errors via callback functions.
+  if (ret)
   {
-    fatal_error(ER_BACKUP_READ_HEADER);
+    if (!error_reported())
+      report_error(ER_BACKUP_READ_HEADER);
+    fatal_error(ret);
     return NULL;
   }
 
   if (s->next_chunk() != BSTREAM_OK)
   {
-    fatal_error(ER_BACKUP_NEXT_CHUNK);
+    fatal_error(report_error(ER_BACKUP_NEXT_CHUNK));
     return NULL;
   }
 
-  if (read_catalog(*info, *s))
+  ret= read_catalog(*info, *s);  // Can log errors via callback functions.
+  if (ret)
   {
-    fatal_error(ER_BACKUP_READ_HEADER);
+    if (!error_reported())
+      report_error(ER_BACKUP_READ_HEADER);
+    fatal_error(ret);
     return NULL;
   }
 
   if (s->next_chunk() != BSTREAM_OK)
   {
-    fatal_error(ER_BACKUP_NEXT_CHUNK);
+    fatal_error(report_error(ER_BACKUP_NEXT_CHUNK));
     return NULL;
   }
 
@@ -836,6 +841,7 @@ Backup_restore_ctx::prepare_for_restore(
 int Backup_restore_ctx::lock_tables_for_restore()
 {
   TABLE_LIST *tables= NULL;
+  int ret;
 
   /*
     Iterate over all tables in all snapshots and create a linked TABLE_LIST
@@ -856,7 +862,7 @@ int Backup_restore_ctx::lock_tables_for_
       if (!ptr)
       {
         // Error has been reported, but not logged to backup logs
-        return log_error(ER_OUT_OF_RESOURCES);
+        return fatal_error(log_error(ER_OUT_OF_RESOURCES));
       }
 
       tables= backup::link_table_list(*ptr, tables); // Never errors
@@ -873,16 +879,13 @@ int Backup_restore_ctx::lock_tables_for_
     Note 2: Skiping tmp tables is also important because otherwise a tmp table
     can occlude a regular table with the same name (BUG#33574).
   */ 
-  if (open_and_lock_tables_derived(m_thd, tables,
-                                   FALSE, /* do not process derived tables */
-                                   MYSQL_OPEN_SKIP_TEMPORARY 
+  ret= open_and_lock_tables_derived(m_thd, tables,
+                                    FALSE, /* do not process derived tables */
+                                    MYSQL_OPEN_SKIP_TEMPORARY 
                                           /* do not open tmp tables */
-                                  )
-     )
-  {
-    fatal_error(ER_BACKUP_OPEN_TABLES,"RESTORE");
-    return m_error;
-  }
+                                   );
+  if (ret)
+    return fatal_error(report_error(ER_BACKUP_OPEN_TABLES,"RESTORE"));
 
   m_tables_locked= TRUE;
   return 0;
@@ -907,39 +910,6 @@ void Backup_restore_ctx::unlock_tables()
 
 
 /**
-  Report error and move context object into error state without pushing the 
-  error on the server's warning stack.  
-  
-  Similar to @c fatal_error, but does not push the error on the
-  server's warning stack.  To be used when an error is reported from a
-  server function that has already pushed the error on the warning stack.
-  
-  @return error code given as input or stored in the context object if
-  a fatal error was reported before.
- */ 
-inline
-int Backup_restore_ctx::log_error(int error_code, ...)
-{
-  if (m_error)
-    return m_error;
-
-  bool saved = push_errors(FALSE);         // Do not use warning stack
-  
-  m_error= error_code;
-  m_remove_loc= TRUE;
-
-  va_list args;
-  va_start(args,error_code);
-  v_report_error(backup::log_level::ERROR, error_code, args);
-  va_end(args);
-
-  push_errors(saved);                      // Reset
-
-  return error_code;
-}
-
-
-/**
   Destroy a backup/restore context.
   
   This should reverse all settings made when context was created and prepared.
@@ -953,7 +923,6 @@ int Backup_restore_ctx::log_error(int er
  */ 
 int Backup_restore_ctx::close()
 {
-  int error= 0;
   if (m_state == CLOSED)
     return 0;
 
@@ -987,7 +956,7 @@ int Backup_restore_ctx::close()
   if (m_stream && !m_stream->close())
   {
     // Note error, but complete clean-up
-    error= ER_BACKUP_CLOSE;
+    fatal_error(report_error(ER_BACKUP_CLOSE));
   }
 
   if (m_catalog)
@@ -1001,31 +970,25 @@ int Backup_restore_ctx::close()
    */
   if (m_remove_loc && m_state == PREPARED_FOR_BACKUP)
   {
-    int res= my_delete(m_path.c_ptr(), MYF(0));
+    int ret= my_delete(m_path.c_ptr(), MYF(0));
 
     /*
       Ignore ENOENT error since it is ok if the file doesn't exist.
      */
-    if (res && my_errno != ENOENT)
-    {
-      error= ER_CANT_DELETE_FILE;
-    }
+    if (ret && my_errno != ENOENT)
+      fatal_error(report_error(ER_CANT_DELETE_FILE, m_path.c_ptr(), my_errno));
   }
 
   /* We report completion of the operation only if no errors were detected,
      and logger has been initialized.
   */
-  if (!error)
+  if (!m_error)
   {
     if (backup::Logger::m_state == backup::Logger::RUNNING)
     {
       report_stop(when, TRUE);
     }
   }
-  else
-  {
-    fatal_error(error);                         // Log error
-  }
 
   /* 
     Destroy backup stream's memory allocator (this frees memory)
@@ -1046,7 +1009,7 @@ int Backup_restore_ctx::close()
   pthread_mutex_unlock(&run_lock);
 
   m_state= CLOSED;
-  return error;
+  return m_error;
 }
 
 /**
@@ -1069,6 +1032,7 @@ int Backup_restore_ctx::do_backup()
   
   using namespace backup;
 
+  int ret;
   Output_stream &s= *static_cast<Output_stream*>(m_stream);
   Backup_info   &info= *static_cast<Backup_info*>(m_catalog);
 
@@ -1079,27 +1043,33 @@ int Backup_restore_ctx::do_backup()
   DBUG_PRINT("backup",("Writing preamble"));
   DEBUG_SYNC(m_thd, "backup_before_write_preamble");
 
-  if (write_preamble(info, s))
+  ret= write_preamble(info, s);  // Can Log errors via callback functions.
+  if (ret)
   {
-    fatal_error(ER_BACKUP_WRITE_HEADER);
-    DBUG_RETURN(m_error);
+    if (!error_reported())
+      report_error(ER_BACKUP_WRITE_HEADER);
+    DBUG_RETURN(fatal_error(ret));
   }
 
   DBUG_PRINT("backup",("Writing table data"));
 
   DEBUG_SYNC(m_thd, "before_backup_data");
 
-  if (write_table_data(m_thd, info, s)) // logs errors
-    DBUG_RETURN(send_error(*this, ER_BACKUP_BACKUP));
+  ret= write_table_data(m_thd, info, s); // logs errors
+  if (ret)
+    DBUG_RETURN(fatal_error(ret));
 
   DBUG_PRINT("backup",("Writing summary"));
 
-  if (write_summary(info, s))
-  {
-    fatal_error(ER_BACKUP_WRITE_SUMMARY);
-    DBUG_RETURN(m_error);
-  }
+  ret= write_summary(info, s);  
+  if (ret)
+    DBUG_RETURN(fatal_error(report_error(ER_BACKUP_WRITE_SUMMARY)));
 
+  /*
+    Now backup image has been written. Set m_remove_loc to FALSE, so that the
+    backup file is not removed in Backup_restore_ctx::close().
+  */
+  m_remove_loc= FALSE;
   report_stats_post(info);                      // Never errors
 
   DBUG_PRINT("backup",("Backup done."));
@@ -1136,9 +1106,7 @@ int Backup_restore_ctx::restore_triggers
 
   Image_info::Iterator *dbit= m_catalog->get_dbs();
   if (!dbit)
-  {
-    DBUG_RETURN(fatal_error(ER_OUT_OF_RESOURCES));
-  }
+    DBUG_RETURN(fatal_error(report_error(ER_OUT_OF_RESOURCES)));
 
   // create all trigers and collect events in the events list
   
@@ -1147,9 +1115,8 @@ int Backup_restore_ctx::restore_triggers
     Image_info::Iterator *it=
                    
m_catalog->get_db_objects(*static_cast<Image_info::Db*>(obj));
     if (!it)
-    {
-      DBUG_RETURN(fatal_error(ER_OUT_OF_RESOURCES));
-    }
+      DBUG_RETURN(fatal_error(report_error(ER_OUT_OF_RESOURCES)));
+
     while ((obj= (*it)++))
       switch (obj->type()) {
       
@@ -1158,7 +1125,7 @@ int Backup_restore_ctx::restore_triggers
         if (events.push_back(obj))
         {
           // Error has been reported, but not logged to backup logs
-          DBUG_RETURN(log_error(ER_OUT_OF_RESOURCES)); 
+          DBUG_RETURN(fatal_error(log_error(ER_OUT_OF_RESOURCES))); 
         }
         break;
       
@@ -1168,8 +1135,9 @@ int Backup_restore_ctx::restore_triggers
         {
           delete it;
           delete dbit;
-          fatal_error(ER_BACKUP_CANT_RESTORE_TRIGGER,obj->describe(buf));
-          DBUG_RETURN(m_error);
+          int err= report_error(ER_BACKUP_CANT_RESTORE_TRIGGER,
+                                obj->describe(buf));
+          DBUG_RETURN(fatal_error(err));
         }
         break;
 
@@ -1189,8 +1157,8 @@ int Backup_restore_ctx::restore_triggers
   while ((ev= it++)) 
     if (ev->m_obj_ptr->create(m_thd))
     {
-      fatal_error(ER_BACKUP_CANT_RESTORE_EVENT,ev->describe(buf));
-      DBUG_RETURN(m_error);
+      int ret= report_error(ER_BACKUP_CANT_RESTORE_EVENT,ev->describe(buf));
+      DBUG_RETURN(fatal_error(ret));
     };
 
   DBUG_RETURN(0);
@@ -1229,18 +1197,21 @@ int Backup_restore_ctx::do_restore(bool 
   DBUG_PRINT("restore", ("Restoring meta-data"));
 
   // unless RESTORE... OVERWRITE: return error if database already exists
-  if (!overwrite) {
+  if (!overwrite)
+  {
     Image_info::Db_iterator *dbit= info.get_dbs();
 
-    if (!dbit) {
-      DBUG_RETURN(fatal_error(ER_OUT_OF_RESOURCES));
-    }
+    if (!dbit)
+      DBUG_RETURN(fatal_error(report_error(ER_OUT_OF_RESOURCES)));
 
     Image_info::Db *mydb;
-    while ((mydb= static_cast<Image_info::Db*>((*dbit)++))) {
-      if (!obs::check_db_existence(m_thd, &mydb->name())) {
+    while ((mydb= static_cast<Image_info::Db*>((*dbit)++)))
+    {
+      if (!obs::check_db_existence(m_thd, &mydb->name()))
+      {
         delete dbit;
-        DBUG_RETURN(fatal_error(ER_RESTORE_DB_EXISTS, mydb->name().ptr()));
+        err= report_error(ER_RESTORE_DB_EXISTS, mydb->name().ptr());
+        DBUG_RETURN(fatal_error(err));
       }
     }
     delete dbit;
@@ -1248,31 +1219,41 @@ int Backup_restore_ctx::do_restore(bool 
 
   disable_fkey_constraints();                   // Never errors
 
-  if (read_meta_data(info, s))
+  err= read_meta_data(info, s);  // Can log errors via callback functions.
+  if (err)
   {
-    m_thd->stmt_da->reset_diagnostics_area();    // Never errors
-
-    fatal_error(ER_BACKUP_READ_META);
-    DBUG_RETURN(m_error);
+    if (!error_reported())
+      report_error(ER_BACKUP_READ_META);
+    DBUG_RETURN(fatal_error(err));
   }
 
   if (s.next_chunk() == BSTREAM_ERROR)
   {
-    DBUG_RETURN(fatal_error(ER_BACKUP_NEXT_CHUNK));
+    DBUG_RETURN(fatal_error(report_error(ER_BACKUP_NEXT_CHUNK)));
   }
 
   DBUG_PRINT("restore",("Restoring table data"));
 
-  if (lock_tables_for_restore())                // logs errors
-    DBUG_RETURN(m_error);
+  /* 
+    FIXME: this call is here because object services doesn't clean the
+    statement execution context properly, which leads to assertion failure.
+    It should be fixed inside object services implementation and then the
+    following line should be removed.
+   */
+  close_thread_tables(m_thd);                   // Never errors
+  m_thd->main_da.reset_diagnostics_area();      // Never errors  
+
+  err= lock_tables_for_restore();               // logs errors
+  if (err)
+    DBUG_RETURN(fatal_error(err));
 
   // Here restore drivers are created to restore table data
-  err= restore_table_data(m_thd, info, s); // reports errors
+  err= restore_table_data(m_thd, info, s);      // logs errors
 
   unlock_tables();                              // Never errors
 
   if (err)
-    DBUG_RETURN(ER_BACKUP_RESTORE);
+    DBUG_RETURN(fatal_error(err));
 
   /* 
    Re-create all triggers and events (it was not done in @c bcat_create_item()).
@@ -1281,16 +1262,24 @@ int Backup_restore_ctx::do_restore(bool 
    creation of these objects will fail.
   */
 
-  if (restore_triggers_and_events())    // reports errors
-     DBUG_RETURN(ER_BACKUP_RESTORE);
+  err= restore_triggers_and_events();           // logs errors
+  if (err)
+     DBUG_RETURN(fatal_error(err));
+
+  /* 
+    FIXME: this call is here because object services doesn't clean the
+    statement execution context properly, which leads to assertion failure.
+    It should be fixed inside object services implementation and then the
+    following line should be removed.
+   */
+  close_thread_tables(m_thd);                   // Never errors
+  m_thd->main_da.reset_diagnostics_area();      // Never errors
 
   DBUG_PRINT("restore",("Done."));
 
-  if (read_summary(info, s))
-  {
-    fatal_error(ER_BACKUP_READ_SUMMARY);
-    DBUG_RETURN(m_error);
-  }
+  err= read_summary(info, s);
+  if (err)
+    DBUG_RETURN(fatal_error(report_error(ER_BACKUP_READ_SUMMARY)));
 
   /*
     Report validity point time and binlog position stored in the backup image
@@ -1309,8 +1298,7 @@ int Backup_restore_ctx::do_restore(bool 
 }
 
 /**
-  Report stream open error by calling fatal_error, effectively moving
-  context object into error state.
+  Report stream open error and move context object into error state.
   
   @return error code given as input or the one stored in the context
   object if a fatal error has already been reported.
@@ -1321,26 +1309,26 @@ int Backup_restore_ctx::report_stream_op
   int error= 0;
   switch (my_open_status) {
     case ER_OPTION_PREVENTS_STATEMENT:
-      error= fatal_error(ER_OPTION_PREVENTS_STATEMENT, "--secure-file-priv");
+      error= report_error(ER_OPTION_PREVENTS_STATEMENT, "--secure-file-priv");
       break;
     case ER_BACKUP_WRITE_LOC:
       /*
         For this error, use the actual value returned instead of the
         path complimented with backupdir.
       */
-      error= fatal_error(ER_BACKUP_WRITE_LOC, location->str);
+      error= report_error(ER_BACKUP_WRITE_LOC, location->str);
       break;
     case ER_BACKUP_READ_LOC:
       /*
         For this error, use the actual value returned instead of the
         path complimented with backupdir.
       */
-      error= fatal_error(ER_BACKUP_READ_LOC, location->str);
+      error= report_error(ER_BACKUP_READ_LOC, location->str);
       break;
     default:
       DBUG_ASSERT(FALSE);
   }
-  return error;
+  return fatal_error(error);
 }
 
 namespace backup {
@@ -1485,6 +1473,7 @@ int bcat_reset(st_bstream_image_header *
 
   DBUG_ASSERT(catalogue);
   Restore_info *info= static_cast<Restore_info*>(catalogue);
+  Logger &log= info->m_log;
 
   /*
     Iterate over the list of snapshots read from the backup image (and stored
@@ -1509,50 +1498,50 @@ int bcat_reset(st_bstream_image_header *
 
       if (!se || !hton)
       {
-        info->m_ctx.fatal_error(ER_BACKUP_CANT_FIND_SE, name_lex.str);
+        log.report_error(ER_BACKUP_CANT_FIND_SE, name_lex.str);
         return BSTREAM_ERROR;
       }
 
       if (!hton->get_backup_engine)
       {
-        info->m_ctx.fatal_error(ER_BACKUP_NO_NATIVE_BE, name_lex.str);
+        log.report_error(ER_BACKUP_NO_NATIVE_BE, name_lex.str);
         return BSTREAM_ERROR;
       }
 
-      info->m_snap[n]= new Native_snapshot(info->m_ctx, snap->version, se);
+      info->m_snap[n]= new Native_snapshot(log, snap->version, se);
                                                               // reports errors
       break;
     }
 
     case BI_NODATA:
-      info->m_snap[n]= new Nodata_snapshot(info->m_ctx, snap->version);
+      info->m_snap[n]= new Nodata_snapshot(log, snap->version);
                                                               // reports errors
       break;
 
     case BI_CS:
-      info->m_snap[n]= new CS_snapshot(info->m_ctx, snap->version);
+      info->m_snap[n]= new CS_snapshot(log, snap->version);
                                                               // reports errors
       break;
 
     case BI_DEFAULT:
-      info->m_snap[n]= new Default_snapshot(info->m_ctx, snap->version);
+      info->m_snap[n]= new Default_snapshot(log, snap->version);
                                                               // reports errors
       break;
 
     default:
       // note: we use convention that snapshots are counted starting from 1.
-      info->m_ctx.fatal_error(ER_BACKUP_UNKNOWN_BE, n + 1);
+      log.report_error(ER_BACKUP_UNKNOWN_BE, n + 1);
       return BSTREAM_ERROR;
     }
 
     if (!info->m_snap[n])
     {
-      info->m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+      log.report_error(ER_OUT_OF_RESOURCES);
       return BSTREAM_ERROR;
     }
 
     info->m_snap[n]->m_num= n + 1;
-    info->m_ctx.report_driver(info->m_snap[n]->name());
+    log.report_driver(info->m_snap[n]->name());
   }
 
   return BSTREAM_OK;
@@ -1582,6 +1571,7 @@ int bcat_add_item(st_bstream_image_heade
   using namespace backup;
 
   Restore_info *info= static_cast<Restore_info*>(catalogue);
+  Logger &log= info->m_log;
 
   backup::String name_str(item->name.begin, item->name.end);
 
@@ -1622,7 +1612,7 @@ int bcat_add_item(st_bstream_image_heade
         with error earlier.
        */
       DBUG_ASSERT(it->snap_num >= info->snap_count());
-      info->m_ctx.fatal_error(ER_BACKUP_WRONG_TABLE_BE, it->snap_num + 1);
+      log.report_error(ER_BACKUP_WRONG_TABLE_BE, it->snap_num + 1);
       return BSTREAM_ERROR;
     }
 
@@ -1686,6 +1676,7 @@ void* bcat_iterator_get(st_bstream_image
   DBUG_ASSERT(catalogue);
 
   Backup_info *info= static_cast<Backup_info*>(catalogue);
+  backup::Logger &log= info->m_log;
 
   switch (type) {
 
@@ -1704,7 +1695,7 @@ void* bcat_iterator_get(st_bstream_image
     Iterator *it= info->get_tablespaces();
     if (!it) 
     {
-      info->m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+      log.report_error(ER_OUT_OF_RESOURCES);
       return NULL;
     }
   
@@ -1716,7 +1707,7 @@ void* bcat_iterator_get(st_bstream_image
     Iterator *it= info->get_dbs();
     if (!it) 
     {
-      info->m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+      log.report_error(ER_OUT_OF_RESOURCES);
       return NULL;
     }
 
@@ -1729,7 +1720,7 @@ void* bcat_iterator_get(st_bstream_image
   
     if (!it)
     {
-      info->m_ctx.fatal_error(ER_BACKUP_CAT_ENUM);
+      log.report_error(ER_BACKUP_CAT_ENUM);
       return NULL;
     }
 
@@ -1820,18 +1811,19 @@ void* bcat_db_iterator_get(st_bstream_im
   DBUG_ASSERT(dbi);
   
   Backup_info *info= static_cast<Backup_info*>(catalogue);
+  backup::Logger &log= info->m_log;
   Backup_info::Db *db = info->get_db(dbi->base.pos);
 
   if (!db)
   {
-    info->m_ctx.fatal_error(ER_BACKUP_UNKNOWN_OBJECT);
+    log.report_error(ER_BACKUP_UNKNOWN_OBJECT);
     return NULL;
   }
 
   backup::Image_info::Iterator *it= info->get_db_objects(*db);
   if (!it)
   {
-    info->m_ctx.fatal_error(ER_OUT_OF_RESOURCES);
+    log.report_error(ER_OUT_OF_RESOURCES);
     return NULL;
   }
 
@@ -1884,7 +1876,8 @@ int bcat_create_item(st_bstream_image_he
   DBUG_ASSERT(item);
 
   Restore_info *info= static_cast<Restore_info*>(catalogue);
-  THD *thd= info->m_ctx.thd();
+  Logger &log= info->m_log;
+  THD *thd= info->m_thd;
   int create_err= 0;
 
   switch (item->type) {
@@ -1906,7 +1899,7 @@ int bcat_create_item(st_bstream_image_he
   */
 
   default:
-    info->m_ctx.fatal_error(ER_BACKUP_UNKNOWN_OBJECT_TYPE);
+    log.report_error(ER_BACKUP_UNKNOWN_OBJECT_TYPE);
     return BSTREAM_ERROR;    
   }
 
@@ -1914,7 +1907,7 @@ int bcat_create_item(st_bstream_image_he
 
   if (!obj)
   {
-    info->m_ctx.fatal_error(ER_BACKUP_UNKNOWN_OBJECT);
+    log.report_error(ER_BACKUP_UNKNOWN_OBJECT);
     return BSTREAM_ERROR;
   }
 
@@ -1933,7 +1926,7 @@ int bcat_create_item(st_bstream_image_he
 
   if (!sobj)
   {
-    info->m_ctx.fatal_error(create_err, desc);
+    log.report_error(create_err, desc);
     return BSTREAM_ERROR;
   }
 
@@ -1981,7 +1974,7 @@ int bcat_create_item(st_bstream_image_he
 
       DBUG_PRINT("restore",
                  (" tablespace has changed on the server - aborting"));
-      info->m_ctx.fatal_error(ER_BACKUP_TS_CHANGE, desc);
+      log.report_error(ER_BACKUP_TS_CHANGE, desc);
       delete ts;
       return BSTREAM_ERROR;
     }
@@ -2004,10 +1997,10 @@ int bcat_create_item(st_bstream_image_he
     */
     if (!obs::check_user_existence(thd, sobj))
     {
-      info->m_ctx.report_error(log_level::WARNING,
-                               ER_BACKUP_GRANT_SKIPPED,
-                               obs::grant_get_grant_info(sobj)->ptr(),
-                               obs::grant_get_user_name(sobj)->ptr());
+      log.report_error(log_level::WARNING,
+                       ER_BACKUP_GRANT_SKIPPED,
+                       obs::grant_get_grant_info(sobj)->ptr(),
+                       obs::grant_get_user_name(sobj)->ptr());
       return BSTREAM_OK;
     }
     /*
@@ -2027,14 +2020,14 @@ int bcat_create_item(st_bstream_image_he
     db_name.append(start, size);
     if (!info->has_db(db_name))
     {
-      info->m_ctx.fatal_error(ER_BACKUP_GRANT_WRONG_DB, create_stmt);
+      log.report_error(ER_BACKUP_GRANT_WRONG_DB, create_stmt);
       return BSTREAM_ERROR;
     }
   }
 
   if (sobj->create(thd))
   {
-    info->m_ctx.fatal_error(create_err, desc);
+    log.report_error(create_err, desc);
     return BSTREAM_ERROR;
   }
   
@@ -2105,11 +2098,12 @@ int bcat_get_item_create_query(st_bstrea
   ::String *buf= &(info->serialization_buf);
   buf->length(0);
 
-  if (obj->m_obj_ptr->serialize(info->m_ctx.thd(), buf))
+  if (obj->m_obj_ptr->serialize(info->m_thd, buf))
   {
     Image_info::Obj::describe_buf dbuf;
 
-    info->m_ctx.fatal_error(meta_err, obj->describe(dbuf));
+    info->m_log.report_error(meta_err, obj->describe(dbuf));
+
     return BSTREAM_ERROR;    
   }
 

=== modified file 'sql/backup/logger.cc'
--- a/sql/backup/logger.cc	2008-11-19 16:32:01 +0000
+++ b/sql/backup/logger.cc	2008-12-10 15:53:06 +0000
@@ -28,15 +28,27 @@ namespace backup {
   the moment. Destinations which are not ready/initialized yet should be 
   silently ignored.
 
-  @returns 0 on success.
+  @returns Reported error code.
  */
 int Logger::write_message(log_level::value level, int error_code,
                           const char *msg)
 {
    char buf[ERRMSGSIZE + 30];
+   /*
+     When logging to server's error log, msg will be prefixed with
+     "Backup:"/"Restore:" if the operation has been initialized (i.e., after
+     Logger::init() call). For other destinations, msg is reported as it is.
+     
+     Pointer out points at output string for server's error log, which has the
+     prefix added if needed.
+    */ 
    const char *out= msg;
 
-   if (m_state == READY || m_state == RUNNING)
+   /*
+     Note: m_type is meaningful only after a call to init() i.e., 
+     if m_state != CREATED.
+   */ 
+   if (m_state != CREATED)
    {
      my_snprintf(buf, sizeof(buf), "%s: %s", 
                  m_type == BACKUP ? "Backup" : "Restore" , msg);
@@ -45,43 +57,61 @@ int Logger::write_message(log_level::val
    
    switch (level) {
    case log_level::ERROR:
-     if (m_save_errors)
-     {
-       error.code= error_code;
-       error.level= MYSQL_ERROR::WARN_LEVEL_ERROR;
-       error.msg= sql_strdup(msg);
-     }
+   {
+     // Report to server's error log
 
      sql_print_error("%s", out);
-     if (m_push_errors)
-       push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-			   error_code, "%s", msg);
-     DBUG_PRINT("backup_log",("[ERROR] %s", out));
-     
+
+     // Report to the client
+
+     bool saved_value= m_thd->no_warnings_for_error;
+     m_thd->no_warnings_for_error= m_push_errors ? FALSE : TRUE;
+     my_printf_error(error_code, msg, MYF(0));
+     m_thd->no_warnings_for_error= saved_value;
+ 
+     m_error_reported= TRUE;
+
+     // Report to backup logs
+
      if (m_state == READY || m_state == RUNNING)
      {
        time_t ts = my_time(0);
 
        backup_log->error_num(error_code);
-       backup_log->write_progress(0, ts, ts, 0, 0, error_code, out);
+       backup_log->write_progress(0, ts, ts, 0, 0, error_code, msg);
      }
      
-     return 0;
+     // Report in the debug trace
+     
+     DBUG_PRINT("backup_log",("[ERROR] %s", out));
+     
+     return error_code;
+   }
 
    case log_level::WARNING:
+     // Report to server's error log
      sql_print_warning("%s", out);
+
+     // Report to the client (push on warning stack)
      if (m_push_errors)
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                            error_code, "%s", msg);
+
+     // Report to the debug trace
      DBUG_PRINT("backup_log",("[Warning] %s", out));
-     return 0;
+
+     return error_code;
 
    case log_level::INFO:
+     // Report to server's error log
      sql_print_information("%s", out);
+
+     // Report to the debug trace
      DBUG_PRINT("backup_log",("[Info] %s", out));
-     return 0;
 
-   default: return ERROR;
+     return error_code;
+
+   default: DBUG_ASSERT(0); return ERROR;
    }
 }
 
@@ -94,7 +124,7 @@ int Logger::write_message(log_level::val
   If the message contains placeholders, additional arguments provide
   values to be put there.
 
-  @returns 0 on success.
+  @returns Reported error code.
  */
 int Logger::v_report_error(log_level::value level, int error_code, va_list args)
 {
@@ -125,6 +155,45 @@ void Logger::report_stats_pre(const Imag
 {
   DBUG_ASSERT(m_state == RUNNING);
   backup_log->num_objects(info.table_count());
+  // Compose list of databases.
+
+  Image_info::Db_iterator *it= info.get_dbs();
+  Image_info::Obj *db;
+  Image_info::Obj::describe_buf name_buf;
+  String dbs;
+
+  while((db= (*it)++))
+  {
+    if (!dbs.is_empty())
+      dbs.append(",");
+    const size_t len= strnlen(db->describe(name_buf), sizeof(name_buf));
+    /*
+      If appending next database name would create too long string, append
+      ellipsis instead and break the loop.
+      
+      The length limit 220-4 is computed as follows. The placeholder for 
+      database list in ER_BACKUP_BACKUP/RESTORE_DBS has maximum width 220 from
+      which we subtract 4 for ",...", which should fit if the loop iterates 
+      once more.
+
+      The width 220 for database list placeholder is chosen so that a complete 
+      message fits into 256 characters.
+    */
+    if (dbs.length() + len > 220-4)
+    {
+      dbs.append("...");
+      break;
+    }
+    dbs.append(name_buf);
+  }
+
+  delete it;
+
+  // Log the databases.
+
+  report_error(log_level::INFO, m_type == BACKUP ? ER_BACKUP_BACKUP_DBS
+                                                 : ER_BACKUP_RESTORE_DBS, 
+                                info.db_count(), dbs.c_ptr());
 }
 
 /**

=== modified file 'sql/backup/logger.h'
--- a/sql/backup/logger.h	2008-11-14 15:02:10 +0000
+++ b/sql/backup/logger.h	2008-12-10 15:53:06 +0000
@@ -51,6 +51,7 @@ class Logger
    int report_error(log_level::value level, int error_code, ...);
    int report_error(const char *format, ...);
    int write_message(log_level::value level, const char *msg, ...);
+   int log_error(int error_code, ...);
 
    void report_start(time_t);
    void report_stop(time_t, bool);
@@ -68,11 +69,8 @@ class Logger
      return backup_log->get_backup_id(); 
    }
    
-   void save_errors();
-   void stop_save_errors();
-   void clear_saved_errors();
-   util::SAVED_MYSQL_ERROR *last_saved_error();
    bool push_errors(bool);
+   bool error_reported() const;
 
  protected:
 
@@ -84,30 +82,26 @@ class Logger
   int write_message(log_level::value level , int error_code, const char *msg);
 
  private:
+
   // Prevent copying/assigments
   Logger(const Logger&);
   Logger& operator=(const Logger&);
 
-  util::SAVED_MYSQL_ERROR error;   ///< Used to store saved errors.
-  bool m_save_errors;        ///< Flag telling if errors should be saved.
   bool m_push_errors;        ///< Should errors be pushed on warning stack?
+  bool m_error_reported;     ///< Has any error been reported?
 
   Backup_log *backup_log;    ///< Backup log interface class.
 };
 
 inline
 Logger::Logger(THD *thd) 
-  :m_type(BACKUP), m_state(CREATED),
-   m_thd(thd), m_save_errors(FALSE), m_push_errors(TRUE), backup_log(0)
-{
-  clear_saved_errors();
-}
- 
+   :m_type(BACKUP), m_state(CREATED), m_thd(thd), m_push_errors(TRUE), 
+    m_error_reported(FALSE), backup_log(0)
+{}
 
 inline
 Logger::~Logger()
 {
-  clear_saved_errors();
   delete backup_log;
 }
 
@@ -163,37 +157,20 @@ int Logger::report_error(const char *for
   return res;
 }
 
-///  Request that all reported errors are saved in the logger.
-inline
-void Logger::save_errors()
-{
-  if (m_save_errors)
-    return;
-  clear_saved_errors();
-  m_save_errors= TRUE;
-}
-
-/// Stop saving errors.
+/// Reports error without pushing it on server's error stack.
 inline
-void Logger::stop_save_errors()
+int Logger::log_error(int error_code, ...)
 {
-  if (!m_save_errors)
-    return;
-  m_save_errors= FALSE;
-}
+  va_list args;
+  bool    saved= push_errors(FALSE);
+  
+  va_start(args, error_code);
+  int res= v_report_error(log_level::ERROR, error_code, args);
+  va_end(args);
 
-/// Delete all saved errors to free resources.
-inline
-void Logger::clear_saved_errors()
-{
-  memset(&error, 0, sizeof(error));
-}
+  push_errors(saved);
 
-/// Return a pointer to most recent saved error.
-inline
-util::SAVED_MYSQL_ERROR *Logger::last_saved_error()
-{ 
-  return error.code ? &error : NULL;
+  return res;
 }
 
 /// Report start of an operation.
@@ -328,7 +305,7 @@ void Logger::report_backup_file(char *pa
     
   @returns 0 on success, error code otherwise.
 
-  @todo Decide what to do if @c initialize() signals errors.
+  @todo Detect, log and report errors to the caller.
   @todo Add code to get the user comment from command.
 */ 
 inline
@@ -338,13 +315,19 @@ int Logger::init(enum_type type, const c
     return 0;
 
   m_type= type;
-  m_state= READY;
   backup_log = new Backup_log(m_thd, (enum_backup_operation)type, query);
   backup_log->state(BUP_STARTING);
+  m_state= READY;
   DEBUG_SYNC(m_thd, "after_backup_log_init");
   return 0;
 }
 
+inline
+bool Logger::error_reported() const
+{
+  return m_error_reported;
+}
+
 } // backup namespace
 
 #endif

=== modified file 'sql/backup/restore_info.h'
--- a/sql/backup/restore_info.h	2008-11-13 13:02:36 +0000
+++ b/sql/backup/restore_info.h	2008-11-25 17:44:19 +0000
@@ -33,9 +33,8 @@ class Restore_info: public backup::Image
 {
  public:
 
-  Backup_restore_ctx &m_ctx;
+  backup::Logger &m_log;
 
-  Restore_info(Backup_restore_ctx&);
   ~Restore_info();
 
   bool is_valid() const;
@@ -47,19 +46,32 @@ class Restore_info: public backup::Image
 
  private:
 
+  /*
+    Note: constructor is private because instances of this class are supposed
+    to be created only with Backup_restore_ctx::prepare_for_restore() method.
+  */
+  Restore_info(backup::Logger&, THD*);
+
   // Prevent copying/assignments
   Restore_info(const Restore_info&);
   Restore_info& operator=(const Restore_info&);
 
+  THD *m_thd;
+
   friend int backup::restore_table_data(THD*, Restore_info&, 
                                         backup::Input_stream&);
   friend int ::bcat_add_item(st_bstream_image_header*,
                              struct st_bstream_item_info*);
+  friend int ::bcat_create_item(st_bstream_image_header *catalogue,
+                                struct st_bstream_item_info *item,
+                                bstream_blob create_stmt,
+                                bstream_blob other_meta_data);
+  friend class Backup_restore_ctx;    // Needs access to the constructor.
 };
 
 inline
-Restore_info::Restore_info(Backup_restore_ctx &ctx)
-  :m_ctx(ctx)
+Restore_info::Restore_info(backup::Logger &log, THD *thd)
+  :m_log(log), m_thd(thd)
 {}
 
 inline
@@ -86,7 +98,7 @@ Restore_info::add_ts(const ::String &nam
   Ts *ts= Image_info::add_ts(name, pos);
 
   if (!ts)
-    m_ctx.fatal_error(ER_BACKUP_CATALOG_ADD_TS, name.ptr());
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_TS, name.ptr());
 
   return ts;
 }
@@ -99,7 +111,7 @@ Restore_info::add_db(const ::String &nam
   Db *db= Image_info::add_db(name, pos);
 
   if (!db)
-    m_ctx.fatal_error(ER_BACKUP_CATALOG_ADD_DB, name.ptr());
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_DB, name.ptr());
 
   return db;
 }
@@ -113,7 +125,7 @@ Restore_info::add_table(Image_info::Db &
   Table *t= Image_info::add_table(db, name, snap, pos);
 
   if (!t)
-    m_ctx.fatal_error(ER_BACKUP_CATALOG_ADD_TABLE, db.name().ptr(), name.ptr());
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_TABLE, db.name().ptr(), name.ptr());
 
   return t;
 }

=== modified file 'sql/backup/stream.cc'
--- a/sql/backup/stream.cc	2008-10-15 20:00:48 +0000
+++ b/sql/backup/stream.cc	2008-12-08 11:24:51 +0000
@@ -238,7 +238,7 @@ int Stream::open()
   if (!test_secure_file_priv_access(m_path->c_ptr()))
     return ER_OPTION_PREVENTS_STATEMENT;
 
-  m_fd= my_open(m_path->c_ptr(), m_flags, MYF(0));
+  m_fd= get_file();
 
   if (!(m_fd >= 0))
     return -1;
@@ -472,6 +472,15 @@ bool Output_stream::rewind()
   return init();
 }
 
+/**
+  Create file to be written to
+
+  @return File descriptor
+*/
+File Output_stream::get_file() 
+{
+  return my_create(m_path->c_ptr(), 0, m_flags, MYF(MY_WME)); // reports errors
+}
 
 Input_stream::Input_stream(Logger &log, ::String *path)
   :Stream(log, path, O_RDONLY)
@@ -651,4 +660,14 @@ int Input_stream::next_chunk()
   return bstream_next_chunk(this);
 }
 
+/**
+  Open file that will be read from
+
+  @return File descriptor
+*/
+File Input_stream::get_file() 
+{
+  return my_open(m_path->c_ptr(), m_flags, MYF(MY_WME));  // reports errors
+}
+
 } // backup namespace

=== modified file 'sql/backup/stream.h'
--- a/sql/backup/stream.h	2008-11-13 13:02:36 +0000
+++ b/sql/backup/stream.h	2008-12-08 11:24:51 +0000
@@ -100,6 +100,9 @@ class Stream: public fd_stream
   size_t  m_block_size;
   Logger&  m_log;
 
+  virtual File get_file() = 0; // Create or open file
+
+
   friend int stream_write(void*, bstream_blob*, bstream_blob);
   friend int stream_read(void*, bstream_blob*, bstream_blob);
 
@@ -121,6 +124,10 @@ class Output_stream:
   bool close();
   bool rewind();
 
+ protected:
+
+  virtual File get_file();
+
  private:
 
   int write_magic_and_version();
@@ -141,6 +148,10 @@ class Input_stream:
 
   int next_chunk();
 
+ protected:
+
+  virtual File get_file();
+
  private:
 
   int check_magic_and_version();

=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc	2008-10-01 10:18:19 +0000
+++ b/sql/event_db_repository.cc	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004-2006 MySQL AB
+/* Copyright 2004-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/event_parse_data.cc'
--- a/sql/event_parse_data.cc	2008-08-18 11:05:51 +0000
+++ b/sql/event_parse_data.cc	2008-11-10 20:21:49 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/event_parse_data.h'
--- a/sql/event_parse_data.h	2008-08-18 11:05:51 +0000
+++ b/sql/event_parse_data.h	2008-11-10 20:21:49 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2008-12-11 18:04:55 +0000
+++ b/sql/field.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/field.h'
--- a/sql/field.h	2008-12-08 21:15:06 +0000
+++ b/sql/field.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/gen_lex_hash.cc'
--- a/sql/gen_lex_hash.cc	2008-04-28 16:24:05 +0000
+++ b/sql/gen_lex_hash.cc	2008-12-09 18:59:54 +0000
@@ -451,7 +451,7 @@ int main(int argc,char **argv)
   printf("/*\n\n  Do " "not " "edit " "this " "file " "directly!\n\n*/\n");
 
   printf("\
-/* Copyright (C) 2001-2004 MySQL AB\n\
+/* Copyright 2001-2008 MySQL AB, 2008 Sun Microsystems, Inc.\n\
 \n\
    This program is free software; you can redistribute it and/or modify\n\
    it under the terms of the GNU General Public License as published by\n\

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2008-12-08 21:15:06 +0000
+++ b/sql/ha_ndbcluster.cc	2008-12-13 11:02:16 +0000
@@ -67,12 +67,22 @@ TYPELIB ndb_distribution_typelib= { arra
 const char *opt_ndb_distribution= ndb_distribution_names[ND_KEYHASH];
 enum ndb_distribution opt_ndb_distribution_id= ND_KEYHASH;
 
+/*
+  Provided for testing purposes to be able to run full test suite
+  with --ndbcluster option without getting warnings about cluster
+  not being connected
+*/
+my_bool ndbcluster_silent= 0;
+
 // Default value for parallelism
 static const int parallelism= 0;
 
-// Default value for max number of transactions
-// createable against NDB from this handler
-static const int max_transactions= 3; // should really be 2 but there is a transaction to
much allocated when loch table is used
+/*
+  Default value for max number of transactions createable against NDB from
+  the handler. Should really be 2 but there is a transaction to much allocated
+  when lock table is used, and one extra to used for global schema lock.
+*/
+static const int max_transactions= 4;
 
 static uint ndbcluster_partition_flags();
 static int ndbcluster_init(void *);
@@ -118,7 +128,7 @@ static uint ndbcluster_alter_partition_f
   return HA_PARTITION_FUNCTION_SUPPORTED;
 }
 
-#define NDB_AUTO_INCREMENT_RETRIES 10
+#define NDB_AUTO_INCREMENT_RETRIES 100
 #define BATCH_FLUSH_SIZE (32768)
 
 #define ERR_PRINT(err) \
@@ -157,10 +167,12 @@ static uchar *ndbcluster_get_key(NDB_SHA
 static
 NdbRecord *
 ndb_get_table_statistics_ndbrecord(NDBDICT *, const NDBTAB *);
-static int ndb_get_table_statistics(ha_ndbcluster*, bool, Ndb*, const NDBTAB *, 
-                                    struct Ndb_statistics *);
-static int ndb_get_table_statistics(ha_ndbcluster*, bool, Ndb*,
-                                    const NdbRecord *, struct Ndb_statistics *);
+static int ndb_get_table_statistics(THD *thd, ha_ndbcluster*, bool, Ndb*, const NDBTAB *,

+                                    struct Ndb_statistics *,
+                                    bool have_lock= FALSE);
+static int ndb_get_table_statistics(THD *thd, ha_ndbcluster*, bool, Ndb*,
+                                    const NdbRecord *, struct Ndb_statistics *,
+                                    bool have_lock= FALSE);
 
 THD *injector_thd= 0;
 
@@ -352,6 +364,7 @@ Thd_ndb::Thd_ndb()
   ndb= new Ndb(connection, "");
   lock_count= 0;
   start_stmt_count= 0;
+  save_point_count= 0;
   count= 0;
   trans= NULL;
   m_error= FALSE;
@@ -360,6 +373,9 @@ Thd_ndb::Thd_ndb()
   (void) hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
                    (hash_get_key)thd_ndb_share_get_key, 0, 0);
   m_unsent_bytes= 0;
+  global_schema_lock_trans= NULL;
+  global_schema_lock_count= 0;
+  global_schema_lock_error= 0;
   init_alloc_root(&m_batch_mem_root, BATCH_FLUSH_SIZE/4, 0);
 }
 
@@ -367,19 +383,6 @@ Thd_ndb::~Thd_ndb()
 {
   if (ndb)
   {
-#ifndef DBUG_OFF
-    Ndb::Free_list_usage tmp;
-    tmp.m_name= 0;
-    while (ndb->get_free_list_usage(&tmp))
-    {
-      uint leaked= (uint) tmp.m_created - tmp.m_free;
-      if (leaked)
-        fprintf(stderr, "NDB: Found %u %s%s that %s not been released\n",
-                leaked, tmp.m_name,
-                (leaked == 1)?"":"'s",
-                (leaked == 1)?"has":"have");
-    }
-#endif
     delete ndb;
     ndb= NULL;
   }
@@ -499,7 +502,8 @@ static void set_ndb_err(THD *thd, const 
   DBUG_VOID_RETURN;
 }
 
-int ha_ndbcluster::ndb_err(NdbTransaction *trans)
+int ha_ndbcluster::ndb_err(NdbTransaction *trans,
+                           bool have_lock)
 {
   THD *thd= current_thd;
   int res;
@@ -518,7 +522,7 @@ int ha_ndbcluster::ndb_err(NdbTransactio
     bzero((char*) &table_list,sizeof(table_list));
     table_list.db= m_dbname;
     table_list.alias= table_list.table_name= m_tabname;
-    close_cached_tables(thd, &table_list, FALSE, FALSE);
+    close_cached_tables(thd, &table_list, have_lock, FALSE);
     break;
   }
   default:
@@ -660,6 +664,33 @@ ha_ndbcluster::copy_row_to_buffer(Thd_nd
   return row;
 }
 
+/**
+ * findBlobError
+ * This method attempts to find an error in the hierarchy of runtime
+ * NDBAPI objects from Blob up to transaction.
+ * It will return -1 if no error is found, 0 if an error is found.
+ */
+int findBlobError(NdbError& error, NdbBlob* pBlob)
+{
+  error= pBlob->getNdbError();
+  if (error.code != 0)
+    return 0;
+  
+  const NdbOperation* pOp= pBlob->getNdbOperation();
+  error= pOp->getNdbError();
+  if (error.code != 0)
+    return 0;
+  
+  NdbTransaction* pTrans= pOp->getNdbTransaction();
+  error= pTrans->getNdbError();
+  if (error.code != 0)
+    return 0;
+  
+  /* No error on any of the objects */
+  return -1;
+}
+
+
 int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg)
 {
   ha_ndbcluster *ha= (ha_ndbcluster *)arg;
@@ -738,7 +769,19 @@ int g_get_ndb_blobs_value(NdbBlob *ndb_b
       uchar *buf= ha->m_blobs_buffer + offset;
       uint32 len= ha->m_blobs_buffer_size - offset;
       if (ndb_blob->readData(buf, len) != 0)
-          ERR_RETURN(ndb_blob->getNdbError());
+      {
+        NdbError err;
+        if (findBlobError(err, ndb_blob) == 0)
+        {
+          ERR_RETURN(err);
+        }
+        else
+        {
+          /* Should always have some error code set */
+          assert(err.code != 0);
+          ERR_RETURN(err);
+        }
+      }   
       DBUG_PRINT("info", ("[%u] offset: %u  buf: %p  len=%u",
                           i, offset, buf, len));
       DBUG_ASSERT(len == len64);
@@ -2893,12 +2936,12 @@ int ha_ndbcluster::ndb_write_row(uchar *
     for (;;)
     {
       Ndb_tuple_id_range_guard g(m_share);
-      if (ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1) == -1)
+      if (ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1000) == -1)
       {
-	if (--retries &&
+	if (--retries && !thd->killed &&
 	    ndb->getNdbError().status == NdbError::TemporaryError)
 	{
-	  my_sleep(retry_sleep);
+	  do_retry_sleep(retry_sleep);
 	  continue;
 	}
 	ERR_RETURN(ndb->getNdbError());
@@ -3435,7 +3478,7 @@ int ha_ndbcluster::ndb_delete_row(const 
     /*
       Poor approx. let delete ~ tabsize / 4
     */
-    uint delete_size= 12 + m_bytes_per_write >> 2;
+    uint delete_size= 12 + (m_bytes_per_write >> 2);
     bool need_flush= add_row_check_if_batch_full_size(thd_ndb, delete_size);
     if ( (thd->options & OPTION_ALLOW_BATCH) &&
          table_share->primary_key != MAX_KEY &&
@@ -3833,6 +3876,14 @@ int ha_ndbcluster::rnd_init(bool scan)
 
 int ha_ndbcluster::close_scan()
 {
+  /*
+    workaround for bug #39872 - explain causes segv
+    - rnd_end/close_scan is called on unlocked table
+    - should be fixed in server code, but this will
+    not be done until 6.0 as it is too intrusive
+  */
+  if (m_thd_ndb == NULL)
+    return 0;
   NdbTransaction *trans= m_thd_ndb->trans;
   int error;
   DBUG_ENTER("close_scan");
@@ -4487,6 +4538,7 @@ int ha_ndbcluster::start_statement(THD *
   trans_register_ha(thd, FALSE, ndbcluster_hton);
   if (!thd_ndb->trans)
   {
+    DBUG_ASSERT(thd_ndb->changed_tables.is_empty() == TRUE);
     if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
       trans_register_ha(thd, TRUE, ndbcluster_hton);
     DBUG_PRINT("trans",("Starting transaction"));      
@@ -4515,6 +4567,11 @@ int ha_ndbcluster::start_statement(THD *
   {
     //lockThisTable();
     DBUG_PRINT("info", ("Locking the table..." ));
+#ifdef NOT_YET
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                        ER_GET_ERRMSG, ER(ER_GET_ERRMSG), 0,
+                        "Table only locked locally in this mysqld", "NDB");
+#endif
   }
   DBUG_RETURN(0);
 }
@@ -4636,15 +4693,17 @@ int ha_ndbcluster::external_lock(THD *th
   {
     DBUG_PRINT("info", ("lock_type == F_UNLCK"));
 
-    if (m_rows_changed)
+    if (m_rows_changed && global_system_variables.query_cache_type)
     {
       DBUG_PRINT("info", ("Rows has changed"));
 
-      if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+      if (thd_ndb->trans &&
+          thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
       {
-        DBUG_PRINT("info", ("Add share to list of changed tables"));
+        DBUG_PRINT("info", ("Add share to list of changed tables, %p",
+                            m_share));
         /* NOTE push_back allocates memory using transactions mem_root! */
-        thd_ndb->changed_tables.push_back(m_share,
+        thd_ndb->changed_tables.push_back(get_share(m_share),
                                           &thd->transaction.mem_root);
       }
 
@@ -4770,8 +4829,12 @@ static int ndbcluster_commit(handlerton 
   PRINT_OPTION_FLAGS(thd);
   DBUG_PRINT("enter", ("Commit %s", (all ? "all" : "stmt")));
   thd_ndb->start_stmt_count= 0;
-  if (trans == NULL || (!all &&
-      thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
+  if (trans == NULL)
+  {
+    DBUG_PRINT("info", ("trans == NULL"));
+    DBUG_RETURN(0);
+  }
+  if (!all && (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
   {
     /*
       An odditity in the handler interface is that commit on handlerton
@@ -4783,9 +4846,11 @@ static int ndbcluster_commit(handlerton 
       the MySQL Server could handle the query without contacting the
       NDB kernel.
     */
+    thd_ndb->save_point_count++;
     DBUG_PRINT("info", ("Commit before start or end-of-statement only"));
     DBUG_RETURN(0);
   }
+  thd_ndb->save_point_count= 0;
 
 #ifdef HAVE_NDB_BINLOG
   if (unlikely(thd_ndb->m_slow_path))
@@ -4833,12 +4898,15 @@ static int ndbcluster_commit(handlerton 
   List_iterator_fast<NDB_SHARE> it(thd_ndb->changed_tables);
   while ((share= it++))
   {
+    DBUG_PRINT("info", ("Remove share to list of changed tables, %p",
+                        share));
     pthread_mutex_lock(&share->mutex);
     DBUG_PRINT("info", ("Invalidate commit_count for %s, share->commit_count: %lu",
                         share->table_name, (ulong) share->commit_count));
     share->commit_count= 0;
     share->commit_count_lock++;
     pthread_mutex_unlock(&share->mutex);
+    free_share(&share);
   }
   thd_ndb->changed_tables.empty();
 
@@ -4858,16 +4926,32 @@ static int ndbcluster_rollback(handlerto
   NdbTransaction *trans= thd_ndb->trans;
 
   DBUG_ENTER("ndbcluster_rollback");
+  DBUG_PRINT("enter", ("all: %d  thd_ndb->save_point_count: %d",
+                       all, thd_ndb->save_point_count));
+  PRINT_OPTION_FLAGS(thd);
   DBUG_ASSERT(ndb);
   thd_ndb->start_stmt_count= 0;
-  if (trans == NULL || (!all &&
-      thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
+  if (trans == NULL)
   {
     /* Ignore end-of-statement until real rollback or commit is called */
+    DBUG_PRINT("info", ("trans == NULL"));
+    DBUG_RETURN(0);
+  }
+  if (!all && (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
&&
+      (thd_ndb->save_point_count > 0))
+  {
+    /*
+      Ignore end-of-statement until real rollback or commit is called
+      as ndb does not support rollback statement
+      - mark that rollback was unsuccessful, this will cause full rollback
+      of the transaction
+    */
     DBUG_PRINT("info", ("Rollback before start or end-of-statement only"));
+    mark_transaction_to_rollback(thd, 1);
+    my_error(ER_WARN_ENGINE_TRANSACTION_ROLLBACK, MYF(0), "NDB");
     DBUG_RETURN(0);
   }
-
+  thd_ndb->save_point_count= 0;
   if (trans->execute(NdbTransaction::Rollback) != 0)
   {
     const NdbError err= trans->getNdbError();
@@ -4881,6 +4965,14 @@ static int ndbcluster_rollback(handlerto
   thd_ndb->trans= NULL;
 
   /* Clear list of tables changed by transaction */
+  NDB_SHARE* share;
+  List_iterator_fast<NDB_SHARE> it(thd_ndb->changed_tables);
+  while ((share= it++))
+  {
+    DBUG_PRINT("info", ("Remove share to list of changed tables, %p",
+                        share));
+    free_share(&share);
+  }
   thd_ndb->changed_tables.empty();
 
   DBUG_RETURN(res);
@@ -5364,18 +5456,6 @@ int ha_ndbcluster::create(const char *na
   NDBDICT *dict= ndb->getDictionary();
 
   DBUG_PRINT("info", ("Tablespace %s,%s", form->s->tablespace,
create_info->tablespace));
-  if (is_truncate)
-  {
-    {
-      Ndb_table_guard ndbtab_g(dict, m_tabname);
-      if (!(m_table= ndbtab_g.get_table()))
-	ERR_RETURN(dict->getNdbError());
-      m_table= NULL;
-    }
-    DBUG_PRINT("info", ("Dropping and re-creating table for TRUNCATE"));
-    if ((my_errno= delete_table(name)))
-      DBUG_RETURN(my_errno);
-  }
   table= form;
   if (create_from_engine)
   {
@@ -5394,6 +5474,12 @@ int ha_ndbcluster::create(const char *na
   }
 
 #ifdef HAVE_NDB_BINLOG
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
+
+  if (!((thd_ndb->options & TNO_NO_LOCK_SCHEMA_OP) ||
+        ndbcluster_has_global_schema_lock(thd_ndb)))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ha_ndbcluster::create"));
   /*
     Don't allow table creation unless
     schema distribution table is setup
@@ -5410,6 +5496,18 @@ int ha_ndbcluster::create(const char *na
     single_user_mode = NdbDictionary::Table::SingleUserModeReadWrite;
   }
 #endif /* HAVE_NDB_BINLOG */
+  if (is_truncate)
+  {
+    {
+      Ndb_table_guard ndbtab_g(dict, m_tabname);
+      if (!(m_table= ndbtab_g.get_table()))
+	ERR_RETURN(dict->getNdbError());
+      m_table= NULL;
+    }
+    DBUG_PRINT("info", ("Dropping and re-creating table for TRUNCATE"));
+    if ((my_errno= delete_table(name)))
+      DBUG_RETURN(my_errno);
+  }
 
   DBUG_PRINT("table", ("name: %s", m_tabname));  
   if (tab.setName(m_tabname))
@@ -5994,6 +6092,12 @@ int ha_ndbcluster::rename_table(const ch
   if (check_ndb_connection(thd))
     DBUG_RETURN(my_errno= HA_ERR_NO_CONNECTION);
 
+#ifdef HAVE_NDB_BINLOG
+  if (!ndbcluster_has_global_schema_lock(get_thd_ndb(thd)))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ha_ndbcluster::rename_table"));
+#endif
+
   Ndb *ndb= get_ndb(thd);
   ndb->setDatabaseName(old_dbname);
   dict= ndb->getDictionary();
@@ -6362,18 +6466,20 @@ retry_temporary_error1:
 int ha_ndbcluster::delete_table(const char *name)
 {
   THD *thd= current_thd;
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
   Ndb *ndb;
   int error= 0;
   DBUG_ENTER("ha_ndbcluster::delete_table");
   DBUG_PRINT("enter", ("name: %s", name));
 
-  if (thd == injector_thd)
+  if ((thd == injector_thd) ||
+      (thd_ndb->options & TNO_NO_NDB_DROP_TABLE))
   {
     /*
       Table was dropped remotely is already
       dropped inside ndb.
       Just drop local files.
-     */
+    */
     DBUG_RETURN(handler::delete_table(name));
   }
 
@@ -6388,7 +6494,6 @@ int ha_ndbcluster::delete_table(const ch
   if (!ndb_schema_share)
   {
     DBUG_PRINT("info", ("Schema distribution table not setup"));
-    DBUG_ASSERT(ndb_schema_share);
     error= HA_ERR_NO_CONNECTION;
     goto err;
   }
@@ -6400,7 +6505,14 @@ int ha_ndbcluster::delete_table(const ch
     goto err;
   }
 
-  ndb= get_ndb(thd);
+  ndb= thd_ndb->ndb;
+
+#ifdef HAVE_NDB_BINLOG
+  if (!ndbcluster_has_global_schema_lock(thd_ndb))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ha_ndbcluster::delete_table"));
+#endif
+
   /*
     Drop table in ndb.
     If it was already gone it might have been dropped
@@ -6455,10 +6567,10 @@ void ha_ndbcluster::get_auto_increment(u
         ndb->readAutoIncrementValue(m_table, g.range, auto_value) ||
         ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size,
increment, offset))
     {
-      if (--retries &&
+      if (--retries && !thd->killed &&
           ndb->getNdbError().status == NdbError::TemporaryError)
       {
-        my_sleep(retry_sleep);
+        do_retry_sleep(retry_sleep);
         continue;
       }
       const NdbError err= ndb->getNdbError();
@@ -6681,7 +6793,7 @@ int ha_ndbcluster::open(const char *name
     m_share= 0;
     DBUG_RETURN(res);
   }
-  if ((res= update_stats(thd, 1)) ||
+  if ((res= update_stats(thd, 1, true)) ||
       (res= info(HA_STATUS_CONST)))
   {
     free_share(&m_share);
@@ -6975,7 +7087,10 @@ err:
                              share->key, share->use_count));
     free_share(&share);
   }
-  if (ndb_error.code)
+  /*
+    ndbcluster_silent - avoid "cluster disconnected error"
+  */
+  if (ndb_error.code && (!ndbcluster_silent || ndb_error.code != 4009))
   {
     ERR_RETURN(ndb_error);
   }
@@ -6999,7 +7114,15 @@ int ndbcluster_table_exists_in_engine(ha
   NDBDICT* dict= ndb->getDictionary();
   NdbDictionary::Dictionary::List list;
   if (dict->listObjects(list, NdbDictionary::Object::UserTable) != 0)
+  {
+    /*
+      ndbcluster_silent
+      - avoid "cluster failure" warning if cluster is not connected
+    */
+    if (ndbcluster_silent && dict->getNdbError().code == 4009)
+      DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
     ERR_RETURN(dict->getNdbError());
+  }
   for (uint i= 0 ; i < list.count ; i++)
   {
     NdbDictionary::Dictionary::List::Element& elmt= list.elements[i];
@@ -7100,7 +7223,6 @@ static void ndbcluster_drop_database(han
   if (!ndb_schema_share)
   {
     DBUG_PRINT("info", ("Schema distribution table not setup"));
-    DBUG_ASSERT(ndb_schema_share);
     DBUG_VOID_RETURN;
   }
 #endif
@@ -7271,6 +7393,7 @@ int ndbcluster_find_files(handlerton *ht
   DBUG_PRINT("enter", ("db: %s", db));
   { // extra bracket to avoid gcc 2.95.3 warning
   uint i;
+  Thd_ndb *thd_ndb;
   Ndb* ndb;
   char name[FN_REFLEN];
   HASH ndb_tables, ok_tables;
@@ -7278,10 +7401,17 @@ int ndbcluster_find_files(handlerton *ht
 
   if (!(ndb= check_ndb_in_thd(thd)))
     DBUG_RETURN(HA_ERR_NO_CONNECTION);
+  thd_ndb= get_thd_ndb(thd);
 
   if (dir)
     DBUG_RETURN(0); // Discover of databases not yet supported
 
+#ifdef HAVE_NDB_BINLOG
+  Ndbcluster_global_schema_lock_guard ndbcluster_global_schema_lock_guard(thd);
+  if (ndbcluster_global_schema_lock_guard.lock())
+    DBUG_RETURN(HA_ERR_NO_CONNECTION);
+#endif
+
   // List tables in NDB
   NDBDICT *dict= ndb->getDictionary();
   if (dict->listObjects(list, 
@@ -7466,12 +7596,17 @@ int ndbcluster_find_files(handlerton *ht
       bzero((char*) &table_list,sizeof(table_list));
       table_list.db= (char*) db;
       table_list.alias= table_list.table_name= (char*)file_name_str;
+      /*
+        set TNO_NO_NDB_DROP_TABLE flag to not drop ndb table.
+        it should not exist anyways
+      */
+      thd_ndb->options|= TNO_NO_NDB_DROP_TABLE;
       (void)mysql_rm_table_part2(thd, &table_list,
                                  FALSE,   /* if_exists */
                                  FALSE,   /* drop_temporary */ 
                                  FALSE,   /* drop_view */
                                  TRUE     /* dont_log_query*/);
-
+      thd_ndb->options&= ~TNO_NO_NDB_DROP_TABLE;
       /* Clear error message that is returned when table is deleted */
       thd->clear_error();
     }
@@ -7569,6 +7704,7 @@ static int ndbcluster_init(void *p)
   ndbcluster_terminating= 0;
   ndb_dictionary_is_mysqld= 1;
   ndbcluster_hton= (handlerton *)p;
+  ndbcluster_global_schema_lock_init();
 
   {
     handlerton *h= ndbcluster_hton;
@@ -7621,6 +7757,7 @@ static int ndbcluster_init(void *p)
     pthread_mutex_destroy(&LOCK_ndb_util_thread);
     pthread_cond_destroy(&COND_ndb_util_thread);
     pthread_cond_destroy(&COND_ndb_util_ready);
+    ndbcluster_global_schema_lock_deinit();
     goto ndbcluster_init_error;
   }
 
@@ -7638,6 +7775,7 @@ static int ndbcluster_init(void *p)
     pthread_mutex_destroy(&LOCK_ndb_util_thread);
     pthread_cond_destroy(&COND_ndb_util_thread);
     pthread_cond_destroy(&COND_ndb_util_ready);
+    ndbcluster_global_schema_lock_deinit();
     goto ndbcluster_init_error;
   }
 
@@ -7692,22 +7830,6 @@ static int ndbcluster_end(handlerton *ht
 #endif
   hash_free(&ndbcluster_open_tables);
 
-  if (g_ndb)
-  {
-#ifndef DBUG_OFF
-    Ndb::Free_list_usage tmp;
-    tmp.m_name= 0;
-    while (g_ndb->get_free_list_usage(&tmp))
-    {
-      uint leaked= (uint) tmp.m_created - tmp.m_free;
-      if (leaked)
-        fprintf(stderr, "NDB: Found %u %s%s that %s not been released\n",
-                leaked, tmp.m_name,
-                (leaked == 1)?"":"'s",
-                (leaked == 1)?"has":"have");
-    }
-#endif
-  }
   ndbcluster_disconnect();
 
   // cleanup ndb interface
@@ -7717,6 +7839,7 @@ static int ndbcluster_end(handlerton *ht
   pthread_mutex_destroy(&LOCK_ndb_util_thread);
   pthread_cond_destroy(&COND_ndb_util_thread);
   pthread_cond_destroy(&COND_ndb_util_ready);
+  ndbcluster_global_schema_lock_deinit();
   DBUG_RETURN(0);
 }
 
@@ -8076,7 +8199,7 @@ uint ndb_get_commitcount(THD *thd, char 
   {
     Ndb_table_guard ndbtab_g(ndb->getDictionary(), tabname);
     if (ndbtab_g.get_table() == 0
-        || ndb_get_table_statistics(NULL, FALSE, ndb, ndbtab_g.get_table(), &stat))
+        || ndb_get_table_statistics(thd, NULL, FALSE, ndb, ndbtab_g.get_table(),
&stat))
     {
       /* ndb_share reference temporary free */
       DBUG_PRINT("NDB_SHARE", ("%s temporary free  use_count: %u",
@@ -8750,7 +8873,9 @@ struct ndb_table_statistics_row {
   Uint64 var_mem;
 };
 
-int ha_ndbcluster::update_stats(THD *thd, bool do_read_stat)
+int ha_ndbcluster::update_stats(THD *thd,
+                                bool do_read_stat,
+                                bool have_lock)
 {
   struct Ndb_statistics stat;
   Thd_ndb *thd_ndb= get_thd_ndb(thd);
@@ -8762,8 +8887,9 @@ int ha_ndbcluster::update_stats(THD *thd
     {
       DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
     }
-    if (int err= ndb_get_table_statistics(this, TRUE, ndb,
-                                          m_ndb_statistics_record, &stat))
+    if (int err= ndb_get_table_statistics(thd, this, TRUE, ndb,
+                                          m_ndb_statistics_record, &stat,
+                                          have_lock))
     {
       DBUG_RETURN(err);
     }
@@ -8830,15 +8956,16 @@ ndb_get_table_statistics_ndbrecord(NDBDI
 
 static 
 int
-ndb_get_table_statistics(ha_ndbcluster* file, bool report_error, Ndb* ndb,
+ndb_get_table_statistics(THD *thd, ha_ndbcluster* file, bool report_error, Ndb* ndb,
                          const NdbRecord *record,
-                         struct Ndb_statistics * ndbstat)
+                         struct Ndb_statistics * ndbstat,
+                         bool have_lock)
 {
   NdbTransaction* pTrans;
   NdbError error;
-  int retries= 10;
+  int retries= 100;
   int reterr= 0;
-  int retry_sleep= 30 * 1000; /* 30 milliseconds */
+  int retry_sleep= 30; /* 30 milliseconds */
   const char *row;
 #ifndef DBUG_OFF
   char buff[22], buff2[22], buff3[22], buff4[22];
@@ -8945,7 +9072,7 @@ retry:
     {
       if (file && pTrans)
       {
-        reterr= file->ndb_err(pTrans);
+        reterr= file->ndb_err(pTrans, have_lock);
       }
       else
       {
@@ -8962,9 +9089,10 @@ retry:
       ndb->closeTransaction(pTrans);
       pTrans= NULL;
     }
-    if (error.status == NdbError::TemporaryError && retries--)
+    if (error.status == NdbError::TemporaryError &&
+        retries-- && !thd->killed)
     {
-      my_sleep(retry_sleep);
+      do_retry_sleep(retry_sleep);
       continue;
     }
     break;
@@ -8979,9 +9107,10 @@ retry:
 */
 static 
 int
-ndb_get_table_statistics(ha_ndbcluster* file, bool report_error, Ndb* ndb,
+ndb_get_table_statistics(THD *thd, ha_ndbcluster* file, bool report_error, Ndb* ndb,
                          const NDBTAB *ndbtab,
-                         struct Ndb_statistics *ndbstat)
+                         struct Ndb_statistics *ndbstat,
+                         bool have_lock)
 {
   NDBDICT *dict= ndb->getDictionary();
   NdbRecord *rec= ndb_get_table_statistics_ndbrecord(dict, ndbtab);
@@ -8990,7 +9119,7 @@ ndb_get_table_statistics(ha_ndbcluster* 
     DBUG_ENTER("ndb_get_table_statistics");
     ERR_RETURN(dict->getNdbError());
   }
-  int res= ndb_get_table_statistics(file, report_error, ndb, rec, ndbstat);
+  int res= ndb_get_table_statistics(thd, file, report_error, ndb, rec, ndbstat);
   dict->releaseRecord(rec);
   return res;
 }
@@ -10159,7 +10288,7 @@ pthread_handler_t ndb_util_thread_func(v
         }
         Ndb_table_guard ndbtab_g(ndb->getDictionary(), share->table_name);
         if (ndbtab_g.get_table() &&
-            ndb_get_table_statistics(NULL, FALSE, ndb,
+            ndb_get_table_statistics(thd, NULL, FALSE, ndb,
                                      ndbtab_g.get_table(), &stat) == 0)
         {
 #ifndef DBUG_OFF
@@ -10904,6 +11033,12 @@ int ha_ndbcluster::alter_table_phase1(TH
   adding=  adding | HA_ADD_INDEX | HA_ADD_UNIQUE_INDEX;
   dropping= dropping | HA_DROP_INDEX | HA_DROP_UNIQUE_INDEX;
 
+#ifdef HAVE_NDB_BINLOG
+  if (!ndbcluster_has_global_schema_lock(get_thd_ndb(thd)))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ha_ndbcluster::alter_table_phase1"));
+#endif
+
   if (!(alter_data= new NDB_ALTER_DATA(dict, m_table)))
     DBUG_RETURN(HA_ERR_OUT_OF_MEM);
   old_tab= alter_data->old_table;
@@ -11094,6 +11229,12 @@ int ha_ndbcluster::alter_table_phase2(TH
   DBUG_ENTER("alter_table_phase2");
   dropping= dropping  | HA_DROP_INDEX | HA_DROP_UNIQUE_INDEX;
 
+#ifdef HAVE_NDB_BINLOG
+  if (!ndbcluster_has_global_schema_lock(get_thd_ndb(thd)))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ha_ndbcluster::alter_table_phase2"));
+#endif
+
   if ((*alter_flags & dropping).is_set())
   {
     /* Tell the handler to finally drop the indexes. */
@@ -11126,6 +11267,10 @@ int ha_ndbcluster::alter_table_phase3(TH
   DBUG_ENTER("alter_table_phase3");
 
 #ifdef HAVE_NDB_BINLOG
+  if (!ndbcluster_has_global_schema_lock(get_thd_ndb(thd)))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ha_ndbcluster::alter_table_phase3"));
+
   const char *db= table->s->db.str;
   const char *name= table->s->table_name.str;
   /*

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2008-08-26 20:38:29 +0000
+++ b/sql/ha_ndbcluster.h	2008-12-13 11:02:16 +0000
@@ -231,7 +231,19 @@ inline my_bool get_binlog_use_update(NDB
 
 enum THD_NDB_OPTIONS
 {
-  TNO_NO_LOG_SCHEMA_OP= 1 << 0
+  TNO_NO_LOG_SCHEMA_OP=  1 << 0,
+  /*
+    In participating mysqld, do not try to acquire global schema
+    lock, as one other mysqld already has the lock.
+  */
+  TNO_NO_LOCK_SCHEMA_OP= 1 << 1
+  /*
+    Skip drop of ndb table in delete_table.  Used when calling
+    mysql_rm_table_part2 in "show tables", as we do not want to
+    remove ndb tables "by mistake".  The table should not exist
+    in ndb in the first place.
+  */
+  ,TNO_NO_NDB_DROP_TABLE=    1 << 2
 };
 
 enum THD_NDB_TRANS_OPTIONS
@@ -260,6 +272,7 @@ class Thd_ndb 
   ulong count;
   uint lock_count;
   uint start_stmt_count;
+  uint save_point_count;
   NdbTransaction *trans;
   bool m_error;
   bool m_slow_path;
@@ -279,6 +292,9 @@ class Thd_ndb 
     we execute() to flush the rows buffered in m_batch_mem_root.
   */
   uint m_unsent_bytes;
+  NdbTransaction *global_schema_lock_trans;
+  uint global_schema_lock_count;
+  uint global_schema_lock_error;
 };
 
 class ha_ndbcluster: public handler
@@ -455,7 +471,7 @@ static void set_tabname(const char *path
   /*
    * Internal to ha_ndbcluster, used by C functions
    */
-  int ndb_err(NdbTransaction*);
+  int ndb_err(NdbTransaction*, bool have_lock= FALSE);
 
   my_bool register_query_cache_table(THD *thd, char *table_key,
                                      uint key_length,
@@ -718,7 +734,7 @@ private:
   NdbIndexScanOperation *m_multi_cursor;
   Ndb *get_ndb(THD *thd);
 
-  int update_stats(THD *thd, bool do_read_stat);
+  int update_stats(THD *thd, bool do_read_stat, bool have_lock= FALSE);
 };
 
 extern SHOW_VAR ndb_status_variables[];

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2008-12-11 18:04:55 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2008-12-13 11:02:16 +0000
@@ -24,10 +24,12 @@
 #include "rpl_injector.h"
 #include "rpl_filter.h"
 #include "slave.h"
+#include "sql_prepare.h"
 #include "ha_ndbcluster_binlog.h"
 #include <ndbapi/NdbDictionary.hpp>
 #include <ndbapi/ndb_cluster_connection.hpp>
 #include <util/NdbAutoPtr.hpp>
+#include <portlib/NdbTick.h>
 
 #ifdef ndb_dynamite
 #undef assert
@@ -39,6 +41,8 @@ extern my_bool opt_ndb_log_orig;
 extern my_bool opt_ndb_log_update_as_write;
 extern my_bool opt_ndb_log_updated_only;
 
+extern my_bool ndbcluster_silent;
+
 /*
   defines for cluster replication table names
 */
@@ -146,6 +150,8 @@ static char binlog_mdlkey[MAX_MDLKEY_LEN
 /*
   Helper functions
 */
+static bool ndbcluster_check_if_local_table(const char *dbname, const char *tabname);
+static bool ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname);
 
 #ifndef DBUG_OFF
 /* purecov: begin deadcode */
@@ -240,78 +246,58 @@ static void dbug_print_table(const char 
   - purging the ndb_binlog_index
   - creating the ndb_apply_status table
 */
+static void copy_warnings(THD *thd, List<MYSQL_ERROR> *src)
+{
+  List_iterator_fast<MYSQL_ERROR> err_it(*src);
+  MYSQL_ERROR *err;
+
+  while ((err= err_it++))
+    push_warning(thd, err->level, err->code, err->msg);
+}
 static void run_query(THD *thd, char *buf, char *end,
-                      const int *no_print_error, my_bool disable_binlog)
+                      const int *no_print_error, my_bool disable_binlog,
+                      my_bool reset_error)
 {
-  ulong save_thd_query_length= thd->query_length;
-  char *save_thd_query= thd->query;
-  ulong save_thread_id= thd->variables.pseudo_thread_id;
-  struct system_status_var save_thd_status_var= thd->status_var;
-  THD_TRANS save_thd_transaction_all= thd->transaction.all;
-  THD_TRANS save_thd_transaction_stmt= thd->transaction.stmt;
   ulonglong save_thd_options= thd->options;
   DBUG_ASSERT(sizeof(save_thd_options) == sizeof(thd->options));
-  NET save_thd_net= thd->net;
-  const char* found_semicolon= NULL;
 
-  bzero((char*) &thd->net, sizeof(NET));
-  thd->query_length= end - buf;
-  thd->query= buf;
-  thd->variables.pseudo_thread_id= thread_id;
-  thd->transaction.stmt.modified_non_trans_table= FALSE;
+  LEX_STRING query= {buf, end - buf};
   if (disable_binlog)
     thd->options&= ~OPTION_BIN_LOG;
-    
-  DBUG_PRINT("query", ("%s", thd->query));
+
+  DBUG_PRINT("query", ("%s", query.str));
 
   DBUG_ASSERT(!thd->in_sub_stmt);
   DBUG_ASSERT(!thd->locked_tables_mode);
 
-  mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
-
-  if (no_print_error && thd->is_slave_error)
   {
-    int i;
-    Thd_ndb *thd_ndb= get_thd_ndb(thd);
-    for (i= 0; no_print_error[i]; i++)
-      if ((thd_ndb->m_error_code == no_print_error[i]) ||
-          (thd->stmt_da->sql_errno() == (unsigned) no_print_error[i]))
-        break;
-    if (!no_print_error[i])
-      sql_print_error("NDB: %s: error %s %d(ndb: %d) %d %d",
-                      buf,
-                      thd->stmt_da->message(),
-                      thd->stmt_da->sql_errno(),
-                      thd_ndb->m_error_code,
-                      (int) thd->is_error(), thd->is_slave_error);
-  }
+    Ed_connection con(thd);
+    bool res= con.execute_direct(query);
 
-  /*
-    After executing statement we should unlock and close tables open
-    by it as well as release meta-data locks obtained by it.
-  */
-  close_thread_tables(thd);
+    if (no_print_error && res)
+    {
+      int i;
+      Thd_ndb *thd_ndb= get_thd_ndb(thd);
+      for (i= 0; no_print_error[i]; i++)
+        if ((thd_ndb->m_error_code == no_print_error[i]) ||
+            (con.get_last_errno() == (unsigned)no_print_error[i]))
+          break;
+      if (!no_print_error[i])
+        sql_print_error("NDB: %s: error %s %d(ndb: %d)",
+                        buf,
+                        con.get_last_error(),
+                        con.get_last_errno(),
+                        thd_ndb->m_error_code);
+    }
 
-  /*
-    XXX: this code is broken. mysql_parse()/mysql_reset_thd_for_next_command()
-    can not be called from within a statement, and
-    run_query() can be called from anywhere, including from within
-    a sub-statement.
-    This particular reset is a temporary hack to avoid an assert
-    for double assignment of the diagnostics area when run_query()
-    is called from ndbcluster_reset_logs(), which is called from
-    mysql_flush().
-  */
-  thd->stmt_da->reset_diagnostics_area();
+    if (res && !reset_error)
+    {
+      copy_warnings(thd, con.get_warn_list());
+      my_message(con.get_last_errno(), con.get_last_error(),
MYF(ME_NO_WARNING_FOR_ERROR));
+    }
+  }
 
   thd->options= save_thd_options;
-  thd->query_length= save_thd_query_length;
-  thd->query= save_thd_query;
-  thd->variables.pseudo_thread_id= save_thread_id;
-  thd->status_var= save_thd_status_var;
-  thd->transaction.all= save_thd_transaction_all;
-  thd->transaction.stmt= save_thd_transaction_stmt;
-  thd->net= save_thd_net;
 }
 
 static void
@@ -473,8 +459,14 @@ static void ndbcluster_binlog_wait(THD *
   if (ndb_binlog_running)
   {
     DBUG_ENTER("ndbcluster_binlog_wait");
-    const char *save_info= thd ? thd->proc_info : 0;
     ulonglong wait_epoch= ndb_get_latest_trans_gci();
+    /*
+      cluster not connected or no transactions done
+      so nothing to wait for
+    */
+    if (!wait_epoch)
+      DBUG_VOID_RETURN;
+    const char *save_info= thd ? thd->proc_info : 0;
     int count= 30;
     if (thd)
       THD_SET_PROC_INFO(thd,
@@ -504,6 +496,11 @@ static int ndbcluster_reset_logs(THD *th
   if (!ndb_binlog_running)
     return 0;
 
+  /* only reset master should reset logs */
+  if (!((thd->lex->sql_command == SQLCOM_RESET) &&
+        (thd->lex->type & REFRESH_MASTER)))
+    return 0;
+
   DBUG_ENTER("ndbcluster_reset_logs");
 
   /*
@@ -515,7 +512,26 @@ static int ndbcluster_reset_logs(THD *th
   char buf[1024];
   char *end= strmov(buf, "TRUNCATE " NDB_REP_DB "." NDB_REP_TABLE);
 
-  run_query(thd, buf, end, NULL, TRUE);
+  run_query(thd, buf, end, NULL, TRUE, FALSE);
+
+  /*
+    Calling function only expects and handles error cases,
+    so reset state if not an error as not to hit asserts
+    in upper layers
+  */
+  while (thd->stmt_da->is_error())
+  {
+    if (thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE)
+    {
+      /*
+        If table does not exist ignore the error as it
+        is a consistant behavior
+      */
+      break;
+    }
+    DBUG_RETURN(1);
+  }
+  thd->stmt_da->reset_diagnostics_area();
 
   DBUG_RETURN(0);
 }
@@ -540,7 +556,16 @@ ndbcluster_binlog_index_purge_file(THD *
                                   NDB_REP_DB "." NDB_REP_TABLE
                                   " WHERE File='"), file), "'");
 
-  run_query(thd, buf, end, NULL, TRUE);
+  run_query(thd, buf, end, NULL, TRUE, FALSE);
+  if (thd->stmt_da->is_error() &&
+      thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE)
+  {
+    /*
+      If table does not exist ignore the error as it
+      is a consistant behavior
+    */
+    thd->stmt_da->reset_diagnostics_area();
+  }
 
   DBUG_RETURN(0);
 }
@@ -657,7 +682,25 @@ static void ndbcluster_reset_slave(THD *
   DBUG_ENTER("ndbcluster_reset_slave");
   char buf[1024];
   char *end= strmov(buf, "DELETE FROM " NDB_REP_DB "." NDB_APPLY_TABLE);
-  run_query(thd, buf, end, NULL, TRUE);
+  run_query(thd, buf, end, NULL, TRUE, FALSE);
+  if (thd->stmt_da->is_error() &&
+      ((thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE) ||
+       (thd->stmt_da->sql_errno() == ER_OPEN_AS_READONLY &&
ndbcluster_silent)))
+  {
+    /*
+      If table does not exist ignore the error as it
+      is a consistant behavior
+    */
+    thd->stmt_da->reset_diagnostics_area();
+    /*
+      ndbcluster_silent
+      - avoid "no table mysql.ndb_apply_status" warning - ER_NO_SUCH_TABLE
+      - avoid "mysql.ndb_apply_status read only" warning - ER_OPEN_AS_READONLY
+    */
+    if (ndbcluster_silent)
+      thd->warning_info->clear_warning_info(thd->query_id);
+  }
+
   DBUG_VOID_RETURN;
 }
 
@@ -676,15 +719,212 @@ static bool ndbcluster_flush_logs(handle
   return FALSE;
 }
 
+/*
+  Global schema lock across mysql servers
+*/
+int ndbcluster_has_global_schema_lock(Thd_ndb *thd_ndb)
+{
+  if (thd_ndb->global_schema_lock_trans)
+  {
+    thd_ndb->global_schema_lock_trans->refresh();
+    return 1;
+  }
+  return 0;
+}
+
+int ndbcluster_no_global_schema_lock_abort(THD *thd, const char *msg)
+{
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
+  if (thd_ndb && thd_ndb->global_schema_lock_error != 0)
+    return HA_ERR_NO_CONNECTION;
+  sql_print_error("NDB: programming error, no lock taken while running "
+                  "query %s. Message: %s", thd->query, msg);
+  abort();
+}
+
+#include "ha_ndbcluster_lock_ext.h"
+
+/*
+  lock/unlock calls are reference counted, so calls to lock
+  must be matched to a call to unlock even if the lock call fails
+*/
+static int ndbcluster_global_schema_lock_is_locked_or_queued= 0;
+static int ndbcluster_global_schema_lock_no_locking_allowed= 0;
+static pthread_mutex_t ndbcluster_global_schema_lock_mutex;
+void ndbcluster_global_schema_lock_init()
+{
+  pthread_mutex_init(&ndbcluster_global_schema_lock_mutex, MY_MUTEX_INIT_FAST);
+}
+void ndbcluster_global_schema_lock_deinit()
+{
+  pthread_mutex_destroy(&ndbcluster_global_schema_lock_mutex);
+}
+
+static int ndbcluster_global_schema_lock(THD *thd, int no_lock_queue,
+                                         int report_cluster_disconnected)
+{
+  Ndb *ndb= check_ndb_in_thd(thd);
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
+  NdbError ndb_error;
+  if (thd_ndb->options & TNO_NO_LOCK_SCHEMA_OP)
+    return 0;
+  DBUG_ENTER("ndbcluster_global_schema_lock");
+  DBUG_PRINT("enter", ("query: %s, no_lock_queue: %d",
+                       thd->query, no_lock_queue));
+  if (thd_ndb->global_schema_lock_count)
+  {
+    if (thd_ndb->global_schema_lock_trans)
+      thd_ndb->global_schema_lock_trans->refresh();
+    else
+      DBUG_ASSERT(thd_ndb->global_schema_lock_error != 0);
+    thd_ndb->global_schema_lock_count++;
+    DBUG_PRINT("exit", ("global_schema_lock_count: %d",
+                        thd_ndb->global_schema_lock_count));
+    DBUG_RETURN(0);
+  }
+  DBUG_ASSERT(thd_ndb->global_schema_lock_count == 0);
+  thd_ndb->global_schema_lock_count= 1;
+  thd_ndb->global_schema_lock_error= 0;
+  DBUG_PRINT("exit", ("global_schema_lock_count: %d",
+                      thd_ndb->global_schema_lock_count));
+
+  /*
+    Check that taking the lock is allowed
+    - if not allowed to enter lock queue, return if lock exists
+    - wait until allowed
+    - increase global lock count
+  */
+  Thd_proc_info_guard thd_proc_info_guard(thd);
+  pthread_mutex_lock(&ndbcluster_global_schema_lock_mutex);
+  /* increase global lock count */
+  ndbcluster_global_schema_lock_is_locked_or_queued++;
+  if (no_lock_queue)
+  {
+    if (ndbcluster_global_schema_lock_is_locked_or_queued != 1)
+    {
+      /* Other thread has lock and this thread may not enter lock queue */
+      pthread_mutex_unlock(&ndbcluster_global_schema_lock_mutex);
+      thd_ndb->global_schema_lock_error= -1;
+      DBUG_PRINT("exit", ("aborting as lock exists"));
+      DBUG_RETURN(-1);
+    }
+    /* Mark that no other thread may be take lock */
+    ndbcluster_global_schema_lock_no_locking_allowed= 1;
+  }
+  else
+  {
+    while (ndbcluster_global_schema_lock_no_locking_allowed)
+    {
+      thd_proc_info(thd, "Waiting for allowed to take ndbcluster global schema lock");
+      /* Wait until locking is allowed */
+      pthread_mutex_unlock(&ndbcluster_global_schema_lock_mutex);
+      do_retry_sleep(50);
+      if (thd->killed)
+      {
+        thd_ndb->global_schema_lock_error= -1;
+        DBUG_RETURN(-1);
+      }
+      pthread_mutex_lock(&ndbcluster_global_schema_lock_mutex);
+    }
+  }
+  pthread_mutex_unlock(&ndbcluster_global_schema_lock_mutex);
+
+  /*
+    Take the lock
+  */
+  thd_proc_info(thd, "Waiting for ndbcluster global schema lock");
+  thd_ndb->global_schema_lock_trans=
+    ndbcluster_global_schema_lock_ext(thd, ndb, ndb_error, -1);
+
+  DBUG_EXECUTE_IF("sleep_after_global_schema_lock", my_sleep(6000000););
+
+  if (no_lock_queue)
+  {
+    pthread_mutex_lock(&ndbcluster_global_schema_lock_mutex);
+    /* Mark that other thread may be take lock */
+    ndbcluster_global_schema_lock_no_locking_allowed= 0;
+    pthread_mutex_unlock(&ndbcluster_global_schema_lock_mutex);
+  }
+
+  if (thd_ndb->global_schema_lock_trans)
+  {
+    DBUG_RETURN(0);
+  }
+
+  /*
+    ndbcluster_silent - avoid "cluster disconnected error"
+  */
+  if (ndbcluster_silent)
+    report_cluster_disconnected= 0;
+  if (ndb_error.code != 4009 || report_cluster_disconnected)
+  {
+    sql_print_warning("NDB: Could not acquire global schema lock (%d)%s",
+                      ndb_error.code, ndb_error.message);
+    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                        ER_GET_ERRMSG, ER(ER_GET_ERRMSG),
+                        ndb_error.code, ndb_error.message,
+                        "NDB. Could not acquire global schema lock");
+  }
+  thd_ndb->global_schema_lock_error= ndb_error.code ? ndb_error.code : -1;
+  DBUG_RETURN(-1);
+}
+static int ndbcluster_global_schema_unlock(THD *thd)
+{
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
+  DBUG_ASSERT(thd_ndb != 0);
+  if (thd_ndb == 0 || (thd_ndb->options & TNO_NO_LOCK_SCHEMA_OP))
+    return 0;
+  Ndb *ndb= thd_ndb->ndb;
+  DBUG_ENTER("ndbcluster_global_schema_unlock");
+  NdbTransaction *trans= thd_ndb->global_schema_lock_trans;
+  thd_ndb->global_schema_lock_count--;
+  DBUG_PRINT("exit", ("global_schema_lock_count: %d",
+                      thd_ndb->global_schema_lock_count));
+  DBUG_ASSERT(ndb != NULL);
+  if (ndb == NULL)
+    return 0;
+  DBUG_ASSERT(trans != NULL || thd_ndb->global_schema_lock_error != 0);
+  if (thd_ndb->global_schema_lock_count != 0)
+  {
+    DBUG_RETURN(0);
+  }
+  thd_ndb->global_schema_lock_error= 0;
+
+  /*
+    Decrease global lock count
+  */
+  pthread_mutex_lock(&ndbcluster_global_schema_lock_mutex);
+  ndbcluster_global_schema_lock_is_locked_or_queued--;
+  pthread_mutex_unlock(&ndbcluster_global_schema_lock_mutex);
+
+  if (trans)
+  {
+    thd_ndb->global_schema_lock_trans= NULL;
+    NdbError ndb_error;
+    if (ndbcluster_global_schema_unlock_ext(ndb, trans, ndb_error))
+    {
+      sql_print_warning("NDB: Releasing global schema lock (%d)%s",
+                        ndb_error.code, ndb_error.message);
+      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                          ER_GET_ERRMSG, ER(ER_GET_ERRMSG),
+                          ndb_error.code,
+                          ndb_error.message,
+                          "ndb. Releasing global schema lock");
+      DBUG_RETURN(-1);
+    }
+  }
+  DBUG_RETURN(0);
+}
+
 static int ndbcluster_binlog_func(handlerton *hton, THD *thd, 
                                   enum_binlog_func fn, 
                                   void *arg)
 {
+  DBUG_ENTER("ndbcluster_binlog_func");
   switch(fn)
   {
   case BFN_RESET_LOGS:
-    ndbcluster_reset_logs(thd);
-    break;
+    DBUG_RETURN(ndbcluster_reset_logs(thd));
   case BFN_RESET_SLAVE:
     ndbcluster_reset_slave(thd);
     break;
@@ -697,8 +937,35 @@ static int ndbcluster_binlog_func(handle
   case BFN_BINLOG_PURGE_FILE:
     ndbcluster_binlog_index_purge_file(thd, (const char *)arg);
     break;
+  case BFN_GLOBAL_SCHEMA_LOCK:
+    DBUG_RETURN(ndbcluster_global_schema_lock(thd, *(int*)arg, 1));
+    break;
+  case BFN_GLOBAL_SCHEMA_UNLOCK:
+    ndbcluster_global_schema_unlock(thd);
+    break;
   }
-  return 0;
+  DBUG_RETURN(0);
+}
+Ndbcluster_global_schema_lock_guard::Ndbcluster_global_schema_lock_guard(THD *thd)
+  : m_thd(thd), m_lock(0)
+{
+}
+Ndbcluster_global_schema_lock_guard::~Ndbcluster_global_schema_lock_guard()
+{
+  if (m_lock)
+    ndbcluster_global_schema_unlock(m_thd);
+}
+int Ndbcluster_global_schema_lock_guard::lock()
+{
+  /* only one lock call allowed */
+  DBUG_ASSERT(m_lock == 0);
+  /*
+    Always se m_lock, even if lock fails. Since the
+    lock/unlock calls are reference counted, the number
+    of calls to lock and unlock need to match up.
+  */
+  m_lock= 1;
+  return ndbcluster_global_schema_lock(m_thd, 0, 0);
 }
 
 void ndbcluster_binlog_init_handlerton()
@@ -794,7 +1061,7 @@ static int ndbcluster_create_ndb_apply_s
 
       end= strmov(buf, "FLUSH TABLE " NDB_REP_DB "." NDB_APPLY_TABLE);
       const int no_print_error[1]= {0};
-      run_query(thd, buf, end, no_print_error, TRUE);
+      run_query(thd, buf, end, no_print_error, TRUE, TRUE);
     }
   }
 
@@ -816,7 +1083,7 @@ static int ndbcluster_create_ndb_apply_s
                                 721, // Table already exist
                                 4009,
                                 0}; // do not print error 701 etc
-  run_query(thd, buf, end, no_print_error, TRUE);
+  run_query(thd, buf, end, no_print_error, TRUE, TRUE);
 
   DBUG_RETURN(0);
 }
@@ -867,7 +1134,7 @@ static int ndbcluster_create_schema_tabl
 
       end= strmov(buf, "FLUSH TABLE " NDB_REP_DB "." NDB_SCHEMA_TABLE);
       const int no_print_error[1]= {0};
-      run_query(thd, buf, end, no_print_error, TRUE);
+      run_query(thd, buf, end, no_print_error, TRUE, TRUE);
     }
   }
 
@@ -893,13 +1160,188 @@ static int ndbcluster_create_schema_tabl
                                 721, // Table already exist
                                 4009,
                                 0}; // do not print error 701 etc
-  run_query(thd, buf, end, no_print_error, TRUE);
+  run_query(thd, buf, end, no_print_error, TRUE, TRUE);
 
   DBUG_RETURN(0);
 }
 
+class Thd_ndb_options_guard
+{
+public:
+  Thd_ndb_options_guard(Thd_ndb *thd_ndb)
+    : m_val(thd_ndb->options), m_save_val(thd_ndb->options) {}
+  ~Thd_ndb_options_guard() { m_val= m_save_val; }
+  void set(uint32 flag) { m_val|= flag; }
+private:
+  uint32 &m_val;
+  uint32 m_save_val;
+};
+
+/*
+  Ndb has no representation of the database schema objects.
+  The mysql.ndb_schema table contains the latest schema operations
+  done via a mysqld, and thus reflects databases created/dropped/altered
+  while a mysqld was disconnected.  This function tries to recover
+  the correct state w.r.t created databases using the information in
+  that table.
+
+  Function should only be called while ndbcluster_global_schema_lock
+  is held, to ensure that ndb_schema table is not being updated while
+  scanning.
+*/
+static int ndbcluster_find_all_databases(THD *thd)
+{
+  Ndb *ndb= check_ndb_in_thd(thd);
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
+  Thd_ndb_options_guard thd_ndb_options(thd_ndb);
+  NDBDICT *dict= ndb->getDictionary();
+  NdbTransaction *trans= NULL;
+  NdbError ndb_error;
+  int retries= 100;
+  int retry_sleep= 30; /* 30 milliseconds, transaction */
+  DBUG_ENTER("ndbcluster_find_all_databases");
+  /* Ensure that we have the right lock */
+  if (!ndbcluster_has_global_schema_lock(thd_ndb))
+    DBUG_RETURN(ndbcluster_no_global_schema_lock_abort
+                (thd, "ndbcluster_find_all_databases"));
+  ndb->setDatabaseName(NDB_REP_DB);
+  thd_ndb_options.set(TNO_NO_LOG_SCHEMA_OP);
+  thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
+  while (1)
+  {
+    char db_buffer[FN_REFLEN];
+    char *db= db_buffer+1;
+    char name[FN_REFLEN];
+    char query[64000];
+    Ndb_table_guard ndbtab_g(dict, NDB_SCHEMA_TABLE);
+    const NDBTAB *ndbtab= ndbtab_g.get_table();
+    NdbScanOperation *op;
+    NdbBlob *query_blob_handle;
+    int r= 0;
+    if (ndbtab == NULL)
+    {
+      ndb_error= dict->getNdbError();
+      goto error;
+    }
+    trans= ndb->startTransaction();
+    if (trans == NULL)
+    {
+      ndb_error= ndb->getNdbError();
+      goto error;
+    }
+    op= trans->getNdbScanOperation(ndbtab);
+    if (op == NULL)
+      abort();
+    op->readTuples(NdbScanOperation::LM_Read,
+                   NdbScanOperation::SF_TupScan, 1);
+    
+    r|= op->getValue("db", db_buffer) == NULL;
+    r|= op->getValue("name", name) == NULL;
+    r|= (query_blob_handle= op->getBlobHandle("query")) == NULL;
+    r|= query_blob_handle->getValue(query, sizeof(query));
+
+    if (r)
+      abort();
+
+    if (trans->execute(NdbTransaction::NoCommit))
+    {
+      ndb_error= trans->getNdbError();
+      goto error;
+    }
+
+    while ((r= op->nextResult()) == 0)
+    {
+      unsigned db_len= db_buffer[0];
+      unsigned name_len= name[0];
+      /*
+        name_len == 0 means no table name, hence the row
+        is for a database
+      */
+      if (db_len > 0 && name_len == 0)
+      {
+        /* database found */
+        Uint64 query_length= 0;
+        if (query_blob_handle->getLength(query_length))
+          abort();
+        db[db_len]= 0;
+        query[query_length]= 0;
+        build_table_filename(name, sizeof(name), db, "", "", 0);
+        int database_exists= !my_access(name, F_OK);
+        if (strncasecmp("CREATE", query, 6) == 0)
+        {
+          /* Database should exist */
+          if (!database_exists)
+          {
+            /* create missing database */
+            sql_print_information("NDB: Discovered missing database '%s'", db);
+            const int no_print_error[1]= {0};
+            run_query(thd, query, query + query_length,
+                      no_print_error,    /* print error */
+                      TRUE,   /* don't binlog the query */
+                      TRUE);  /* reset error */
+          }
+        }
+        else if (strncasecmp("ALTER", query, 5) == 0)
+        {
+          /* Database should exist */
+          if (!database_exists)
+          {
+            /* create missing database */
+            sql_print_information("NDB: Discovered missing database '%s'", db);
+            const int no_print_error[1]= {0};
+            name_len= my_snprintf(name, sizeof(name), "CREATE DATABASE %s", db);
+            run_query(thd, name, name + name_len,
+                      no_print_error,    /* print error */
+                      TRUE,   /* don't binlog the query */
+                      TRUE);  /* reset error */
+            run_query(thd, query, query + query_length,
+                      no_print_error,    /* print error */
+                      TRUE,   /* don't binlog the query */
+                      TRUE);  /* reset error */
+          }
+        }
+        else if (strncasecmp("DROP", query, 4) == 0)
+        {
+          /* Database should not exist */
+          if (database_exists)
+          {
+            /* drop missing database */
+            sql_print_information("NDB: Discovered reamining database '%s'", db);
+          }
+        }
+      }
+    }
+    if (r == -1)
+    {
+      ndb_error= op->getNdbError();
+      goto error;
+    }
+    ndb->closeTransaction(trans);
+    trans= NULL;
+    DBUG_RETURN(0); // success
+  error:
+    if (trans)
+    {
+      ndb->closeTransaction(trans);
+      trans= NULL;
+    }
+    if (ndb_error.status == NdbError::TemporaryError && !thd->killed)
+    {
+      if (retries--)
+      {
+        do_retry_sleep(retry_sleep);
+        continue; // retry
+      }
+    }
+    DBUG_RETURN(1); // not temp error or too many retries
+  }
+}
+
 int ndbcluster_setup_binlog_table_shares(THD *thd)
 {
+  Ndbcluster_global_schema_lock_guard global_schema_lock_guard(thd);
+  if (global_schema_lock_guard.lock())
+    return 1;
   if (!ndb_schema_share &&
       ndbcluster_check_ndb_schema_share() == 0)
   {
@@ -928,6 +1370,11 @@ int ndbcluster_setup_binlog_table_shares
     }
   }
 
+  if (ndbcluster_find_all_databases(thd))
+  {
+    return 1;
+  }
+
   if (!ndbcluster_find_all_files(thd))
   {
     pthread_mutex_lock(&LOCK_open);
@@ -1104,7 +1551,7 @@ ndbcluster_update_slock(THD *thd,
   const NDBTAB *ndbtab= ndbtab_g.get_table();
   NdbTransaction *trans= 0;
   int retries= 100;
-  int retry_sleep= 10; /* 10 milliseconds, transaction */
+  int retry_sleep= 30; /* 30 milliseconds, transaction */
   const NDBCOL *col[SCHEMA_SIZE];
   unsigned sz[SCHEMA_SIZE];
 
@@ -1114,7 +1561,8 @@ ndbcluster_update_slock(THD *thd,
 
   if (ndbtab == 0)
   {
-    abort();
+    if (dict->getNdbError().code != 4009)
+      abort();
     DBUG_RETURN(0);
   }
 
@@ -1199,13 +1647,13 @@ ndbcluster_update_slock(THD *thd,
   err:
     const NdbError *this_error= trans ?
       &trans->getNdbError() : &ndb->getNdbError();
-    if (this_error->status == NdbError::TemporaryError)
+    if (this_error->status == NdbError::TemporaryError && !thd->killed)
     {
       if (retries--)
       {
         if (trans)
           ndb->closeTransaction(trans);
-        my_sleep(retry_sleep);
+        do_retry_sleep(retry_sleep);
         continue; // retry
       }
     }
@@ -1441,7 +1889,7 @@ int ndbcluster_log_schema_op(THD *thd,
   const NDBTAB *ndbtab= ndbtab_g.get_table();
   NdbTransaction *trans= 0;
   int retries= 100;
-  int retry_sleep= 10; /* 10 milliseconds, transaction */
+  int retry_sleep= 30; /* 30 milliseconds, transaction */
   const NDBCOL *col[SCHEMA_SIZE];
   unsigned sz[SCHEMA_SIZE];
 
@@ -1548,13 +1996,13 @@ int ndbcluster_log_schema_op(THD *thd,
 err:
     const NdbError *this_error= trans ?
       &trans->getNdbError() : &ndb->getNdbError();
-    if (this_error->status == NdbError::TemporaryError)
+    if (this_error->status == NdbError::TemporaryError && !thd->killed)
     {
       if (retries--)
       {
         if (trans)
           ndb->closeTransaction(trans);
-        my_sleep(retry_sleep);
+        do_retry_sleep(retry_sleep);
         continue; // retry
       }
     }
@@ -1812,6 +2260,8 @@ ndb_binlog_thread_handle_schema_event(TH
     if (ev_type == NDBEVENT::TE_UPDATE ||
         ev_type == NDBEVENT::TE_INSERT)
     {
+      Thd_ndb *thd_ndb= get_thd_ndb(thd);
+      Thd_ndb_options_guard thd_ndb_options(thd_ndb);
       Cluster_schema *schema= (Cluster_schema *)
         sql_alloc(sizeof(Cluster_schema));
       MY_BITMAP slock;
@@ -1863,10 +2313,12 @@ ndb_binlog_thread_handle_schema_event(TH
           // fall through
         case SOT_RENAME_TABLE_NEW:
         {
-          uint end= snprintf(&errmsg[0], MYSQL_ERRMSG_SIZE,
-                             "NDB Binlog: Skipping renaming locally defined table '%s.%s'
from binlog schema event '%s' from node %d. ",
-                             schema->db, schema->name, schema->query,
-                             schema->node_id);
+          uint end= my_snprintf(&errmsg[0], MYSQL_ERRMSG_SIZE,
+                                "NDB Binlog: Skipping renaming locally "
+                                "defined table '%s.%s' from binlog schema "
+                                "event '%s' from node %d. ",
+                                schema->db, schema->name, schema->query,
+                                schema->node_id);
           
           errmsg[end]= '\0';
         }
@@ -1874,21 +2326,24 @@ ndb_binlog_thread_handle_schema_event(TH
         case SOT_DROP_TABLE:
           if (schema_type == SOT_DROP_TABLE)
           {
-            uint end= snprintf(&errmsg[0], MYSQL_ERRMSG_SIZE,
-                               "NDB Binlog: Skipping dropping locally defined table
'%s.%s' from binlog schema event '%s' from node %d. ",
-                               schema->db, schema->name, schema->query,
-                               schema->node_id);
+            uint end= my_snprintf(&errmsg[0], MYSQL_ERRMSG_SIZE,
+                                  "NDB Binlog: Skipping dropping locally "
+                                  "defined table '%s.%s' from binlog schema "
+                                  "event '%s' from node %d. ",
+                                  schema->db, schema->name, schema->query,
+                                  schema->node_id);
             errmsg[end]= '\0';
           }
           if (! ndbcluster_check_if_local_table(schema->db, schema->name))
           {
-            const int no_print_error[1]=
-              {ER_BAD_TABLE_ERROR}; /* ignore missing table */
+            thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
+            const int no_print_error[2]=
+              {ER_BAD_TABLE_ERROR, 0}; /* ignore missing table */
             run_query(thd, schema->query,
                       schema->query + schema->query_length,
                       no_print_error, //   /* don't print error */
-                      TRUE); //  /* don't binlog the query */
-
+                      TRUE,   /* don't binlog the query */
+                      TRUE);  /* reset error */
             /* binlog dropping table after any table operations */
             post_epoch_log_list->push_back(schema, mem_root);
             /* acknowledge this query _after_ epoch completion */
@@ -1941,6 +2396,7 @@ ndb_binlog_thread_handle_schema_event(TH
           break;
         // fall through
         case SOT_CREATE_TABLE:
+          thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
           pthread_mutex_lock(&LOCK_open);
           if (ndbcluster_check_if_local_table(schema->db, schema->name))
           {
@@ -1968,13 +2424,15 @@ ndb_binlog_thread_handle_schema_event(TH
           break;
         case SOT_DROP_DB:
           /* Drop the database locally if it only contains ndb tables */
+          thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
           if (! ndbcluster_check_if_local_tables_in_db(thd, schema->db))
           {
             const int no_print_error[1]= {0};
             run_query(thd, schema->query,
                       schema->query + schema->query_length,
                       no_print_error,    /* print error */
-                      TRUE);   /* don't binlog the query */
+                      TRUE,   /* don't binlog the query */
+                      TRUE);  /* reset error */
             /* binlog dropping database after any table operations */
             post_epoch_log_list->push_back(schema, mem_root);
             /* acknowledge this query _after_ epoch completion */
@@ -1997,11 +2455,13 @@ ndb_binlog_thread_handle_schema_event(TH
           /* fall through */
         case SOT_ALTER_DB:
         {
+          thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
           const int no_print_error[1]= {0};
           run_query(thd, schema->query,
                     schema->query + schema->query_length,
                     no_print_error,    /* print error */
-                    TRUE);   /* don't binlog the query */
+                    TRUE,   /* don't binlog the query */
+                    TRUE);  /* reset error */
           log_query= 1;
           break;
         }
@@ -2153,8 +2613,10 @@ ndb_binlog_thread_handle_schema_event_po
     return;
   DBUG_ENTER("ndb_binlog_thread_handle_schema_event_post_epoch");
   Cluster_schema *schema;
+  Thd_ndb *thd_ndb= get_thd_ndb(thd);
   while ((schema= post_epoch_log_list->pop()))
   {
+    Thd_ndb_options_guard thd_ndb_options(thd_ndb);
     DBUG_PRINT("info",
                ("%s.%s: log query_length: %d  query: '%s'  type: %d",
                 schema->db, schema->name,
@@ -2219,34 +2681,9 @@ ndb_binlog_thread_handle_schema_event_po
         if (ndb_extra_logging > 9)
           sql_print_information("SOT_RENAME_TABLE %s.%s", schema->db,
schema->name);
         log_query= 1;
-        {
-          injector_ndb->setDatabaseName(schema->db);
-          Ndb_table_guard ndbtab_g(injector_ndb->getDictionary(),
-                                   schema->name);
-          ndbtab_g.invalidate();
-        }
-        {
-          TABLE_LIST table_list;
-          bzero((char*) &table_list,sizeof(table_list));
-          table_list.db= schema->db;
-          table_list.alias= table_list.table_name= schema->name;
-          close_cached_tables(thd, &table_list, FALSE, FALSE);
-        }
-        {
-          if (ndb_extra_logging > 9)
-            sql_print_information("NDB Binlog: renaming files start");
-          pthread_mutex_lock(&LOCK_open);
-          char from[FN_REFLEN];
-          char to[FN_REFLEN];
-          strxnmov(from, FN_REFLEN-1, share->key, NullS);
-          ndbcluster_rename_share(thd, share);
-          strxnmov(to, FN_REFLEN-1, share->key, NullS);
-          rename_file_ext(from, to, ".ndb");
-          rename_file_ext(from, to, ".frm");
-          pthread_mutex_unlock(&LOCK_open);
-          if (ndb_extra_logging > 9)
-            sql_print_information("NDB Binlog: renaming files done");
-        }
+        pthread_mutex_lock(&LOCK_open);
+        ndbcluster_rename_share(thd, share);
+        pthread_mutex_unlock(&LOCK_open);
         break;
       case SOT_RENAME_TABLE_PREPARE:
         if (ndb_extra_logging > 9)
@@ -2302,6 +2739,7 @@ ndb_binlog_thread_handle_schema_event_po
             free_share(&share);
             share= 0;
           }
+          thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
           pthread_mutex_lock(&LOCK_open);
           if (ndbcluster_check_if_local_table(schema->db, schema->name))
           {
@@ -2481,6 +2919,7 @@ ndb_binlog_thread_handle_schema_event_po
             free_share(&share);
             share= 0;
           }
+          thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
           pthread_mutex_lock(&LOCK_open);
           if (ndbcluster_check_if_local_table(schema->db, schema->name))
           {
@@ -2761,7 +3200,7 @@ void set_binlog_flags(NDB_SHARE *share)
     set_binlog_full(share);
 }
 
-bool
+static bool
 ndbcluster_check_if_local_table(const char *dbname, const char *tabname)
 {
   char key[FN_REFLEN];
@@ -2783,7 +3222,7 @@ ndbcluster_check_if_local_table(const ch
   DBUG_RETURN(false);
 }
 
-bool
+static bool
 ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname)
 {
   DBUG_ENTER("ndbcluster_check_if_local_tables_in_db");
@@ -3345,9 +3784,9 @@ ndbcluster_create_event_ops(THD *thd, ND
       op->setCustomData(NULL);
       ndb->dropEventOperation(op);
       pthread_mutex_unlock(&injector_mutex);
-      if (retries)
+      if (retries && !thd->killed)
       {
-        my_sleep(retry_sleep);
+        do_retry_sleep(retry_sleep);
         continue;
       }
       DBUG_RETURN(-1);
@@ -4347,7 +4786,6 @@ pthread_handler_t ndb_binlog_thread_func
     if (ndbcluster_terminating)
     {
       pthread_mutex_unlock(&LOCK_server_started);
-      pthread_mutex_lock(&LOCK_ndb_util_thread);
       goto err;
     }
   }
@@ -4542,17 +4980,6 @@ restart:
       res= i_ndb->pollEvents(tot_poll_wait, &gci);
       tot_poll_wait= 0;
     }
-    else
-    {
-      /*
-        Just consume any events, not used if no binlogging
-        e.g. node failure events
-      */
-      Uint64 tmp_gci;
-      if (i_ndb->pollEvents(0, &tmp_gci))
-        while (i_ndb->nextEvent())
-          ;
-    }
     int schema_res= s_ndb->pollEvents(tot_poll_wait, &schema_gci);
     ndb_latest_received_binlog_epoch= gci;
 
@@ -4632,7 +5059,35 @@ restart:
       }
     }
 
-    if (res > 0)
+    if (!ndb_binlog_running)
+    {
+      /*
+        Just consume any events, not used if no binlogging
+        e.g. node failure events
+      */
+      Uint64 tmp_gci;
+      if (i_ndb->pollEvents(0, &tmp_gci))
+      {
+        NdbEventOperation *pOp;
+        while ((pOp= i_ndb->nextEvent()))
+        {
+          if ((unsigned) pOp->getEventType() >=
+              (unsigned) NDBEVENT::TE_FIRST_NON_DATA_EVENT)
+          {
+            ndb_binlog_index_row row;
+            ndb_binlog_thread_handle_non_data_event(thd, i_ndb, pOp, row);
+          }
+        }
+        if (i_ndb->getEventOperation() == NULL &&
+            s_ndb->getEventOperation() == NULL &&
+            do_ndbcluster_binlog_close_connection == BCCC_running)
+        {
+          DBUG_PRINT("info", ("do_ndbcluster_binlog_close_connection= BCCC_restart"));
+          do_ndbcluster_binlog_close_connection= BCCC_restart;
+        }
+      }
+    }
+    else if (res > 0)
     {
       DBUG_PRINT("info", ("pollEvents res: %d", res));
       THD_SET_PROC_INFO(thd, "Processing events");
@@ -5085,17 +5540,17 @@ ndbcluster_show_status_binlog(THD* thd, 
     pthread_mutex_unlock(&injector_mutex);
 
     buflen=
-      snprintf(buf, sizeof(buf),
-               "latest_epoch=%s, "
-               "latest_trans_epoch=%s, "
-               "latest_received_binlog_epoch=%s, "
-               "latest_handled_binlog_epoch=%s, "
-               "latest_applied_binlog_epoch=%s",
-               llstr(ndb_latest_epoch, buff1),
-               llstr(ndb_get_latest_trans_gci(), buff2),
-               llstr(ndb_latest_received_binlog_epoch, buff3),
-               llstr(ndb_latest_handled_binlog_epoch, buff4),
-               llstr(ndb_latest_applied_binlog_epoch, buff5));
+      my_snprintf(buf, sizeof(buf),
+                  "latest_epoch=%s, "
+                  "latest_trans_epoch=%s, "
+                  "latest_received_binlog_epoch=%s, "
+                  "latest_handled_binlog_epoch=%s, "
+                  "latest_applied_binlog_epoch=%s",
+                  llstr(ndb_latest_epoch, buff1),
+                  llstr(ndb_get_latest_trans_gci(), buff2),
+                  llstr(ndb_latest_received_binlog_epoch, buff3),
+                  llstr(ndb_latest_handled_binlog_epoch, buff4),
+                  llstr(ndb_latest_applied_binlog_epoch, buff5));
     if (stat_print(thd, ndbcluster_hton_name, ndbcluster_hton_name_length,
                    "binlog", strlen("binlog"),
                    buf, buflen))

=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h	2008-03-26 23:22:46 +0000
+++ b/sql/ha_ndbcluster_binlog.h	2008-12-09 18:59:54 +0000
@@ -135,7 +135,25 @@ private:
   int m_invalidate;
 };
 
+class Thd_proc_info_guard
+{
+public:
+  Thd_proc_info_guard(THD *thd)
+   : m_thd(thd), m_proc_info(thd->proc_info) {}
+  ~Thd_proc_info_guard() { m_thd->proc_info= m_proc_info; }
+private:
+  THD *m_thd;
+  const char *m_proc_info;
+};
+
 extern Ndb_cluster_connection* g_ndb_cluster_connection;
+#ifdef HAVE_NDB_BINLOG
+void ndbcluster_global_schema_lock_init();
+void ndbcluster_global_schema_lock_deinit();
+#else
+inline void ndbcluster_global_schema_lock_init() {}
+inline void ndbcluster_global_schema_lock_deinit() {}
+#endif
 
 #ifdef HAVE_NDB_BINLOG
 extern pthread_t ndb_binlog_thread;
@@ -159,10 +177,6 @@ void ndbcluster_binlog_init_handlerton()
   Initialize the binlog part of the NDB_SHARE
 */
 int ndbcluster_binlog_init_share(THD *thd, NDB_SHARE *share, TABLE *table);
-
-bool ndbcluster_check_if_local_table(const char *dbname, const char *tabname);
-bool ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname);
-
 int ndbcluster_create_binlog_setup(THD *thd, Ndb *ndb, const char *key,
                                    uint key_len,
                                    const char *db,
@@ -269,3 +283,17 @@ set_thd_ndb(THD *thd, Thd_ndb *thd_ndb)
 { thd_set_ha_data(thd, ndbcluster_hton, thd_ndb); }
 
 Ndb* check_ndb_in_thd(THD* thd);
+
+int ndbcluster_has_global_schema_lock(Thd_ndb *thd_ndb);
+int ndbcluster_no_global_schema_lock_abort(THD *thd, const char *msg);
+
+class Ndbcluster_global_schema_lock_guard
+{
+public:
+  Ndbcluster_global_schema_lock_guard(THD *thd);
+  ~Ndbcluster_global_schema_lock_guard();
+  int lock();
+private:
+  THD *m_thd;
+  int m_lock;
+};

=== modified file 'sql/ha_ndbcluster_connection.cc'
--- a/sql/ha_ndbcluster_connection.cc	2008-04-09 13:52:09 +0000
+++ b/sql/ha_ndbcluster_connection.cc	2008-10-02 15:52:29 +0000
@@ -91,7 +91,9 @@ int ndbcluster_connect(int (*connect_cal
         (now_time.tv_sec == end_time.tv_sec &&
          now_time.tv_usec >= end_time.tv_usec))
       break;
-    sleep(1);
+    do_retry_sleep(100);
+    if (abort_loop)
+      goto ndbcluster_connect_error;
   }
 
   {

=== modified file 'sql/ha_ndbcluster_connection.h'
--- a/sql/ha_ndbcluster_connection.h	2008-04-09 13:52:09 +0000
+++ b/sql/ha_ndbcluster_connection.h	2008-10-02 15:52:29 +0000
@@ -23,3 +23,9 @@ int ndb_has_node_id(uint id);
 
 /* options from from mysqld.cc */
 extern ulong opt_ndb_cluster_connection_pool;
+
+/* perform random sleep in the range milli_sleep to 2*milli_sleep */
+inline void do_retry_sleep(unsigned milli_sleep)
+{
+  my_sleep(1000*(milli_sleep + 5*(rand()%(milli_sleep/5))));
+}

=== added file 'sql/ha_ndbcluster_lock_ext.h'
--- a/sql/ha_ndbcluster_lock_ext.h	1970-01-01 00:00:00 +0000
+++ b/sql/ha_ndbcluster_lock_ext.h	2008-10-09 09:10:50 +0000
@@ -0,0 +1,113 @@
+/* Copyright (C) 2000-2003 MySQL AB
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+/*
+  These functions are shared with ndb_restore so that the creating of
+  tables through ndb_restore is syncronized correctly with the mysqld's
+
+  The lock/unlock functions use the BACKUP_SEQUENCE row in SYSTAB_0
+
+  retry_time == 0 means no retry
+  retry_time <  0 means infinite retries
+  retry_time >  0 means retries for max 'retry_time' seconds
+*/
+static NdbTransaction *
+ndbcluster_global_schema_lock_ext(THD *thd, Ndb *ndb, NdbError &ndb_error,
+                                  int retry_time= 10)
+{
+  ndb->setDatabaseName("sys");
+  ndb->setDatabaseSchemaName("def");
+  NdbDictionary::Dictionary *dict= ndb->getDictionary();
+  Ndb_table_guard ndbtab_g(dict, "SYSTAB_0");
+  const NdbDictionary::Table *ndbtab= NULL;
+  NdbOperation *op;
+  NdbTransaction *trans= NULL;
+  int retry_sleep= 50; /* 50 milliseconds, transaction */
+  NDB_TICKS time_end;
+
+  if (retry_time > 0)
+  {
+    time_end= NdbTick_CurrentMillisecond();
+    time_end+= retry_time * 1000;
+  }
+  while (1)
+  {
+    if (!ndbtab)
+    {
+      if (!(ndbtab= ndbtab_g.get_table()))
+      {
+        if (dict->getNdbError().status == NdbError::TemporaryError)
+          goto retry;
+        ndb_error= dict->getNdbError();
+        goto error_handler;
+      }
+    }
+
+    trans= ndb->startTransaction();
+    if (trans == NULL)
+    {
+      ndb_error= ndb->getNdbError();
+      goto error_handler;
+    }
+
+    op= trans->getNdbOperation(ndbtab);
+    op->readTuple(NdbOperation::LM_Exclusive);
+    op->equal("SYSKEY_0", NDB_BACKUP_SEQUENCE);
+
+    if (trans->execute(NdbTransaction::NoCommit) == 0)
+      break;
+
+    if (trans->getNdbError().status != NdbError::TemporaryError)
+      goto error_handler;
+    else if (thd->killed)
+      goto error_handler;
+  retry:
+    if (retry_time == 0)
+      goto error_handler;
+    if (retry_time > 0 &&
+        time_end < NdbTick_CurrentMillisecond())
+      goto error_handler;
+    if (trans)
+    {
+      ndb->closeTransaction(trans);
+      trans= NULL;
+    }
+    do_retry_sleep(retry_sleep);
+  }
+  return trans;
+
+ error_handler:
+  if (trans)
+  {
+    ndb_error= trans->getNdbError();
+    ndb->closeTransaction(trans);
+  }
+  return NULL;
+}
+
+static int
+ndbcluster_global_schema_unlock_ext(Ndb *ndb, NdbTransaction *trans,
+                                    NdbError &ndb_error)
+{
+  if (trans->execute(NdbTransaction::Commit))
+  {
+    ndb_error= trans->getNdbError();
+    ndb->closeTransaction(trans);
+    return -1;
+  }
+  ndb->closeTransaction(trans);
+  return 0;
+}

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2008-12-11 17:29:35 +0000
+++ b/sql/ha_partition.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 MySQL AB
+/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by

=== modified file 'sql/ha_partition.h'
--- a/sql/ha_partition.h	2008-12-08 21:15:06 +0000
+++ b/sql/ha_partition.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 MySQL AB
+/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2008-12-11 18:04:55 +0000
+++ b/sql/handler.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -3877,14 +3877,15 @@ static my_bool binlog_func_foreach(THD *
 {
   hton_list_st hton_list;
   uint i, sz;
+  int res= 0;
 
   hton_list.sz= 0;
   plugin_foreach(thd, binlog_func_list,
                  MYSQL_STORAGE_ENGINE_PLUGIN, &hton_list);
 
   for (i= 0, sz= hton_list.sz; i < sz ; i++)
-    hton_list.hton[i]->binlog_func(hton_list.hton[i], thd, bfn->fn, bfn->arg);
-  return FALSE;
+    res|= hton_list.hton[i]->binlog_func(hton_list.hton[i], thd, bfn->fn,
bfn->arg);
+  return res != 0;
 }
 
 int ha_reset_logs(THD *thd)
@@ -3927,6 +3928,42 @@ int ha_binlog_index_purge_file(THD *thd,
   return 0;
 }
 
+static int ha_global_schema_lock(THD *thd, int no_queue)
+{
+  binlog_func_st bfn= {BFN_GLOBAL_SCHEMA_LOCK, (void *)&no_queue};
+  int res= binlog_func_foreach(thd, &bfn);
+  if (res || thd->main_da.is_error())
+    return 1;
+  return 0;
+}
+
+static int ha_global_schema_unlock(THD *thd)
+{
+  binlog_func_st bfn= {BFN_GLOBAL_SCHEMA_UNLOCK, 0};
+  binlog_func_foreach(thd, &bfn);
+  if (thd->main_da.is_error())
+    return 1;
+  return 0;
+}
+
+Ha_global_schema_lock_guard::Ha_global_schema_lock_guard(THD *thd)
+  : m_thd(thd), m_lock(0)
+{
+}
+
+Ha_global_schema_lock_guard::~Ha_global_schema_lock_guard()
+{
+  if (m_lock)
+    ha_global_schema_unlock(m_thd);
+}
+
+int Ha_global_schema_lock_guard::lock(int no_queue)
+{
+  DBUG_ASSERT(m_lock == 0);
+  m_lock= 1;
+  return ha_global_schema_lock(m_thd, no_queue);
+}
+
 struct binlog_log_query_st
 {
   enum_binlog_command binlog_command;

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2008-12-08 21:15:06 +0000
+++ b/sql/handler.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -358,7 +358,9 @@ enum enum_binlog_func {
   BFN_RESET_SLAVE=       2,
   BFN_BINLOG_WAIT=       3,
   BFN_BINLOG_END=        4,
-  BFN_BINLOG_PURGE_FILE= 5
+  BFN_BINLOG_PURGE_FILE= 5,
+  BFN_GLOBAL_SCHEMA_LOCK=  6,
+  BFN_GLOBAL_SCHEMA_UNLOCK=7
 };
 
 enum enum_binlog_command {
@@ -2487,11 +2489,6 @@ extern TYPELIB tx_isolation_typelib;
 extern TYPELIB myisam_stats_method_typelib;
 extern ulong total_ha, total_ha_2pc;
 
- 
-/* Wrapper functions */
-#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
-#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
-
 /* lookups */
 handlerton *ha_default_handlerton(THD *thd);
 plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
@@ -2602,6 +2599,16 @@ void ha_binlog_log_query(THD *thd, handl
                          const char *db, const char *table_name);
 void ha_binlog_wait(THD *thd);
 int ha_binlog_end(THD *thd);
+class Ha_global_schema_lock_guard
+{
+public:
+  Ha_global_schema_lock_guard(THD *thd);
+  ~Ha_global_schema_lock_guard();
+  int lock(int no_queue= 0);
+private:
+  THD *m_thd;
+  int m_lock;
+};
 #else
 inline int ha_int_dummy() { return 0; }
 #define ha_reset_logs(a) ha_int_dummy()
@@ -2610,4 +2617,11 @@ inline int ha_int_dummy() { return 0; }
 #define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
 #define ha_binlog_wait(a) do {} while (0)
 #define ha_binlog_end(a)  do {} while (0)
+class Ha_global_schema_lock_guard
+{
+public:
+  Ha_global_schema_lock_guard(THD *thd) {}
+  ~Ha_global_schema_lock_guard() {}
+  int lock(int no_queue= 0) { return 0; }
+};
 #endif

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2008-12-08 21:15:06 +0000
+++ b/sql/item.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/item.h'
--- a/sql/item.h	2008-12-08 21:15:06 +0000
+++ b/sql/item.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2008-12-08 21:15:06 +0000
+++ b/sql/item_func.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2008-12-08 21:15:06 +0000
+++ b/sql/item_func.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/lock.cc'
--- a/sql/lock.cc	2008-10-23 16:29:52 +0000
+++ b/sql/lock.cc	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2008-12-11 18:04:55 +0000
+++ b/sql/log.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2008-12-11 18:04:55 +0000
+++ b/sql/log_event.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2008-12-11 18:04:55 +0000
+++ b/sql/mysql_priv.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -2336,7 +2336,7 @@ uint build_table_shadow_filename(char *b
 #define FN_TO_IS_TMP    (1 << 1)
 #define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
 #define NO_FRM_RENAME   (1 << 2)
-#define FRM_ONLY     (1 << 3)
+#define FRM_ONLY        (1 << 3)
 
 /* from hostname.cc */
 char *ip_to_hostname(struct sockaddr_storage *in, int addrLen, uint *errors);

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2008-12-11 19:02:44 +0000
+++ b/sql/mysqld.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -6269,7 +6269,7 @@ thread is in the master's binlogs.",
    "Turn on more logging in the error log.",
    (uchar**) &ndb_extra_logging,
    (uchar**) &ndb_extra_logging,
-   0, GET_ULONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
+   0, GET_ULONG, OPT_ARG, 1, 0, 0, 0, 0, 0},
 #ifdef HAVE_NDB_BINLOG
   {"ndb-report-thresh-binlog-epoch-slip", OPT_NDB_REPORT_THRESH_BINLOG_EPOCH_SLIP,
    "Threshold on number of epochs to be behind before reporting binlog status. "
@@ -7929,6 +7929,7 @@ static int mysql_init_variables(void)
   max_system_variables.ndb_index_stat_cache_entries=~0L;
   global_system_variables.ndb_index_stat_update_freq=20;
   max_system_variables.ndb_index_stat_update_freq=~0L;
+
 #ifdef HAVE_OPENSSL
   have_ssl=SHOW_OPTION_YES;
 #else

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2008-12-08 21:15:06 +0000
+++ b/sql/opt_range.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/partition_info.h'
--- a/sql/partition_info.h	2008-10-15 01:19:02 +0000
+++ b/sql/partition_info.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2008-12-11 19:02:44 +0000
+++ b/sql/set_var.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2008-12-11 18:04:55 +0000
+++ b/sql/share/errmsg.txt	2008-12-13 11:02:16 +0000
@@ -6192,7 +6192,7 @@ ER_BACKUP_INVALID_LOC
 ER_BACKUP_READ_LOC
         eng "Can't read backup location '%-.64s'"
 ER_BACKUP_WRITE_LOC
-        eng "Can't write to backup location '%-.64s' (file already exists?)"
+        eng "Can't write to backup location '%-.64s'"
 ER_BACKUP_LIST_DBS
         eng "Can't enumerate server databases"
 ER_BACKUP_LIST_TABLES
@@ -6439,3 +6439,14 @@ ER_RESTORE_DB_EXISTS
   eng "Database \'%-.64s\' already exists. Use OVERWRITE flag to overwrite."
 ER_QUERY_CACHE_DISABLED
 	eng "Query cache is disabled; restart the server with query_cache_type=1 to enable it"
+
+
+ER_BACKUP_UNEXPECTED_DATA
+  eng "Backup image contains no tables, but table data was found in it"
+ER_BACKUP_BACKUP_DBS
+  eng "Backing up %u database(s) %.220s"
+ER_BACKUP_RESTORE_DBS
+  eng "Restoring %u database(s) %.220s"
+
+ER_WARN_ENGINE_TRANSACTION_ROLLBACK
+  eng "Storage engine %s does not support rollback for this statement. Transaction rolled
back and must be restarted"

=== modified file 'sql/si_logs.h'
--- a/sql/si_logs.h	2008-10-30 17:53:24 +0000
+++ b/sql/si_logs.h	2008-11-14 14:49:09 +0000
@@ -201,7 +201,7 @@ void Backup_log::stop(time_t when)
 inline
 void Backup_log::binlog_file(char *file)
 {
-  if (strlen(file) > 0)
+  if (file && strlen(file) > 0)
     m_op_hist.binlog_file= file;
 }
 
@@ -217,7 +217,7 @@ void Backup_log::binlog_file(char *file)
 inline
 void Backup_log::master_binlog_file(char *file)
 {
-  if (strlen(file) > 0)
+  if (file && strlen(file) > 0)
     m_op_hist.master_binlog_file= file;
 }
 

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sp_head.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 MySQL AB
+/* Copyright 2002-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_base.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_cache.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_class.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2008-12-11 18:04:55 +0000
+++ b/sql/sql_class.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2008-12-08 11:29:15 +0000
+++ b/sql/sql_db.cc	2008-12-09 18:59:54 +0000
@@ -616,6 +616,7 @@ int mysql_create_db(THD *thd, char *db, 
   MY_STAT stat_info;
   uint create_options= create_info ? create_info->options : 0;
   uint path_len;
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_create_db");
 
   /* do not create 'information_schema' db */
@@ -643,6 +644,8 @@ int mysql_create_db(THD *thd, char *db, 
     goto exit2;
   }
 
+  global_schema_lock_guard.lock();
+
   pthread_mutex_lock(&LOCK_mysql_create_db);
 
   /* Check directory */
@@ -767,6 +770,7 @@ bool mysql_alter_db(THD *thd, const char
   char path[FN_REFLEN+16];
   long result=1;
   int error= 0;
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_alter_db");
 
   /*
@@ -784,6 +788,8 @@ bool mysql_alter_db(THD *thd, const char
   if ((error=wait_if_global_read_lock(thd,0,1)))
     goto exit2;
 
+  global_schema_lock_guard.lock();
+
   pthread_mutex_lock(&LOCK_mysql_create_db);
 
   /* 
@@ -861,6 +867,7 @@ bool mysql_rm_db(THD *thd,char *db,bool 
   MY_DIR *dirp;
   uint length;
   TABLE_LIST* dropped_tables= 0;
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_rm_db");
 
   /*
@@ -881,6 +888,8 @@ bool mysql_rm_db(THD *thd,char *db,bool 
     goto exit2;
   }
 
+  global_schema_lock_guard.lock();
+
   pthread_mutex_lock(&LOCK_mysql_create_db);
 
   length= build_table_filename(path, sizeof(path), db, "", "", 0);

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2008-12-08 21:15:06 +0000
+++ b/sql/sql_delete.cc	2008-12-13 11:02:16 +0000
@@ -987,6 +987,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST
   bool error;
   uint path_length;
   MDL_LOCK_DATA *mdl_lock_data= 0;
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_truncate");
 
   bzero((char*) &create_info,sizeof(create_info));
@@ -1040,6 +1041,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST
                                       HTON_CAN_RECREATE))
       goto trunc_by_del;
 
+    if (table_type == DB_TYPE_NDBCLUSTER)
+      global_schema_lock_guard.lock();
     /*
       FIXME: Actually code of TRUNCATE breaks meta-data locking protocol since
              tries to get table enging and therefore accesses table in some way

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2008-12-11 19:02:44 +0000
+++ b/sql/sql_insert.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_lex.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2008-12-11 18:04:55 +0000
+++ b/sql/sql_lex.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_parse.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -2508,6 +2508,7 @@ mysql_execute_command(THD *thd)
     if (select_lex->item_list.elements)		// With select
     {
       select_result *result;
+      Ha_global_schema_lock_guard global_schema_lock_guard(thd);
 
       select_lex->options|= SELECT_NO_UNLOCK;
       unit->set_limit(select_lex);
@@ -2529,6 +2530,8 @@ mysql_execute_command(THD *thd)
       {
         lex->link_first_table_back(create_table, link_to_local);
         create_table->open_type= TABLE_LIST::OPEN_OR_CREATE;
+        if (!thd->locked_tables_mode)
+          global_schema_lock_guard.lock();
       }
 
       if (!(res= open_and_lock_tables(thd, lex->query_tables)))

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2008-12-08 21:15:06 +0000
+++ b/sql/sql_partition.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005, 2006 MySQL AB
+/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -3244,8 +3244,8 @@ int get_partition_id_key_sub(partition_i
 {
   longlong func_value;
   *part_id= get_part_id_key(part_info->table->file,
-                         part_info->subpart_field_array,
-                         part_info->no_subparts, &func_value);
+                            part_info->subpart_field_array,
+                            part_info->no_subparts, &func_value);
   return FALSE;
 }
 

=== modified file 'sql/sql_rename.cc'
--- a/sql/sql_rename.cc	2008-06-11 04:33:36 +0000
+++ b/sql/sql_rename.cc	2008-10-15 12:14:27 +0000
@@ -37,6 +37,7 @@ bool mysql_rename_tables(THD *thd, TABLE
   TABLE_LIST *ren_table= 0;
   int to_table;
   char *rename_log_table[2]= {NULL, NULL};
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_rename_tables");
 
   /*
@@ -133,6 +134,13 @@ bool mysql_rename_tables(THD *thd, TABLE
     }
   }
 
+  /*
+    Rename table may clash with parallell or existing ndb table
+    thus a global shema lock is needed to ensure global serialization.
+    Moreover we do not know here what table type the tables have.
+  */
+  global_schema_lock_guard.lock();
+
   if (lock_table_names(thd, table_list))
     goto err;
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_select.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -8581,6 +8581,7 @@ no_join_cache:
   return FALSE;          
 }
 
+
 /*
   Plan refinement stage: do various set ups for the executioner
 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_show.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_show.h'
--- a/sql/sql_show.h	2008-10-08 11:46:49 +0000
+++ b/sql/sql_show.h	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_table.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2004 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1555,6 +1555,14 @@ int mysql_rm_table_part2(THD *thd, TABLE
   }
 
   mysql_ha_rm_tables(thd, tables);
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
+  /*
+    Here we have no way of knowing if an ndb table is one of
+    the ones that should be dropped, so we take the global
+    schema lock to be safe.
+  */
+  if (!drop_temporary)
+    global_schema_lock_guard.lock();
 
   /*
     If we have the table in the definition cache, we don't have to check the
@@ -3770,8 +3778,14 @@ bool mysql_create_table(THD *thd, const 
 {
   MDL_LOCK_DATA *target_lock_data= 0;
   bool result;
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_create_table");
 
+  if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
+      !create_info->frm_only &&
+      !internal_tmp_table)
+    global_schema_lock_guard.lock();
+
   /* Wait for any database locks */
   pthread_mutex_lock(&LOCK_lock_db);
   while (!thd->killed &&
@@ -3814,7 +3828,6 @@ bool mysql_create_table(THD *thd, const 
       goto unlock;
     }
   }
-
   result= mysql_create_table_no_lock(thd, db, table_name, create_info,
                                      alter_info,
                                      internal_tmp_table,
@@ -4858,9 +4871,13 @@ bool mysql_create_like_table(THD* thd, T
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   char tmp_path[FN_REFLEN];
 #endif
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
   DBUG_ENTER("mysql_create_like_table");
 
 
+  if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
+    global_schema_lock_guard.lock();
+
   /*
     By opening source table and thus acquiring shared metadata lock on it
     we guarantee that it exists and no concurrent DDL operation will mess
@@ -5257,13 +5274,14 @@ compare_tables(THD *thd,
   Create_field *new_field, *tmp_new_field;
   KEY_PART_INFO *key_part;
   KEY_PART_INFO *end;
-  uint candidate_key_count= 0;
-  bool not_nullable= true;
   /*
     Remember if the new definition has new VARCHAR column;
     create_info->varchar will be reset in mysql_prepare_create_table.
   */
   bool varchar= create_info->varchar;
+  uint candidate_key_count= 0;
+  bool not_nullable= true;
+
   /*
     Create a copy of alter_info.
     To compare the new and old table definitions, we need to "prepare"
@@ -5286,13 +5304,13 @@ compare_tables(THD *thd,
 
   /* Create the prepared information. */
   if (mysql_prepare_create_table(thd, create_info,
-                                  &tmp_alter_info,
-                                  (table->s->tmp_table != NO_TMP_TABLE),
-                                  &db_options,
-                                  table->file,
-                                  &ha_alter_info->key_info_buffer,
-                                  &ha_alter_info->key_count,
-                                  /* select_field_count */ 0))
+                                 &tmp_alter_info,
+                                 (table->s->tmp_table != NO_TMP_TABLE),
+                                 &db_options,
+                                 table->file,
+                                 &ha_alter_info->key_info_buffer,
+                                 &ha_alter_info->key_count,
+                                 /* select_field_count */ 0))
     DBUG_RETURN(TRUE);
   /* Allocate result buffers. */
   if (! (ha_alter_info->index_drop_buffer=
@@ -5951,6 +5969,12 @@ mysql_fast_or_online_alter_table(THD *th
                                         create_info, alter_info,
                                         ha_alter_flags))
       DBUG_RETURN(1);
+
+    /*
+      Make the metadata lock available to open_table() called to
+      reopen the table down the road.
+    */
+    table_list->mdl_lock_data= table->mdl_lock_data;
   }
 
   /*
@@ -6639,6 +6663,11 @@ bool mysql_alter_table(THD *thd,char *ne
 
     if (wait_if_global_read_lock(thd,0,1))
       DBUG_RETURN(TRUE);
+
+    Ha_global_schema_lock_guard global_schema_lock_guard(thd);
+    if (table_type == DB_TYPE_NDBCLUSTER)
+      global_schema_lock_guard.lock();
+
     if (lock_table_names(thd, table_list))
     {
       error= 1;
@@ -6666,6 +6695,29 @@ view_err:
     DBUG_RETURN(error);
   }
 
+  Ha_global_schema_lock_guard global_schema_lock_guard(thd);
+  if (table_type == DB_TYPE_NDBCLUSTER ||
+      (create_info->db_type && create_info->db_type->db_type ==
DB_TYPE_NDBCLUSTER))
+  {
+    if (thd->locked_tables_mode)
+    {
+      /*
+        To avoid deadlock in this situation:
+        - if other thread has lock do not enter lock queue
+        and report an error instead
+      */
+      if (global_schema_lock_guard.lock(1))
+      {
+        my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+                   ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
+        DBUG_RETURN(TRUE);
+      }
+    }
+    else
+    {
+      global_schema_lock_guard.lock();
+    }
+  }
   if (!(table= open_n_lock_single_table(thd, table_list, TL_WRITE_ALLOW_READ,
                                         MYSQL_OPEN_TAKE_UPGRADABLE_MDL)))
     DBUG_RETURN(TRUE);

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2008-10-09 16:13:03 +0000
+++ b/sql/sql_union.cc	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2008-12-11 18:04:55 +0000
+++ b/sql/sql_update.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2008-12-11 18:04:55 +0000
+++ b/sql/sql_yacc.yy	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -3775,7 +3775,7 @@ ts_wait:
         ;
 
 size_number:
-          real_ulong_num { $$= $1;}
+          real_ulonglong_num { $$= $1;}
         | IDENT
           {
             ulonglong number;
@@ -5228,7 +5228,7 @@ attribute:
             Lex->default_value=$2; 
             Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
           }
-        | ON UPDATE_SYM NOW_SYM optional_braces 
+        | ON UPDATE_SYM NOW_SYM optional_braces
           {
             Item *item= new (YYTHD->mem_root) Item_func_now_local();
             if (item == NULL)

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2008-12-11 18:04:55 +0000
+++ b/sql/table.cc	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/table.h'
--- a/sql/table.h	2008-12-08 21:15:06 +0000
+++ b/sql/table.h	2008-12-13 11:02:16 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'storage/archive/archive_reader.c'
--- a/storage/archive/archive_reader.c	2007-10-21 21:19:52 +0000
+++ b/storage/archive/archive_reader.c	2008-12-09 18:59:54 +0000
@@ -323,10 +323,8 @@ static struct my_option my_long_options[
 static void usage(void)
 {
   print_version();
-  puts("Copyright (C) 2007 MySQL AB");
-  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
-       \nand you are welcome to modify and redistribute it under the GPL \
-       license\n");
+  puts("Copyright 2007-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
+  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you
are welcome to modify and redistribute it under the GPL license\n");
   puts("Read and modify Archive files directly\n");
   printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", my_progname);
   print_defaults("my", load_default_groups);

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2008-10-03 10:01:20 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2008-12-09 18:59:54 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 MySQL AB
+/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by

=== modified file 'storage/blackhole/ha_blackhole.h'
--- a/storage/blackhole/ha_blackhole.h	2008-10-02 09:02:38 +0000
+++ b/storage/blackhole/ha_blackhole.h	2008-11-10 20:21:49 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 MySQL AB
+/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by

=== modified file 'storage/myisam/myisampack.c'
--- a/storage/myisam/myisampack.c	2008-07-09 07:12:43 +0000
+++ b/storage/myisam/myisampack.c	2008-12-09 18:59:54 +0000
@@ -300,7 +300,7 @@ static void print_version(void)
 static void usage(void)
 {
   print_version();
-  puts("Copyright (C) 2002 MySQL AB");
+  puts("Copyright 2002-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,");
   puts("and you are welcome to modify and redistribute it under the GPL license\n");
 

=== modified file 'storage/ndb/docs/doxygen/postdoxy.pl'
--- a/storage/ndb/docs/doxygen/postdoxy.pl	2005-04-27 01:19:54 +0000
+++ b/storage/ndb/docs/doxygen/postdoxy.pl	2008-11-14 16:29:38 +0000
@@ -81,9 +81,9 @@ open (OUTFILE, "> ${destdir}/doxygen.sty
 while (<INFILE>) 
 {
     if (/\\rfoot/) {
-	print OUTFILE "\\rfoot[\\fancyplain{}{\\bfseries\\small \\copyright~Copyright 2003-2004
MySQL AB\\hfill support-cluster\@mysql.com}]{}\n";
+	print OUTFILE "\\rfoot[\\fancyplain{}{\\bfseries\\small \\copyright~Copyright 2003-2008
MySQL AB, 2008 Sun Microsystems, Inc.\\hfill support-cluster\@mysql.com}]{}\n";
     } elsif (/\\lfoot/) {
-	print OUTFILE "\\lfoot[]{\\fancyplain{}{\\bfseries\\small
support-cluster\@mysql.com\\hfill \\copyright~Copyright 2003-2004 MySQL AB}}\n";
+	print OUTFILE "\\lfoot[]{\\fancyplain{}{\\bfseries\\small
support-cluster\@mysql.com\\hfill \\copyright~Copyright 2003-2008 MySQL AB, 2008 Sun
Microsystems, Inc.}}\n";
     } else {
 	print OUTFILE;
     }

=== modified file 'storage/ndb/include/debugger/SignalLoggerManager.hpp'
--- a/storage/ndb/include/debugger/SignalLoggerManager.hpp	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/include/debugger/SignalLoggerManager.hpp	2008-10-24 11:00:37 +0000
@@ -86,7 +86,8 @@ public:
   /**
    * Generic messages in the signal log
    */
-  void log(BlockNumber bno, const char * msg, ...);
+  void log(BlockNumber bno, const char * msg, ...)
+    ATTRIBUTE_FORMAT(printf, 3, 4);
   
   /**
    * LogModes

=== modified file 'storage/ndb/include/kernel/NodeState.hpp'
--- a/storage/ndb/include/kernel/NodeState.hpp	2007-01-06 00:21:39 +0000
+++ b/storage/ndb/include/kernel/NodeState.hpp	2008-08-13 12:30:19 +0000
@@ -166,6 +166,13 @@ public:
   bool getSystemRestartInProgress() const;
 
   /**
+   * Are we started
+   */
+  bool getStarted() const {
+    return startLevel == SL_STARTED || startLevel == SL_SINGLEUSER;
+  }
+
+  /**
    * Is in single user mode?
    */
   bool getSingleUserMode() const;

=== modified file 'storage/ndb/include/kernel/signaldata/SumaImpl.hpp'
--- a/storage/ndb/include/kernel/signaldata/SumaImpl.hpp	2008-06-16 06:25:29 +0000
+++ b/storage/ndb/include/kernel/signaldata/SumaImpl.hpp	2008-08-13 12:30:19 +0000
@@ -551,6 +551,7 @@ struct SumaStartMeRef {
   Uint32 errorCode;
   enum {
     Busy = 0x1
+    ,NotStarted = 0x2
   };
 };
 

=== modified file 'storage/ndb/include/logger/LogHandler.hpp'
--- a/storage/ndb/include/logger/LogHandler.hpp	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/include/logger/LogHandler.hpp	2008-09-05 09:46:56 +0000
@@ -160,6 +160,11 @@ public:  
    */
   virtual bool checkParams();
 
+  /*
+   * Set repeat frequency, 0 means disable special repeated message handling
+   */
+  virtual void setRepeatFrequency(unsigned val);
+
 protected:
   /** Max length of the date and time header in the log. */
   STATIC_CONST( MAX_DATE_TIME_HEADER_LENGTH = 64 );

=== modified file 'storage/ndb/include/logger/Logger.hpp'
--- a/storage/ndb/include/logger/Logger.hpp	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/include/logger/Logger.hpp	2008-11-06 16:35:05 +0000
@@ -228,7 +228,8 @@ public:
    *
    * @param pMsg the message.
    */
-  virtual void alert(const char* pMsg, ...) const;
+  virtual void alert(const char* pMsg, ...) const
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   virtual void alert(BaseString &pMsg) const { alert(pMsg.c_str()); };
   
   /**
@@ -236,7 +237,8 @@ public:
    *
    * @param pMsg the message.
    */
-  virtual void critical(const char* pMsg, ...) const;
+  virtual void critical(const char* pMsg, ...) const
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   virtual void critical(BaseString &pMsg) const { critical(pMsg.c_str()); };
 
   /**
@@ -244,7 +246,8 @@ public:
    *
    * @param pMsg the message.
    */
-  virtual void error(const char* pMsg, ...) const;
+  virtual void error(const char* pMsg, ...) const
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   virtual void error(BaseString &pMsg) const { error(pMsg.c_str()); };
 
   /**
@@ -252,7 +255,8 @@ public:
    *
    * @param pMsg the message.
    */
-  virtual void warning(const char* pMsg, ...) const;
+  virtual void warning(const char* pMsg, ...) const
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   virtual void warning(BaseString &pMsg) const { warning(pMsg.c_str()); };
 
   /**
@@ -260,7 +264,8 @@ public:
    *
    * @param pMsg the message.
    */
-  virtual void info(const char* pMsg, ...) const;
+  virtual void info(const char* pMsg, ...) const
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   virtual void info(BaseString &pMsg) const { info(pMsg.c_str()); };
 
   /**
@@ -268,9 +273,15 @@ public:
    *
    * @param pMsg the message.
    */
-  virtual void debug(const char* pMsg, ...) const;
+  virtual void debug(const char* pMsg, ...) const
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   virtual void debug(BaseString &pMsg) const { debug(pMsg.c_str()); };
 
+  /*
+   * Set repeat frequency, 0 means disable special repeated message handling
+   */
+  virtual void setRepeatFrequency(unsigned val);
+
 protected:
 
   NdbMutex *m_mutex;

=== modified file 'storage/ndb/include/mgmapi/mgmapi.h'
--- a/storage/ndb/include/mgmapi/mgmapi.h	2008-08-07 03:44:29 +0000
+++ b/storage/ndb/include/mgmapi/mgmapi.h	2008-11-20 16:41:06 +0000
@@ -642,6 +642,24 @@ extern "C" {
   struct ndb_mgm_cluster_state * 
   ndb_mgm_get_status2(NdbMgmHandle handle,
                       const enum ndb_mgm_node_type types[]);
+                      
+
+
+  /**
+   * Dump state
+   *
+   * @param handle the NDB management handle.
+   * @param nodeId the node id.
+   * @param args integer array
+   * @param number of args in int array
+   * @param reply the reply message.
+   * @return 0 if successful or an error code.
+   */
+  int ndb_mgm_dump_state(NdbMgmHandle handle,
+			 int nodeId,
+			 const int * args,
+			 int num_args,
+			 struct ndb_mgm_reply* reply);
 
   /** @} *********************************************************************/
   /**

=== modified file 'storage/ndb/include/mgmapi/mgmapi_debug.h'
--- a/storage/ndb/include/mgmapi/mgmapi_debug.h	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/include/mgmapi/mgmapi_debug.h	2008-11-20 16:41:06 +0000
@@ -87,22 +87,6 @@ extern "C" {
 			   int nodeId, 
 			   int errorCode,
 			   struct ndb_mgm_reply* reply);
-
-  /**
-   * Dump state
-   *
-   * @param handle the NDB management handle.
-   * @param nodeId the node id.
-   * @param args integer array
-   * @param number of args in int array
-   * @param reply the reply message.
-   * @return 0 if successful or an error code.
-   */
-  int ndb_mgm_dump_state(NdbMgmHandle handle,
-			 int nodeId,
-			 const int * args,
-			 int num_args,
-			 struct ndb_mgm_reply* reply);
     
 
   /**

=== modified file 'storage/ndb/include/ndb_constants.h'
--- a/storage/ndb/include/ndb_constants.h	2007-03-23 13:06:00 +0000
+++ b/storage/ndb/include/ndb_constants.h	2008-09-30 06:55:35 +0000
@@ -97,4 +97,9 @@
 #define NDB_SUM_READONLY     1
 #define NDB_SUM_READ_WRITE   2
 
+/*
+ * SYSTAB_0 reserved keys
+ */
+#define NDB_BACKUP_SEQUENCE 0x1F000000
+
 #endif

=== modified file 'storage/ndb/include/ndb_version.h.in'
--- a/storage/ndb/include/ndb_version.h.in	2008-08-08 09:40:47 +0000
+++ b/storage/ndb/include/ndb_version.h.in	2008-12-09 18:59:54 +0000
@@ -171,16 +171,18 @@ ndbd_suma_dictlock(Uint32 x)
   if (x >= NDB_VERSION_D)
     return 1;
   
-  const Uint32 major = (x >> 16) & 0xFF;
-  const Uint32 minor = (x >>  8) & 0xFF;
-  
-  if (major >= 6)
   {
-    if (minor == 2)
+    const Uint32 major = (x >> 16) & 0xFF;
+    const Uint32 minor = (x >>  8) & 0xFF;
+    
+    if (major >= 6)
+    {
+      if (minor == 2)
       return x >= NDBD_SUMA_DICT_LOCK_62;
+    }
+    
+    return x >= NDBD_SUMA_DICT_LOCK_63;
   }
-  
-  return x >= NDBD_SUMA_DICT_LOCK_63;
 }
 
 #define NDBD_LONG_LIST_TABLES_CONF_62 NDB_MAKE_VERSION(6,2,16)
@@ -194,16 +196,44 @@ ndbd_LIST_TABLES_CONF_long_signal(Uint32
   if (x >= NDB_VERSION_D)
     return 1;
 
-  const Uint32 major = (x >> 16) & 0xFF;
-  const Uint32 minor = (x >>  8) & 0xFF;
-
-  if (major >= 6)
   {
-    if (minor == 2)
-      return x >= NDBD_LONG_LIST_TABLES_CONF_62;
+    const Uint32 major = (x >> 16) & 0xFF;
+    const Uint32 minor = (x >>  8) & 0xFF;
+    
+    if (major >= 6)
+    {
+      if (minor == 2)
+        return x >= NDBD_LONG_LIST_TABLES_CONF_62;
+    }
+    
+    return x >= NDBD_LONG_LIST_TABLES_CONF_63;
   }
+}
+
+#define NDBD_API_TAKE_OVERTCCONF_60 NDB_MAKE_VERSION(5,2,4)
+#define NDBD_API_TAKE_OVERTCCONF_62 NDB_MAKE_VERSION(6,2,17)
+#define NDBD_API_TAKE_OVERTCCONF_63 NDB_MAKE_VERSION(6,3,19)
+
+static
+inline
+int
+ndb_takeovertc(Uint32 x)
+{
+  if (x >= NDB_VERSION_D)
+    return 1;
 
-  return x >= NDBD_LONG_LIST_TABLES_CONF_63;
+  {
+    const Uint32 major = (x >> 16) & 0xFF;
+    const Uint32 minor = (x >>  8) & 0xFF;
+    
+    if (major >= 6)
+    {
+      if (minor == 2)
+        return x >= NDBD_API_TAKE_OVERTCCONF_62;
+    }
+    
+    return x >= NDBD_API_TAKE_OVERTCCONF_63;
+  }
 }
 
 #endif

=== modified file 'storage/ndb/include/ndbapi/Ndb.hpp'
--- a/storage/ndb/include/ndbapi/Ndb.hpp	2008-04-02 22:33:51 +0000
+++ b/storage/ndb/include/ndbapi/Ndb.hpp	2008-12-09 18:59:54 +0000
@@ -1881,7 +1881,9 @@ private:
 			     struct LinearSectionPtr ptr[3]);
   static void statusMessage(void*, Uint32, bool, bool);
 #ifdef VM_TRACE
-  void printState(const char* fmt, ...);
+#include <my_attribute.h>
+  void printState(const char* fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
 #endif
 };
 

=== modified file 'storage/ndb/include/ndbapi/NdbBlob.hpp'
--- a/storage/ndb/include/ndbapi/NdbBlob.hpp	2008-02-19 10:41:22 +0000
+++ b/storage/ndb/include/ndbapi/NdbBlob.hpp	2008-11-08 20:40:15 +0000
@@ -263,6 +263,13 @@ public:
    */
   const NdbError& getNdbError() const;
   /**
+   * Get a pointer to the operation which this Blob Handle
+   * was initially created as part of.
+   * Note that this could be a scan operation.
+   * Note that the pointer returned is a const pointer.
+   */
+  const NdbOperation* getNdbOperation() const;  
+  /**
    * Return info about all blobs in this operation.
    *
    * Get first blob in list.

=== modified file 'storage/ndb/include/ndbapi/NdbOperation.hpp'
--- a/storage/ndb/include/ndbapi/NdbOperation.hpp	2008-08-07 06:24:52 +0000
+++ b/storage/ndb/include/ndbapi/NdbOperation.hpp	2008-11-08 20:40:15 +0000
@@ -837,6 +837,7 @@ public:
    * @return method number where the error occured.
    */
   int getNdbErrorLine();
+  int getNdbErrorLine() const;
 
   /**
    * Get table name of this operation.
@@ -885,6 +886,11 @@ public:
    */
   AbortOption getAbortOption() const;
   int setAbortOption(AbortOption);
+
+  /**
+   * Get NdbTransaction object pointer for this operation
+   */
+  virtual NdbTransaction* getNdbTransaction() const;
   
 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
   
@@ -1037,7 +1043,6 @@ protected:
 
 public:
 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
-  NdbTransaction* getNdbTransaction();
   const NdbOperation* next() const;
   const NdbRecAttr* getFirstRecAttr() const;
 #endif
@@ -1473,6 +1478,13 @@ NdbOperation::getNdbErrorLine()
   return theErrorLine;
 }
 
+inline
+int
+NdbOperation::getNdbErrorLine() const
+{
+  return theErrorLine;
+}
+
 /******************************************************************************
 void next(NdbOperation* aNdbOperation);
 

=== modified file 'storage/ndb/include/ndbapi/NdbScanOperation.hpp'
--- a/storage/ndb/include/ndbapi/NdbScanOperation.hpp	2008-08-11 12:44:24 +0000
+++ b/storage/ndb/include/ndbapi/NdbScanOperation.hpp	2008-11-08 20:40:15 +0000
@@ -377,6 +377,11 @@ public:
                                          const NdbOperation::OperationOptions *opts = 0,
                                          Uint32 sizeOfOptions = 0);
 
+  /**
+   * Get NdbTransaction object for this scan operation
+   */
+  NdbTransaction* getNdbTransaction() const;
+
 protected:
   NdbScanOperation(Ndb* aNdb,
                    NdbOperation::Type aType = NdbOperation::TableScan);
@@ -651,4 +656,14 @@ NdbScanOperation::deleteCurrentTuple(Ndb
                                  opts, sizeOfOptions);
 }
 
+inline
+NdbTransaction*
+NdbScanOperation::getNdbTransaction() const
+{
+  /* return the user visible transaction object ptr, not the
+   * scan's 'internal' / buddy transaction object
+   */
+  return m_transConnection;
+};
+
 #endif

=== modified file 'storage/ndb/include/util/BaseString.hpp'
--- a/storage/ndb/include/util/BaseString.hpp	2007-04-11 13:51:09 +0000
+++ b/storage/ndb/include/util/BaseString.hpp	2008-10-24 11:00:37 +0000
@@ -97,10 +97,12 @@ public:
 		     const BaseString &separator = BaseString(" "));
 
   /** @brief Assigns from a format string a la printf() */
-  BaseString& assfmt(const char* ftm, ...);
+  BaseString& assfmt(const char* ftm, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
 
   /** @brief Appends a format string a la printf() to the end */
-  BaseString& appfmt(const char* ftm, ...);
+  BaseString& appfmt(const char* ftm, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
 
   /**
    * Split a string into a vector of strings. Separate the string where
@@ -183,7 +185,8 @@ public:
   /**
    * snprintf on some platforms need special treatment
    */
-  static int snprintf(char *str, size_t size, const char *format, ...);
+  static int snprintf(char *str, size_t size, const char *format, ...)
+    ATTRIBUTE_FORMAT(printf, 3, 4);
   static int vsnprintf(char *str, size_t size, const char *format, va_list ap);
 private:
   char* m_chr;

=== modified file 'storage/ndb/include/util/InputStream.hpp'
--- a/storage/ndb/include/util/InputStream.hpp	2007-03-22 11:36:07 +0000
+++ b/storage/ndb/include/util/InputStream.hpp	2008-09-07 22:48:48 +0000
@@ -25,14 +25,14 @@
  */
 class InputStream {
 public:
-  InputStream() { m_mutex= NULL; };
-  virtual ~InputStream() {};
+  InputStream() { m_mutex= NULL; }
+  virtual ~InputStream() {}
   virtual char* gets(char * buf, int bufLen) = 0;
   /**
    * Set the mutex to be UNLOCKED when blocking (e.g. select(2))
    */
-  void set_mutex(NdbMutex *m) { m_mutex= m; };
-  virtual void reset_timeout() {};
+  void set_mutex(NdbMutex *m) { m_mutex= m; }
+  virtual void reset_timeout() {}
 protected:
   NdbMutex *m_mutex;
 };
@@ -57,8 +57,8 @@ public:
   SocketInputStream(NDB_SOCKET_TYPE socket, unsigned read_timeout_ms = 60000);
   virtual ~SocketInputStream() {}
   char* gets(char * buf, int bufLen);
-  bool timedout() { return m_timedout; };
-  void reset_timeout() { m_timedout= false; m_timeout_remain= m_timeout_ms;};
+  bool timedout() { return m_timedout; }
+  void reset_timeout() { m_timedout= false; m_timeout_remain= m_timeout_ms;}
 
 };
 

=== modified file 'storage/ndb/include/util/NdbOut.hpp'
--- a/storage/ndb/include/util/NdbOut.hpp	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/include/util/NdbOut.hpp	2008-10-24 11:00:37 +0000
@@ -76,8 +76,10 @@ public:
   NdbOut(OutputStream &);
   virtual ~NdbOut();
 
-  void print(const char * fmt, ...);
-  void println(const char * fmt, ...);
+  void print(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
+  void println(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   
   OutputStream * m_out;
 private:
@@ -125,7 +127,7 @@ private:
 };
 
 #else
-void ndbout_c(const char * fmt, ...);
+void ndbout_c(const char * fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
 #endif
 
 #endif

=== added file 'storage/ndb/include/util/NdbTap.hpp'
--- a/storage/ndb/include/util/NdbTap.hpp	1970-01-01 00:00:00 +0000
+++ b/storage/ndb/include/util/NdbTap.hpp	2008-11-20 16:36:23 +0000
@@ -0,0 +1,32 @@
+/* Copyright (C) 2003-2008 MySQL AB, 2008 Sun Microsystems Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef NDB_TAP_HPP
+#define NDB_TAP_HPP
+
+#include <../../../unittest/mytap/tap.h>
+#include <../../../unittest/mytap/tap.c>
+
+#define TAPTEST(name)                           \
+int name##_test();                              \
+int main(int argc, const char** argv){          \
+  plan(1);                                      \
+  ok(name##_test(), #name);                     \
+  return exit_status();                         \
+}                                               \
+int name##_test()
+
+
+#endif

=== modified file 'storage/ndb/include/util/OutputStream.hpp'
--- a/storage/ndb/include/util/OutputStream.hpp	2008-08-05 11:53:52 +0000
+++ b/storage/ndb/include/util/OutputStream.hpp	2008-11-06 16:35:05 +0000
@@ -26,8 +26,10 @@ class OutputStream {
 public:
   OutputStream() {}
   virtual ~OutputStream() {}
-  virtual int print(const char * fmt, ...) = 0;
-  virtual int println(const char * fmt, ...) = 0;
+  virtual int print(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3) = 0;
+  virtual int println(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3) = 0;
   virtual void flush() {};
   virtual void reset_timeout() {};
 };
@@ -39,8 +41,10 @@ public:
   virtual ~FileOutputStream() {}
   FILE *getFile() { return f; }
 
-  int print(const char * fmt, ...);
-  int println(const char * fmt, ...);
+  int print(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
+  int println(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
   void flush() { fflush(f); }
 };
 
@@ -53,11 +57,13 @@ protected:
 public:
   SocketOutputStream(NDB_SOCKET_TYPE socket, unsigned write_timeout_ms = 1000);
   virtual ~SocketOutputStream() {}
-  bool timedout() { return m_timedout; };
-  void reset_timeout() { m_timedout= false; m_timeout_remain= m_timeout_ms;};
+  bool timedout() { return m_timedout; }
+  void reset_timeout() { m_timedout= false; m_timeout_remain= m_timeout_ms;}
 
-  int print(const char * fmt, ...);
-  int println(const char * fmt, ...);
+  int print(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
+  int println(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
 };
 
 
@@ -68,8 +74,10 @@ public:
                            unsigned write_timeout_ms = 1000);
   virtual ~BufferedSockOutputStream();
 
-  int print(const char * fmt, ...);
-  int println(const char * fmt, ...);
+  int print(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
+  int println(const char * fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
 
   void flush();
 };

=== modified file 'storage/ndb/include/util/basestring_vsnprintf.h'
--- a/storage/ndb/include/util/basestring_vsnprintf.h	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/include/util/basestring_vsnprintf.h	2008-10-24 11:00:37 +0000
@@ -15,12 +15,14 @@
 
 #ifndef BASESTRING_VSNPRINTF_H
 #define BASESTRING_VSNPRINTF_H
+#include <ndb_global.h>
 #include <stdarg.h>
 #if defined(__cplusplus)
 extern "C"
 {
 #endif
-int basestring_snprintf(char*, size_t, const char*, ...);
+int basestring_snprintf(char*, size_t, const char*, ...)
+  ATTRIBUTE_FORMAT(printf, 3, 4);
 int basestring_vsnprintf(char*,size_t, const char*,va_list);
 #if defined(__cplusplus)
 }

=== modified file 'storage/ndb/include/util/ndb_opts.h'
--- a/storage/ndb/include/util/ndb_opts.h	2007-07-02 17:08:02 +0000
+++ b/storage/ndb/include/util/ndb_opts.h	2008-10-09 11:53:53 +0000
@@ -100,8 +100,13 @@ const char *opt_debug= 0;
 
 static void ndb_std_print_version()
 {
-  printf("MySQL distrib %s, for %s (%s)\n",
-	 NDB_VERSION_STRING,SYSTEM_TYPE,MACHINE_TYPE);
+#ifndef DBUG_OFF
+  const char *suffix= "-debug";
+#else
+  const char *suffix= "";
+#endif
+  printf("MySQL distrib %s%s, for %s (%s)\n",
+	 NDB_VERSION_STRING,suffix,SYSTEM_TYPE,MACHINE_TYPE);
 }
 
 static void usage();

=== modified file 'storage/ndb/include/util/socket_io.h'
--- a/storage/ndb/include/util/socket_io.h	2007-03-22 11:35:07 +0000
+++ b/storage/ndb/include/util/socket_io.h	2008-10-24 11:00:37 +0000
@@ -35,9 +35,9 @@ extern "C" {
                    const char[], int len);
 
   int print_socket(NDB_SOCKET_TYPE, int timeout_ms, int *time,
-                   const char *, ...);
+                   const char *, ...) ATTRIBUTE_FORMAT(printf, 4, 5);
   int println_socket(NDB_SOCKET_TYPE, int timeout_ms, int *time,
-                     const char *, ...);
+                     const char *, ...) ATTRIBUTE_FORMAT(printf, 4, 5);
   int vprint_socket(NDB_SOCKET_TYPE, int timeout_ms, int *time,
                     const char *, va_list);
   int vprintln_socket(NDB_SOCKET_TYPE, int timeout_ms, int *time,

=== modified file 'storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile'
--- a/storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile	2007-05-29 21:39:57 +0000
+++ b/storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile	2008-10-22 10:38:54 +0000
@@ -9,13 +9,11 @@ LFLAGS = -Wall
 TOP_SRCDIR = ../../../..
 INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include
 LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
-          -L$(TOP_SRCDIR)/libmysql_r/.libs \
-	  -L$(TOP_SRCDIR)/zlib/.libs \
-          -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
+          -L$(TOP_SRCDIR)/libmysql_r/.libs
 SYS_LIB = 
 
 $(TARGET): $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys
-lmystrings -lz $(SYS_LIB) -o $(TARGET)
+	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r $(SYS_LIB)
-o $(TARGET)
 
 $(OBJS): $(SRCS)
 	$(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/mgmapi 
-I$(INCLUDE_DIR)/ndbapi $(SRCS)

=== modified file 'storage/ndb/ndbapi-examples/mgmapi_logevent2/Makefile'
--- a/storage/ndb/ndbapi-examples/mgmapi_logevent2/Makefile	2007-05-30 18:29:14 +0000
+++ b/storage/ndb/ndbapi-examples/mgmapi_logevent2/Makefile	2008-10-22 10:38:54 +0000
@@ -9,13 +9,11 @@ LFLAGS = -Wall
 TOP_SRCDIR = ../../../..
 INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include
 LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
-          -L$(TOP_SRCDIR)/libmysql_r/.libs \
-	  -L$(TOP_SRCDIR)/zlib/.libs \
-          -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
+          -L$(TOP_SRCDIR)/libmysql_r/.libs
 SYS_LIB = 
 
 $(TARGET): $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys
-lmystrings -lz $(SYS_LIB) -o $(TARGET)
+	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r $(SYS_LIB)
-o $(TARGET)
 
 $(OBJS): $(SRCS)
 	$(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/mgmapi 
-I$(INCLUDE_DIR)/ndbapi $(SRCS)

=== modified file 'storage/ndb/ndbapi-examples/ndbapi_async/Makefile'
--- a/storage/ndb/ndbapi-examples/ndbapi_async/Makefile	2006-09-01 13:14:50 +0000
+++ b/storage/ndb/ndbapi-examples/ndbapi_async/Makefile	2008-10-22 10:38:54 +0000
@@ -9,16 +9,14 @@ LFLAGS = -Wall
 TOP_SRCDIR = ../../../..
 INCLUDE_DIR = $(TOP_SRCDIR)
 LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
-          -L$(TOP_SRCDIR)/libmysql_r/.libs \
-          -L$(TOP_SRCDIR)/zlib/.libs \
-          -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
+          -L$(TOP_SRCDIR)/libmysql_r/.libs
 SYS_LIB = 
 
 $(TARGET): $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys
-lmystrings -lz $(SYS_LIB) -o $(TARGET)
+	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r $(SYS_LIB)
-o $(TARGET)
 
 $(TARGET).o: $(SRCS)
-	$(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/include -I$(INCLUDE_DIR)/extra
-I$(INCLUDE_DIR)/storage/ndb/include -I$(INCLUDE_DIR)/storage/ndb/include/ndbapi $(SRCS)
+	$(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/include -I$(INCLUDE_DIR)/storage/ndb/include
-I$(INCLUDE_DIR)/storage/ndb/include/ndbapi $(SRCS)
 
 clean:
 	rm -f *.o $(TARGET)

=== modified file 'storage/ndb/ndbapi-examples/ndbapi_async1/Makefile'
--- a/storage/ndb/ndbapi-examples/ndbapi_async1/Makefile	2006-09-01 13:14:50 +0000
+++ b/storage/ndb/ndbapi-examples/ndbapi_async1/Makefile	2008-10-22 10:38:54 +0000
@@ -8,13 +8,11 @@ LFLAGS = -Wall
 TOP_SRCDIR = ../../../..
 INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include
 LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
-          -L$(TOP_SRCDIR)/libmysql_r/.libs \
-          -L$(TOP_SRCDIR)/zlib/.libs \
-          -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
+          -L$(TOP_SRCDIR)/libmysql_r/.libs
 SYS_LIB = 
 
 $(TARGET): $(OBJS)
-	$(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lmystrings -lz
$(SYS_LIB) -o $(TARGET)
+	$(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r $(SYS_LIB) -o $(TARGET)
 
 $(TARGET).o: $(SRCS)
 	$(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi
$(SRCS)

=== modified file 'storage/ndb/ndbapi-examples/ndbapi_blob/Makefile'
--- a/storage/ndb/ndbapi-examples/ndbapi_blob/Makefile	2007-03-26 08:40:57 +0000
+++ b/storage/ndb/ndbapi-examples/ndbapi_blob/Makefile	2008-10-22 10:38:54 +0000
@@ -9,16 +9,14 @@ LFLAGS = -Wall
 TOP_SRCDIR = ../../../..
 INCLUDE_DIR = $(TOP_SRCDIR)
 LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
-          -L$(TOP_SRCDIR)/libmysql_r/.libs \
-          -L$(TOP_SRCDIR)/zlib/.libs \
-          -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
+          -L$(TOP_SRCDIR)/libmysql_r/.libs
 SYS_LIB = 
 
 $(TARGET): $(OBJS)
-	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys
-lmystrings -lz $(SYS_LIB) -o $(TARGET)
+	$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r $(S