--source include/have_falcon.inc
#
# Bug #22160: REPLACE crash with two interleaving transactions
# The changes for Bug#34351 means that the second transaction
# in this test does not atempt to lock the inserted record
# since it is not visible, even after it was committed.
# So the result is now 132 (ER_KEY_NOT_FOUND) instead of
# 1020 (ER_CHECKREAD or UpdateConflict)
#
--echo *** Bug #22160 ***

# ----------------------------------------------------- #
# --- Initialisation                                --- #
# ----------------------------------------------------- #
let $engine = 'Falcon';
eval SET @@storage_engine = $engine;

SELECT @@GLOBAL.falcon_consistent_read INTO @previous_falcon_consistent_read;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET GLOBAL falcon_consistent_read = ON;

--disable_warnings
DROP DATABASE IF EXISTS db64;
--enable_warnings

CREATE DATABASE db64;
USE db64;

--echo # Establish connection conn1
connect (conn1,localhost,root,,);
eval SET @@storage_engine = $engine;
USE db64;

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
CREATE TABLE t1 (s1 int, primary key (s1));
SET @@autocommit = 0;
INSERT INTO t1 VALUES (1);

--echo # Switch to connection conn1
connection conn1;
SET @@autocommit = 0;
SELECT * FROM t1;

--echo # Switch to connection default
connection default;
COMMIT;

--echo # Switch to connection conn1
connection conn1;
--real_sleep 1
--error ER_KEY_NOT_FOUND
REPLACE INTO t1 VALUES (1);
COMMIT;

# ----------------------------------------------------- #
# --- Check                                         --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
SELECT count(*) FROM t1;

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
disconnect conn1;
DROP DATABASE db64;
SET GLOBAL falcon_consistent_read = @previous_falcon_consistent_read;
USE test;
