diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index d6fb9382b90..1b2ce17a689 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -880,19 +880,28 @@ sub mtr_kill_processes ($) {
 sub mtr_kill_process ($$$$) {
   my $pid= shift;
   my $signal= shift;
-  my $retries= shift;
+  my $total_retries= shift;
   my $timeout= shift;
 
-  while (1)
+  for (my $cur_attempt= 1; $cur_attempt <= $total_retries; ++$cur_attempt)
   {
+    mtr_debug("Sending $signal to $pid...");
+
     kill($signal, $pid);
 
-    last unless kill (0, $pid) and $retries--;
+    unless (kill (0, $pid))
+    {
+      mtr_debug("Process $pid died.");
+      return;
+    }
 
-    mtr_debug("Sleep $timeout second waiting for processes to die");
+    mtr_debug("Sleeping $timeout second(s) waiting for processes to die...");
 
     sleep($timeout);
   }
+
+  mtr_debug("Process $pid is still alive after $total_retries " .
+            "of sending signal $signal.");
 }
 
 ##############################################################################
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 811dd004246..ca2eb6641cd 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -3120,22 +3120,58 @@ sub im_stop($) {
 
   # Try graceful shutdown.
 
+  mtr_debug("IM-main pid: $instance_manager->{'pid'}");
+  mtr_debug("Stopping IM-main...");
+
   mtr_kill_process($instance_manager->{'pid'}, 'TERM', 10, 1);
 
+  # If necessary, wait for angel process to die.
+
+  if (defined $instance_manager->{'angel_pid'})
+  {
+    mtr_debug("IM-angel pid: $instance_manager->{'angel_pid'}");
+    mtr_debug("Waiting for IM-angel to die...");
+
+    my $total_attempts= 10;
+
+    for (my $cur_attempt=1; $cur_attempt <= $total_attempts; ++$cur_attempt)
+    {
+      unless (kill (0, $instance_manager->{'angel_pid'}))
+      {
+        mtr_debug("IM-angel died.");
+        last;
+      }
+
+      sleep(1);
+    }
+  }
+
   # Check that all processes died.
 
   my $clean_shutdown= 0;
 
   while (1)
   {
-    last if kill (0, $instance_manager->{'pid'});
+    if (kill (0, $instance_manager->{'pid'}))
+    {
+      mtr_debug("IM-main is still alive.");
+      last;
+    }
 
-    last if (defined $instance_manager->{'angel_pid'}) &&
-            kill (0, $instance_manager->{'angel_pid'});
+    if (defined $instance_manager->{'angel_pid'} &&
+        kill (0, $instance_manager->{'angel_pid'}))
+    {
+      mtr_debug("IM-angel is still alive.");
+      last;
+    }
 
     foreach my $pid (@mysqld_pids)
     {
-      last if kill (0, $pid);
+      if (kill (0, $pid))
+      {
+        mtr_debug("Guarded mysqld ($pid) is still alive.");
+        last;
+      }
     }
 
     $clean_shutdown= 1;
@@ -3146,15 +3182,21 @@ sub im_stop($) {
 
   unless ($clean_shutdown)
   {
-    mtr_kill_process($instance_manager->{'angel_pid'}, 'KILL', 10, 1)
-      if defined $instance_manager->{'angel_pid'};
+
+    if (defined $instance_manager->{'angel_pid'})
+    {
+      mtr_debug("Killing IM-angel...");
+      mtr_kill_process($instance_manager->{'angel_pid'}, 'KILL', 10, 1)
+    }
     
+    mtr_debug("Killing IM-main...");
     mtr_kill_process($instance_manager->{'pid'}, 'KILL', 10, 1);
 
     # Shutdown managed mysqld-processes. Some of them may be nonguarded, so IM
     # will not stop them on shutdown. So, we should firstly try to end them
     # legally.
 
+    mtr_debug("Killing guarded mysqld(s)...");
     mtr_kill_processes(\@mysqld_pids);
 
     # Complain in error log so that a warning will be shown.
diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result
index 29c9ea2047d..a5526a31384 100644
--- a/mysql-test/r/im_daemon_life_cycle.result
+++ b/mysql-test/r/im_daemon_life_cycle.result
@@ -1,3 +1,4 @@
+Success: the process has been started.
 SHOW INSTANCES;
 instance_name	state
 mysqld1	online
diff --git a/mysql-test/r/im_life_cycle.result b/mysql-test/r/im_life_cycle.result
index 876fbb38eee..b6d3bb8361c 100644
--- a/mysql-test/r/im_life_cycle.result
+++ b/mysql-test/r/im_life_cycle.result
@@ -2,6 +2,7 @@
 --------------------------------------------------------------------
 -- 1.1.1.
 --------------------------------------------------------------------
+Success: the process has been started.
 SHOW INSTANCES;
 instance_name	state
 mysqld1	online
@@ -11,10 +12,7 @@ mysqld2	offline
 -- 1.1.2.
 --------------------------------------------------------------------
 START INSTANCE mysqld2;
-SHOW INSTANCES;
-instance_name	state
-mysqld1	online
-mysqld2	online
+Success: the process has been started.
 SHOW VARIABLES LIKE 'port';
 Variable_name	Value
 port	IM_MYSQLD2_PORT
@@ -23,16 +21,7 @@ port	IM_MYSQLD2_PORT
 -- 1.1.3.
 --------------------------------------------------------------------
 STOP INSTANCE mysqld2;
-SHOW INSTANCES;
-instance_name	state
-mysqld1	online
-mysqld2	offline
-SHOW INSTANCE STATUS mysqld1;
-instance_name	state	version_number	version	mysqld_compatible
-mysqld1	online	VERSION_NUMBER	VERSION	no
-SHOW INSTANCE STATUS mysqld2;
-instance_name	state	version_number	version	mysqld_compatible
-mysqld2	offline	VERSION_NUMBER	VERSION	no
+Success: the process has been stopped.
 
 --------------------------------------------------------------------
 -- 1.1.4.
@@ -58,26 +47,19 @@ mysqld2	offline
 Killing the process...
 Sleeping...
 Success: the process was restarted.
+SHOW INSTANCES;
+instance_name	state
+mysqld1	online
+mysqld2	offline
 
 --------------------------------------------------------------------
 -- 1.1.7.
 --------------------------------------------------------------------
-SHOW INSTANCES;
-instance_name	state
-mysqld1	online
-mysqld2	offline
 START INSTANCE mysqld2;
-SHOW INSTANCES;
-instance_name	state
-mysqld1	online
-mysqld2	online
+Success: the process has been started.
 Killing the process...
 Sleeping...
 Success: the process was killed.
-SHOW INSTANCES;
-instance_name	state
-mysqld1	online
-mysqld2	offline
 
 --------------------------------------------------------------------
 -- 1.1.8.
diff --git a/mysql-test/r/im_utils.result b/mysql-test/r/im_utils.result
index ae8e03bf8ea..df20a7fb5c7 100644
--- a/mysql-test/r/im_utils.result
+++ b/mysql-test/r/im_utils.result
@@ -1,3 +1,4 @@
+Success: the process has been started.
 SHOW INSTANCES;
 instance_name	state
 mysqld1	online
@@ -42,7 +43,9 @@ skip-ndbcluster	VALUE
 nonguarded	VALUE
 log-output	VALUE
 START INSTANCE mysqld2;
+Success: the process has been started.
 STOP INSTANCE mysqld2;
+Success: the process has been stopped.
 SHOW mysqld1 LOG FILES;
 Logfile	Path	File size
 ERROR LOG	PATH	FILE_SIZE
diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result
index 18bd6d7e796..235c3f61fe9 100644
--- a/mysql-test/r/insert.result
+++ b/mysql-test/r/insert.result
@@ -321,3 +321,35 @@ ERROR 42000: Column 'b' specified twice
 INSERT INTO t1 (b,b) SELECT 0,0 ON DUPLICATE KEY UPDATE a = a + VALUES (a);
 ERROR 42000: Column 'b' specified twice
 drop table t1;
+create table t1 (n int);
+create view  v1 as select * from t1;
+insert delayed into v1 values (1);
+ERROR HY000: 'test.v1' is not BASE TABLE
+drop table t1;
+drop view  v1;
+create table t1 (id int primary key, data int);
+insert into t1 values (1, 1), (2, 2), (3, 3);
+select row_count();
+row_count()
+3
+insert ignore into t1 values (1, 1);
+select row_count();
+row_count()
+0
+replace into t1 values (1, 11);
+select row_count();
+row_count()
+2
+replace into t1 values (4, 4);
+select row_count();
+row_count()
+1
+insert into t1 values (2, 2) on duplicate key update data= data + 10;
+select row_count();
+row_count()
+2
+insert into t1 values (5, 5) on duplicate key update data= data + 10;
+select row_count();
+row_count()
+1
+drop table t1;
diff --git a/mysql-test/r/ndb_replace.result b/mysql-test/r/ndb_replace.result
index cdcd935bfcc..8e85feb3bd3 100644
--- a/mysql-test/r/ndb_replace.result
+++ b/mysql-test/r/ndb_replace.result
@@ -1,4 +1,4 @@
-drop table if exists t1;
+drop table if exists t1,t2;
 CREATE TABLE t1 (
 gesuchnr int(11) DEFAULT '0' NOT NULL,
 benutzer_id int(11) DEFAULT '0' NOT NULL,
@@ -31,3 +31,24 @@ SELECT * from t1 ORDER BY i;
 i	j	k
 3	1	42
 17	2	NULL
+CREATE TABLE t2 (a INT(11) NOT NULL,
+b INT(11) NOT NULL,
+c INT(11) NOT NULL,
+x TEXT,
+y TEXT,
+z TEXT,
+id INT(10) unsigned NOT NULL AUTO_INCREMENT,
+i INT(11) DEFAULT NULL,
+PRIMARY KEY (id),
+UNIQUE KEY a (a,b,c)
+) ENGINE=ndbcluster;
+REPLACE INTO t2 (a,b,c,x,y,z,i) VALUES (1,1,1,'a','a','a',1),(1,1,1,'b','b','b',2), (1,1,1,'c','c','c',3);
+SELECT * FROM t2 ORDER BY id;
+a	b	c	x	y	z	id	i
+1	1	1	c	c	c	3	3
+REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'a','a','a',1);
+REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'b','b','b',2);
+SELECT * FROM t2 ORDER BY id;
+a	b	c	x	y	z	id	i
+1	1	1	b	b	b	5	2
+DROP TABLE t2;
diff --git a/mysql-test/r/rpl_ndb_log.result b/mysql-test/r/rpl_ndb_log.result
index c435fb37531..b88af325397 100644
--- a/mysql-test/r/rpl_ndb_log.result
+++ b/mysql-test/r/rpl_ndb_log.result
@@ -132,3 +132,19 @@ ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not find tar
 DROP TABLE t1;
 DROP TABLE t2;
 DROP TABLE t3;
+create table t1(a int auto_increment primary key, b int);
+insert into t1 values (NULL, 1);
+reset master;
+set insert_id=5;
+insert into t1 values (NULL, last_insert_id()), (NULL, last_insert_id());
+show binlog events;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Format_desc	2	#	Server ver: VERSION, Binlog ver: 4
+slave-bin.000001	#	Table_map	2	#	table_id: 30 (test.t1)
+slave-bin.000001	#	Write_rows	2	#	table_id: 30 flags: STMT_END_F
+select * from t1;
+a	b
+1	1
+5	1
+6	1
+drop table t1;
diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index 24675f2cd66..145579201a9 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -169,21 +169,22 @@ select @log;
 @log
 (BEFORE_INSERT: new=(id=1, data=2))
 set @log:= "";
-replace t1 values (1, 3), (2, 2);
+insert into t1 (id, data) values (1, 3), (2, 2) on duplicate key update data= data + 1;
 select @log;
 @log
-(BEFORE_INSERT: new=(id=1, data=3))(BEFORE_UPDATE: old=(id=1, data=1) new=(id=1, data=3))(AFTER_UPDATE: old=(id=1, data=1) new=(id=1, data=3))(BEFORE_INSERT: new=(id=2, data=2))(AFTER_INSERT: new=(id=2, data=2))
-alter table t1 add ts timestamp default now();
+(BEFORE_INSERT: new=(id=1, data=3))(BEFORE_UPDATE: old=(id=1, data=1) new=(id=1, data=2))(AFTER_UPDATE: old=(id=1, data=1) new=(id=1, data=2))(BEFORE_INSERT: new=(id=2, data=2))(AFTER_INSERT: new=(id=2, data=2))
 set @log:= "";
-replace t1 (id, data) values (1, 4);
+replace t1 values (1, 4), (3, 3);
 select @log;
 @log
-(BEFORE_INSERT: new=(id=1, data=4))(BEFORE_DELETE: old=(id=1, data=3))(AFTER_DELETE: old=(id=1, data=3))(AFTER_INSERT: new=(id=1, data=4))
+(BEFORE_INSERT: new=(id=1, data=4))(BEFORE_DELETE: old=(id=1, data=2))(AFTER_DELETE: old=(id=1, data=2))(AFTER_INSERT: new=(id=1, data=4))(BEFORE_INSERT: new=(id=3, data=3))(AFTER_INSERT: new=(id=3, data=3))
+drop trigger t1_bd;
+drop trigger t1_ad;
 set @log:= "";
-insert into t1 (id, data) values (1, 5), (3, 3) on duplicate key update data= data + 2;
+replace t1 values (1, 5);
 select @log;
 @log
-(BEFORE_INSERT: new=(id=1, data=5))(BEFORE_UPDATE: old=(id=1, data=4) new=(id=1, data=6))(AFTER_UPDATE: old=(id=1, data=4) new=(id=1, data=6))(BEFORE_INSERT: new=(id=3, data=3))(AFTER_INSERT: new=(id=3, data=3))
+(BEFORE_INSERT: new=(id=1, data=5))(AFTER_INSERT: new=(id=1, data=5))
 drop table t1;
 create table t1 (id int primary key, data varchar(10), fk int);
 create table t2 (event varchar(100));
@@ -493,15 +494,9 @@ select * from t1;
 i	k
 3	13
 replace into t1 values (3, 3);
-ERROR 42S22: Unknown column 'at' in 'NEW'
-select * from t1;
-i	k
-3	3
-alter table t1 add ts timestamp default now();
-replace into t1 (i, k) values (3, 13);
 ERROR 42S22: Unknown column 'at' in 'OLD'
 select * from t1;
-i	k	ts
+i	k
 drop table t1, t2;
 create table t1 (i int, bt int, k int, key(k)) engine=myisam;
 create table t2 (i int);
@@ -574,18 +569,11 @@ i	k
 1	1
 2	2
 replace into t1 values (2, 4);
-ERROR 42S22: Unknown column 'bt' in 'NEW'
+ERROR 42S22: Unknown column 'bt' in 'OLD'
 select * from t1;
 i	k
 1	1
 2	2
-alter table t1 add ts timestamp default now();
-replace into t1 (i, k) values (2, 11);
-ERROR 42S22: Unknown column 'bt' in 'OLD'
-select * from t1;
-i	k	ts
-1	1	0000-00-00 00:00:00
-2	2	0000-00-00 00:00:00
 drop table t1, t2;
 drop function if exists bug5893;
 create table t1 (col1 int, col2 int);
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index 96f31133e65..6c3df50011c 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -13,9 +13,9 @@
 #events_stress            : BUG#17619 2006-02-21 andrey  Race conditions
 #events                   : BUG#17619 2006-02-21 andrey  Race conditions
 #events_scheduling        : BUG#19170 2006-04-26 andrey  Test case of 19170 fails on some platforms. Has to be checked.
-im_instance_conf          : Bug#20294 2006-06-06 monty   Instance manager test im_instance_conf fails randomly
-im_options                : Bug#20294 2006-06-06 monty   Instance manager test im_instance_conf fails randomly
-im_life_cycle             : Bug#20368 2006-06-10 alik    im_life_cycle test fails
+im_instance_conf         : Bug#20294 2006-06-06 monty   Instance manager test im_instance_conf fails randomly
+im_options               : Bug#20294 2006-06-06 monty   Instance manager test im_instance_conf fails randomly
+im_life_cycle            : Bug#20368 2006-06-10 alik    im_life_cycle test fails
 ndb_autodiscover         : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog
 ndb_autodiscover2        : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog
 #ndb_binlog_discover      : BUG#19395 2006-04-28 tomas/knielsen mysqld does not always detect cluster shutdown
diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest
index d173ce2a6e2..3afc36935f8 100644
--- a/mysql-test/t/im_daemon_life_cycle.imtest
+++ b/mysql-test/t/im_daemon_life_cycle.imtest
@@ -10,9 +10,22 @@
 
 ###########################################################################
 
+# Wait for mysqld1 (guarded instance) to start.
+
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
+
+# Let IM detect that mysqld1 is online. This delay should be longer than
+# monitoring interval.
+
 --sleep 3
-# should be longer than monitoring interval and enough to start instance.
+
+# Check that start conditions are as expected.
 
 SHOW INSTANCES;
 
---exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted
+###########################################################################
+
+# Kill the IM main process and check that the IM Angel will restart the main
+# process.
+
+--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30
diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest
index d71cdc86624..2cbe53a7b28 100644
--- a/mysql-test/t/im_life_cycle.imtest
+++ b/mysql-test/t/im_life_cycle.imtest
@@ -22,8 +22,16 @@
 --echo -- 1.1.1.
 --echo --------------------------------------------------------------------
 
+# Wait for mysqld1 (guarded instance) to start.
+
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
+
+# Let IM detect that mysqld1 is online. This delay should be longer than
+# monitoring interval.
+
 --sleep 3
-# should be longer than monitoring interval and enough to start instance.
+
+# Check that start conditions are as expected.
 
 SHOW INSTANCES;
 
@@ -44,10 +52,12 @@ SHOW INSTANCES;
 
 START INSTANCE mysqld2;
 # FIXME: START INSTANCE should be synchronous.
---sleep 3
-# should be longer than monitoring interval and enough to start instance.
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
 
-SHOW INSTANCES;
+# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
+# synchronous. Even waiting for mysqld to start by looking at its pid file is
+# not enough, because IM may not detect that mysqld has started.
+# SHOW INSTANCES;
 
 --connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK)
 --connection mysql_con
@@ -74,14 +84,12 @@ SHOW VARIABLES LIKE 'port';
 
 STOP INSTANCE mysqld2;
 # FIXME: STOP INSTANCE should be synchronous.
---sleep 3
-# should be longer than monitoring interval and enough to stop instance.
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped
 
-SHOW INSTANCES;
---replace_column 3 VERSION_NUMBER 4 VERSION
-SHOW INSTANCE STATUS mysqld1;
---replace_column 3 VERSION_NUMBER 4 VERSION
-SHOW INSTANCE STATUS mysqld2;
+# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
+# synchronous. Even waiting for mysqld to start by looking at its pid file is
+# not enough, because IM may not detect that mysqld has started.
+# SHOW INSTANCES;
 
 ###########################################################################
 #
@@ -140,10 +148,14 @@ STOP INSTANCE mysqld3;
 
 SHOW INSTANCES;
 
---exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted
+--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30
+
+# Give some time to IM to detect that mysqld was restarted. It should be longer
+# than monitoring interval.
 
 --sleep 3
-# should be longer than monitoring interval and enough to start instance.
+
+SHOW INSTANCES;
 
 ###########################################################################
 #
@@ -156,18 +168,21 @@ SHOW INSTANCES;
 --echo -- 1.1.7.
 --echo --------------------------------------------------------------------
 
-SHOW INSTANCES;
-
 START INSTANCE mysqld2;
 # FIXME: START INSTANCE should be synchronous.
---sleep 3
-# should be longer than monitoring interval and enough to start instance.
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
 
-SHOW INSTANCES;
+# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
+# synchronous. Even waiting for mysqld to start by looking at its pid file is
+# not enough, because IM may not detect that mysqld has started.
+# SHOW INSTANCES;
 
---exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed
+--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10
 
-SHOW INSTANCES;
+# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
+# synchronous. Even waiting for mysqld to start by looking at its pid file is
+# not enough, because IM may not detect that mysqld has started.
+# SHOW INSTANCES;
 
 ###########################################################################
 #
diff --git a/mysql-test/t/im_utils.imtest b/mysql-test/t/im_utils.imtest
index 8e8d475cfee..47902eeba52 100644
--- a/mysql-test/t/im_utils.imtest
+++ b/mysql-test/t/im_utils.imtest
@@ -17,8 +17,16 @@
 #  - the second instance is offline;
 #
 
+# Wait for mysqld1 (guarded instance) to start.
+
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
+
+# Let IM detect that mysqld1 is online. This delay should be longer than
+# monitoring interval.
+
 --sleep 3
-# should be longer than monitoring interval and enough to start instance.
+
+# Check that start conditions are as expected.
 
 SHOW INSTANCES;
 
@@ -43,12 +51,10 @@ SHOW INSTANCE OPTIONS mysqld2;
 #
 
 START INSTANCE mysqld2;
-
-# FIXME: START INSTANCE should be synchronous.
---sleep 3
-# should be longer than monitoring interval and enough to start instance.
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
 
 STOP INSTANCE mysqld2;
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped
 
 #
 # Check 'SHOW LOG FILES' command:
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test
index e2514083ea7..3711e2986ed 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -201,3 +201,36 @@ insert into t1 (b,b) select 1,2;
 --error 1110
 INSERT INTO t1 (b,b) SELECT 0,0 ON DUPLICATE KEY UPDATE a = a + VALUES (a);
 drop table t1;
+# Test for INSERT DELAYED INTO a <view>
+# BUG#13683: INSERT DELAYED into a view creates an infinite loop
+#
+
+create table t1 (n int);
+create view  v1 as select * from t1;
+--error 1347
+insert delayed into v1 values (1);
+drop table t1;
+drop view  v1;
+
+#
+# Test for values returned by ROW_COUNT() function
+# (and thus for values returned by mysql_affected_rows())
+# for various forms of INSERT
+#
+create table t1 (id int primary key, data int);
+insert into t1 values (1, 1), (2, 2), (3, 3);
+select row_count();
+insert ignore into t1 values (1, 1);
+select row_count();
+# Reports that 2 rows are affected (1 deleted + 1 inserted)
+replace into t1 values (1, 11);
+select row_count();
+replace into t1 values (4, 4);
+select row_count();
+# Reports that 2 rows are affected. This conforms to documentation.
+# (Useful for differentiating inserts from updates).
+insert into t1 values (2, 2) on duplicate key update data= data + 10;
+select row_count();
+insert into t1 values (5, 5) on duplicate key update data= data + 10;
+select row_count();
+drop table t1;
diff --git a/mysql-test/t/kill_n_check.sh b/mysql-test/t/kill_n_check.sh
index e722b3a180d..64cc869d1ec 100755
--- a/mysql-test/t/kill_n_check.sh
+++ b/mysql-test/t/kill_n_check.sh
@@ -1,66 +1,115 @@
 #!/bin/sh
 
-if [ $# -ne 2 ]; then
-  echo "Usage: kill_n_check.sh <pid file path> killed|restarted"
+###########################################################################
+
+# NOTE: this script returns 0 (success) even in case of failure. This is
+# because this script is executed under mysql-test-run[.pl] and it's better to
+# examine particular problem in log file, than just having said that the test
+# case has failed.
+
+###########################################################################
+
+check_restart()
+{
+  if [ ! -r "$pid_path" ]; then
+    user_msg='the process was killed'
+    return 1
+  fi
+
+  new_pid=`cat "$pid_path" 2>/dev/null`
+
+  if [ $? -eq 0 -a "$original_pid" = "$new_pid" ]; then
+    user_msg='the process was not restarted'
+    return 1
+  fi
+
+  user_msg='the process was restarted'
+  return 0
+}
+
+###########################################################################
+
+if [ $# -ne 3 ]; then
+  echo "Usage: kill_n_check.sh <pid file path> killed|restarted <timeout>"
   exit 0
 fi
 
 pid_path="$1"
 expected_result="$2"
+total_timeout="$3"
 
-if [ -z "$pid_path" -o ! -r "$pid_path" ]; then
-  echo "Error: invalid PID path ($pid_path) or PID file does not exist."
+if [ "$expected_result" != 'killed' -a \
+     "$expected_result" != 'restarted' ]; then
+  echo "Error: invalid second argument ('killed' or 'restarted' expected)."
   exit 0
 fi
 
-if [ "$expected_result" != "killed" -a \
-     "$expected_result" != "restarted" ]; then
-  echo "Error: expected result must be either 'killed' or 'restarted'."
+if [ -z "$pid_path" ]; then
+  echo "Error: invalid PID path ($pid_path)."
   exit 0
 fi
 
-# echo "PID path: '$pid_path'"
+if [ $expected_result = 'killed' -a ! -r "$pid_path" ]; then
+  echo "Error: PID file ($pid_path) does not exist."
+  exit 0
+fi
+
+if [ -z "$total_timeout" ]; then
+  echo "Error: timeout is not specified."
+  exit 0
+fi
+
+###########################################################################
 
 original_pid=`cat "$pid_path"`
 
-# echo "Original PID: $original_pid"
-
 echo "Killing the process..."
 
 kill -9 $original_pid
 
+###########################################################################
+
 echo "Sleeping..."
 
-sleep 3
-
-new_pid=""
-
-[ -r "$pid_path" ] && new_pid=`cat "$pid_path"`
-
-# echo "New PID: $new_pid"
-
 if [ "$expected_result" = "restarted" ]; then
 
-  if [ -z "$new_pid" ]; then
-    echo "Error: the process was killed."
-    exit 0
-  fi
+  # Wait for the process to restart.
 
-  if [ "$original_pid" -eq "$new_pid" ]; then
-    echo "Error: the process was not restarted."
-    exit 0
-  fi
-  
-  echo "Success: the process was restarted."
+  cur_attempt=1
+
+  while true; do
+
+    if check_restart; then
+      echo "Success: $user_msg."
+      exit 0
+    fi
+
+    [ $cur_attempt -ge $total_timeout ] && break
+
+    sleep 1
+
+    cur_attempt=`expr $cur_attempt + 1`
+
+  done
+
+  echo "Error: $user_msg."
   exit 0
-  
-else # $expected_result = killed
-    
+
+else # $expected_result == killed
+
+  # Here we have to sleep for some long time to ensure that the process will
+  # not be restarted.
+
+  sleep $total_timeout
+
+  new_pid=`cat "$pid_path" 2>/dev/null`
+
   if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then
     echo "Error: the process was restarted."
-    exit 0
+  else
+    echo "Success: the process was killed."
   fi
 
-  echo "Success: the process was killed."
   exit 0
+
 fi
diff --git a/mysql-test/t/ndb_replace.test b/mysql-test/t/ndb_replace.test
index 6cad80ef8ea..94a11f7dfb2 100644
--- a/mysql-test/t/ndb_replace.test
+++ b/mysql-test/t/ndb_replace.test
@@ -6,7 +6,7 @@
 #
 
 --disable_warnings
-drop table if exists t1;
+drop table if exists t1,t2;
 --enable_warnings
 
 CREATE TABLE t1 (
@@ -27,6 +27,8 @@ replace into t1 (gesuchnr,benutzer_id) values (1,1);
 select * from t1 order by gesuchnr;
 drop table t1;
 
+# End of 4.1 tests
+
 # bug#17431
 CREATE TABLE t1(i INT PRIMARY KEY AUTO_INCREMENT, 
                 j INT, 
@@ -38,4 +40,28 @@ REPLACE INTO t1 (j,k) VALUES (1,42);
 REPLACE INTO t1 (i,j) VALUES (17,2);
 SELECT * from t1 ORDER BY i;
 
-# End of 4.1 tests
+# bug#19906
+CREATE TABLE t2 (a INT(11) NOT NULL,
+	         b INT(11) NOT NULL,
+                 c INT(11) NOT NULL,
+                 x TEXT,
+                 y TEXT,
+                 z TEXT,
+                 id INT(10) unsigned NOT NULL AUTO_INCREMENT,
+                 i INT(11) DEFAULT NULL,
+                 PRIMARY KEY (id),
+                 UNIQUE KEY a (a,b,c)
+) ENGINE=ndbcluster;
+
+REPLACE INTO t2 (a,b,c,x,y,z,i) VALUES (1,1,1,'a','a','a',1),(1,1,1,'b','b','b',2), (1,1,1,'c','c','c',3);
+
+SELECT * FROM t2 ORDER BY id;
+
+REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'a','a','a',1);
+REPLACE INTO t2(a,b,c,x,y,z,i) values (1,1,1,'b','b','b',2);
+
+SELECT * FROM t2 ORDER BY id;
+
+DROP TABLE t2;
+
+
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index a87f289e94e..58adffc6e87 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -185,24 +185,26 @@ select @log;
 set @log:= "";
 insert ignore t1 values (1, 2);
 select @log;
-# REPLACE: before insert trigger should be called for both records,
-#          but then for first one update will be executed (and both update
-#          triggers should fire). For second after insert trigger will be
-#          called as for usual insert
+# INSERT ... ON DUPLICATE KEY UPDATE ...
 set @log:= "";
-replace t1 values (1, 3), (2, 2);
+insert into t1 (id, data) values (1, 3), (2, 2) on duplicate key update data= data + 1;
 select @log;
-# Now let us change table in such way that REPLACE on won't be executed
-# using update.
-alter table t1 add ts timestamp default now();
+# REPLACE (also test for bug#13479 "REPLACE activates UPDATE trigger,
+#          not the DELETE and INSERT triggers")
+# We define REPLACE as INSERT which DELETEs old rows which conflict with
+# row being inserted. So for the first record in statement below we will
+# call before insert trigger, then delete will be executed (and both delete
+# triggers should fire). Finally after insert trigger will be called.
+# For the second record we will just call both on insert triggers.
 set @log:= "";
-# This REPLACE should be executed via DELETE and INSERT so proper 
-# triggers should be invoked.
-replace t1 (id, data) values (1, 4);
+replace t1 values (1, 4), (3, 3);
 select @log;
-# Finally let us test INSERT ... ON DUPLICATE KEY UPDATE ...
+# Now we will drop ON DELETE triggers to test REPLACE which is internally
+# executed via update
+drop trigger t1_bd;
+drop trigger t1_ad;
 set @log:= "";
-insert into t1 (id, data) values (1, 5), (3, 3) on duplicate key update data= data + 2; 
+replace t1 values (1, 5);
 select @log;
 
 # This also drops associated triggers
@@ -531,14 +533,11 @@ alter table t1 add primary key (i);
 --error 1054
 insert into t1 values (3, 4) on duplicate key update k= k + 10;
 select * from t1;
+# The following statement will delete old row and won't
+# insert new one since after delete trigger will fail.
 --error 1054
 replace into t1 values (3, 3);
 select * from t1;
-# Change table in such way that REPLACE will delete row
-alter table t1 add ts timestamp default now();
---error 1054
-replace into t1 (i, k) values (3, 13);
-select * from t1;
 # Also drops all triggers
 drop table t1, t2;
 
@@ -594,11 +593,6 @@ select * from t1;
 --error 1054
 replace into t1 values (2, 4);
 select * from t1;
-# Change table in such way that REPLACE will delete row
-alter table t1 add ts timestamp default now();
---error 1054
-replace into t1 (i, k) values (2, 11);
-select * from t1;
 # Also drops all triggers
 drop table t1, t2;
 
diff --git a/mysql-test/t/wait_for_process.sh b/mysql-test/t/wait_for_process.sh
new file mode 100755
index 00000000000..df0f4a17e3a
--- /dev/null
+++ b/mysql-test/t/wait_for_process.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+###########################################################################
+
+pid_path="$1"
+total_attempts="$2"
+event="$3"
+
+case "$3" in
+  started)
+    check_fn='check_started';
+    ;;
+
+  stopped)
+    check_fn='check_stopped';
+    ;;
+
+  *)
+    echo "Error: invalid third argument ('started' or 'stopped' expected)."
+    exit 0
+esac
+
+###########################################################################
+
+check_started()
+{
+  [ ! -r "$pid_path" ] && return 1
+
+  new_pid=`cat "$pid_path" 2>/dev/null`
+
+  [ $? -eq 0 -a "$original_pid" = "$new_pid" ] && return 1
+
+  return 0
+}
+
+###########################################################################
+
+check_stopped()
+{
+  [ -r "$pid_path" ] && return 1
+
+  return 0
+}
+
+###########################################################################
+
+cur_attempt=1
+
+while true; do
+
+  if ( eval $check_fn ); then
+    echo "Success: the process has been $event."
+    exit 0
+  fi
+
+  [ $cur_attempt -ge $total_attempts ] && break
+
+  sleep 1
+
+  cur_attempt=`expr $cur_attempt + 1`
+
+done
+
+echo "Error: the process has not been $event in $total_attempts secs."
+exit 0
+
diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc
index c9608fa7c14..ec73fb7d73a 100644
--- a/server-tools/instance-manager/instance_map.cc
+++ b/server-tools/instance-manager/instance_map.cc
@@ -293,7 +293,7 @@ int Instance_map::flush_instances()
             get_instance_key, delete_instance, 0);
 
   rc= load();
-  guardian->init();
+  guardian->init(); // TODO: check error status.
   return rc;
 }
 
diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc
index 599131089ed..d2d498eebf1 100644
--- a/server-tools/instance-manager/manager.cc
+++ b/server-tools/instance-manager/manager.cc
@@ -198,6 +198,25 @@ void manager()
   if (create_pid_file(Options::Main::pid_file_name, manager_pid))
     return; /* necessary logging has been already done. */
 
+  /*
+    Initialize signals and alarm-infrastructure.
+
+    NOTE: To work nicely with LinuxThreads, the signal thread is the first
+    thread in the process.
+
+    NOTE:
+      After init_thr_alarm() call it's possible to call thr_alarm() (from
+      different threads), that results in sending ALARM signal to the alarm
+      thread (which can be the main thread). That signal can interrupt
+      blocking calls.
+
+      In other words, a blocking call can be interrupted in the main thread
+      after init_thr_alarm().
+  */
+
+  sigset_t mask;
+  set_signals(&mask);
+
   /* create guardian thread */
   {
     pthread_t guardian_thd_id;
@@ -205,9 +224,16 @@ void manager()
     int rc;
 
     /*
-       NOTE: Guardian should be shutdown first. Only then all other threads
-       need to be stopped. This should be done, as guardian is responsible for
-       shutting down the instances, and this is a long operation.
+      NOTE: Guardian should be shutdown first. Only then all other threads
+      need to be stopped. This should be done, as guardian is responsible
+      for shutting down the instances, and this is a long operation.
+
+      NOTE: Guardian uses thr_alarm() when detects current state of
+      instances (is_running()), but it is not interfere with
+      flush_instances() later in the code, because until flush_instances()
+      complete in the main thread, Guardian thread is not permitted to
+      process instances. And before flush_instances() there is no instances
+      to proceed.
     */
 
     pthread_attr_init(&guardian_thd_attr);
@@ -223,10 +249,8 @@ void manager()
 
   }
 
-  /*
-    To work nicely with LinuxThreads, the signal thread is the first thread
-    in the process.
-  */
+  /* Load instances. */
+
 
   {
     instance_map.guardian->lock();
@@ -246,11 +270,6 @@ void manager()
     }
   }
 
-  /* Initialize signals and alarm-infrastructure. */
-
-  sigset_t mask;
-  set_signals(&mask);
-
   /* create the listener */
   {
     pthread_t listener_thd_id;
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 6c66ba620c9..7afa2852e1a 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -735,7 +735,7 @@ int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg)
   ha_ndbcluster *ha= (ha_ndbcluster *)arg;
   int ret= get_ndb_blobs_value(ha->table, ha->m_value,
                                ha->m_blobs_buffer, ha->m_blobs_buffer_size,
-                               0);
+                               ha->m_blobs_offset);
   DBUG_RETURN(ret);
 }
 
@@ -864,6 +864,7 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field,
       if (ndb_blob != NULL)
       {
         // Set callback
+	m_blobs_offset= buf - (byte*) table->record[0];
         void *arg= (void *)this;
         DBUG_RETURN(ndb_blob->setActiveHook(g_get_ndb_blobs_value, arg) != 0);
       }
@@ -5477,6 +5478,7 @@ ha_ndbcluster::ha_ndbcluster(TABLE_SHARE *table_arg):
   m_ops_pending(0),
   m_skip_auto_increment(TRUE),
   m_blobs_pending(0),
+  m_blobs_offset(0),
   m_blobs_buffer(0),
   m_blobs_buffer_size(0),
   m_dupkey((uint) -1),
diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h
index 9bcc549cb60..df3c5791713 100644
--- a/sql/ha_ndbcluster.h
+++ b/sql/ha_ndbcluster.h
@@ -798,7 +798,6 @@ private:
   int get_ndb_value(NdbOperation*, Field *field, uint fieldnr, byte*);
   int get_ndb_partition_id(NdbOperation *);
   friend int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg);
-  int get_ndb_blobs_value(NdbBlob *last_ndb_blob);
   int set_primary_key(NdbOperation *op, const byte *key);
   int set_primary_key_from_record(NdbOperation *op, const byte *record);
   int set_index_key_from_record(NdbOperation *op, const byte *record,
@@ -883,6 +882,7 @@ private:
   ha_rows m_ops_pending;
   bool m_skip_auto_increment;
   bool m_blobs_pending;
+  my_ptrdiff_t m_blobs_offset;
   // memory for blobs in one tuple
   char *m_blobs_buffer;
   uint32 m_blobs_buffer_size;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index f1f97400283..ecf4f4a545b 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1083,16 +1083,19 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
 	  to convert the latter operation internally to an UPDATE.
           We also should not perform this conversion if we have 
           timestamp field with ON UPDATE which is different from DEFAULT.
+          Another case when conversion should not be performed is when
+          we have ON DELETE trigger on table so user may notice that
+          we cheat here. Note that it is ok to do such conversion for
+          tables which have ON UPDATE but have no ON DELETE triggers,
+          we just should not expose this fact to users by invoking
+          ON UPDATE triggers.
 	*/
 	if (last_uniq_key(table,key_nr) &&
 	    !table->file->referenced_by_foreign_key() &&
             (table->timestamp_field_type == TIMESTAMP_NO_AUTO_SET ||
-             table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
+             table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH) &&
+            (!table->triggers || !table->triggers->has_delete_triggers()))
         {
-          if (table->triggers &&
-              table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
-                                                TRG_ACTION_BEFORE, TRUE))
-            goto before_trg_err;
           if (thd->clear_next_insert_id)
           {
             /* Reset auto-increment cacheing if we do an update */
@@ -1103,13 +1106,11 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
 					        table->record[0])))
             goto err;
           info->deleted++;
-          trg_error= (table->triggers &&
-                      table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
-                                                        TRG_ACTION_AFTER,
-                                                        TRUE));
-          /* Update logfile and count */
-          info->copied++;
-          goto ok_or_after_trg_err;
+          /*
+            Since we pretend that we have done insert we should call
+            its after triggers.
+          */
+          goto after_trg_n_copied_inc;
         }
         else
         {
@@ -1133,10 +1134,6 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
         }
       }
     }
-    info->copied++;
-    trg_error= (table->triggers &&
-                table->triggers->process_triggers(thd, TRG_EVENT_INSERT,
-                                                  TRG_ACTION_AFTER, TRUE));
     /*
       Restore column maps if they where replaced during an duplicate key
       problem.
@@ -1151,14 +1148,14 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
 	(error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE))
       goto err;
     table->file->restore_auto_increment();
+    goto ok_or_after_trg_err;
   }
-  else
-  {
-    info->copied++;
-    trg_error= (table->triggers &&
-                table->triggers->process_triggers(thd, TRG_EVENT_INSERT,
-                                                  TRG_ACTION_AFTER, TRUE));
-  }
+
+after_trg_n_copied_inc:
+  info->copied++;
+  trg_error= (table->triggers &&
+              table->triggers->process_triggers(thd, TRG_EVENT_INSERT,
+                                                TRG_ACTION_AFTER, TRUE));
 
 ok_or_after_trg_err:
   if (key)
diff --git a/storage/ndb/include/mgmapi/ndbd_exit_codes.h b/storage/ndb/include/mgmapi/ndbd_exit_codes.h
index 686641ebef5..b16f1a63a8d 100644
--- a/storage/ndb/include/mgmapi/ndbd_exit_codes.h
+++ b/storage/ndb/include/mgmapi/ndbd_exit_codes.h
@@ -77,6 +77,7 @@ typedef ndbd_exit_classification_enum ndbd_exit_classification;
 #define NDBD_EXIT_SR_RESTARTCONFLICT          2311
 #define NDBD_EXIT_NO_MORE_UNDOLOG             2312 
 #define NDBD_EXIT_SR_UNDOLOG                  2313 
+#define NDBD_EXIT_SR_SCHEMAFILE               2310
 #define NDBD_EXIT_MEMALLOC                    2327
 #define NDBD_EXIT_BLOCK_JBUFCONGESTION        2334
 #define NDBD_EXIT_TIME_QUEUE_SHORT            2335
@@ -91,6 +92,9 @@ typedef ndbd_exit_classification_enum ndbd_exit_classification;
 #define NDBD_EXIT_INVALID_CONFIG              2350
 #define NDBD_EXIT_OUT_OF_LONG_SIGNAL_MEMORY   2351
 
+/* Errorcodes for fatal resource errors */
+#define NDBD_EXIT_RESOURCE_ALLOC_ERROR        2500
+
 #define NDBD_EXIT_OS_SIGNAL_RECEIVED          6000
 
 /* VM 6050-> */
diff --git a/storage/ndb/src/common/transporter/TransporterRegistry.cpp b/storage/ndb/src/common/transporter/TransporterRegistry.cpp
index 633cfeb0ac2..458f7c4f47e 100644
--- a/storage/ndb/src/common/transporter/TransporterRegistry.cpp
+++ b/storage/ndb/src/common/transporter/TransporterRegistry.cpp
@@ -1319,7 +1319,7 @@ TransporterRegistry::start_clients_thread()
 	      else
 	      {
 		ndbout_c("Management server closed connection early. "
-			 "It is probably being shut down (or has crashed). "
+			 "It is probably being shut down (or has problems). "
 			 "We will retry the connection.");
 	      }
 	    }
diff --git a/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp b/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
index ef08c06822f..e9d2fce5e18 100644
--- a/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
+++ b/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
@@ -1355,10 +1355,11 @@ void Dbdict::readSchemaConf(Signal* signal,
       sf->FileSize == sf0->FileSize &&
       sf->PageNumber == n &&
       computeChecksum((Uint32*)sf, NDB_SF_PAGE_SIZE_IN_WORDS) == 0;
-    ndbrequire(ok || !crashInd);
+    ndbrequireErr(ok || !crashInd, NDBD_EXIT_SR_SCHEMAFILE);
     if (! ok) {
       jam();
-      ndbrequire(fsPtr.p->fsState == FsConnectRecord::READ_SCHEMA1);
+      ndbrequireErr(fsPtr.p->fsState == FsConnectRecord::READ_SCHEMA1,
+                    NDBD_EXIT_SR_SCHEMAFILE);
       readSchemaRef(signal, fsPtr);
       return;
     }
diff --git a/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp b/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
index bb4c2ed197e..dc93dca4e46 100644
--- a/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
+++ b/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
@@ -8606,7 +8606,7 @@ Dbdih::resetReplicaSr(TabRecordPtr tabPtr){
 	     *--------_----------------------------------------------------- */
 	    const Uint32 nextCrashed = noCrashedReplicas + 1;
 	    replicaPtr.p->noCrashedReplicas = nextCrashed;
-	    arrGuard(nextCrashed, 8);
+	    arrGuardErr(nextCrashed, 8, NDBD_EXIT_MAX_CRASHED_REPLICAS);
 	    replicaPtr.p->createGci[nextCrashed] = newestRestorableGCI + 1;
 	    ndbrequire(newestRestorableGCI + 1 != 0xF1F1F1F1);
 	    replicaPtr.p->replicaLastGci[nextCrashed] = (Uint32)-1;
diff --git a/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp b/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp
index 53cf5c06fe4..bdd19839a02 100644
--- a/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp
+++ b/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp
@@ -17839,7 +17839,8 @@ void Dblqh::stepAhead(Signal* signal, Uint32 stepAheadWords)
     logFilePtr.p->currentLogpage = logPagePtr.p->logPageWord[ZNEXT_PAGE];
     logPagePtr.i = logPagePtr.p->logPageWord[ZNEXT_PAGE];
     logFilePtr.p->currentFilepage++;
-    ptrCheckGuard(logPagePtr, clogPageFileSize, logPageRecord);
+    ptrCheckGuardErr(logPagePtr, clogPageFileSize, logPageRecord,
+                     NDBD_EXIT_SR_REDOLOG);
     logPagePtr.p->logPageWord[ZCURR_PAGE_INDEX] = ZPAGE_HEADER_SIZE;
     logPartPtr.p->execSrPagesRead--;
     logPartPtr.p->execSrPagesExecuted++;
diff --git a/storage/ndb/src/kernel/blocks/suma/Suma.cpp b/storage/ndb/src/kernel/blocks/suma/Suma.cpp
index 91f0fab06f8..686ae476879 100644
--- a/storage/ndb/src/kernel/blocks/suma/Suma.cpp
+++ b/storage/ndb/src/kernel/blocks/suma/Suma.cpp
@@ -410,7 +410,22 @@ Suma::createSequenceReply(Signal* signal,
   jam();
 
   if (ref != NULL)
+  {
+    switch ((UtilSequenceRef::ErrorCode)ref->errorCode)
+    {
+      case UtilSequenceRef::NoSuchSequence:
+        ndbrequire(false);
+      case UtilSequenceRef::TCError:
+      {
+        char buf[128];
+        snprintf(buf, sizeof(buf),
+                 "Startup failed during sequence creation. TC error %d",
+                 ref->TCErrorCode);
+        progError(__LINE__, NDBD_EXIT_RESOURCE_ALLOC_ERROR, buf);
+      }
+    }
     ndbrequire(false);
+  }
 
   sendSTTORRY(signal);
 }
diff --git a/storage/ndb/src/kernel/error/ndbd_exit_codes.c b/storage/ndb/src/kernel/error/ndbd_exit_codes.c
index 6a14d8b7ffd..172125c35a1 100644
--- a/storage/ndb/src/kernel/error/ndbd_exit_codes.c
+++ b/storage/ndb/src/kernel/error/ndbd_exit_codes.c
@@ -51,14 +51,16 @@ static const ErrStruct errArray[] =
    {NDBD_EXIT_SYSTEM_ERROR, XIE,
     "System error, node killed during node restart by other node"},
    {NDBD_EXIT_INDEX_NOTINRANGE, XIE, "Array index out of range"},
-   {NDBD_EXIT_ARBIT_SHUTDOWN, XAE, "Arbitrator shutdown, "
-    "please investigate error(s) on other node(s)"},
+   {NDBD_EXIT_ARBIT_SHUTDOWN, XAE, "Node lost connection to other nodes and "
+    "can not form a unpartitioned cluster, please investigate if there are "
+    "error(s) on other node(s)"},
    {NDBD_EXIT_POINTER_NOTINRANGE, XIE, "Pointer too large"},
    {NDBD_EXIT_SR_OTHERNODEFAILED, XRE, "Another node failed during system "
     "restart, please investigate error(s) on other node(s)"},
    {NDBD_EXIT_NODE_NOT_DEAD, XRE, "Internal node state conflict, "
     "most probably resolved by restarting node again"},
    {NDBD_EXIT_SR_REDOLOG, XFI, "Error while reading the REDO log"},
+   {NDBD_EXIT_SR_SCHEMAFILE, XFI, "Error while reading the schema file"},
    /* Currently unused? */
    {2311, XIE, "Conflict when selecting restart type"},
    {NDBD_EXIT_NO_MORE_UNDOLOG, XCR,
@@ -80,6 +82,10 @@ static const ErrStruct errArray[] =
    /* this error message is complemented by additional info when generated */
    {NDBD_EXIT_INVALID_CONFIG, XCE,
     "Invalid configuration received from Management Server"},
+
+   {NDBD_EXIT_RESOURCE_ALLOC_ERROR, XCE,
+    "Resource allocation error, please review the configuration"},
+
    /* this error message is complemented by additional info when
       generated, such as signal, and text
    */
@@ -94,7 +100,7 @@ static const ErrStruct errArray[] =
    {NDBD_EXIT_WATCHDOG_TERMINATE, XIE, "WatchDog terminate, internal error "
     "or massive overload on the machine running this node"},
    {NDBD_EXIT_SIGNAL_LOST_SEND_BUFFER_FULL, XCR,
-    "Signal lost, out of send buffer memory, please increase SendBufferMemory"},
+    "Signal lost, out of send buffer memory, please increase SendBufferMemory or lower the load"},
    {NDBD_EXIT_SIGNAL_LOST,    XIE, "Signal lost (unknown reason)"},
    {NDBD_EXIT_ILLEGAL_SIGNAL, XIE,
     "Illegal signal (version mismatch a possibility)"},
diff --git a/storage/ndb/src/ndbapi/ndberror.c b/storage/ndb/src/ndbapi/ndberror.c
index a867ad7315b..b72ce4bd3c6 100644
--- a/storage/ndb/src/ndbapi/ndberror.c
+++ b/storage/ndb/src/ndbapi/ndberror.c
@@ -284,6 +284,7 @@ ErrorBundle ErrorCodes[] = {
   /**
    * Application error
    */
+  { 763,  DMEC, AE, "Alter table requires cluster nodes to have exact same version" },
   { 823,  DMEC, AE, "Too much attrinfo from application in tuple manager" },
   { 831,  DMEC, AE, "Too many nullable/bitfields in table definition" },
   { 876,  DMEC, AE, "876" },
@@ -344,6 +345,7 @@ ErrorBundle ErrorCodes[] = {
   /**
    * SchemaError
    */
+  { 311,  DMEC, AE, "Undefined partition used in setPartitionId" },
   { 703,  DMEC, SE, "Invalid table format" },
   { 704,  DMEC, SE, "Attribute name too long" },
   { 705,  DMEC, SE, "Table name too long" },