yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.96k stars 1.07k forks source link

[YSQL] transaction_ vector keeps growing under rapid execution #2858

Open jaki opened 4 years ago

jaki commented 4 years ago

Jira Link: DB-1855 The transaction_ vector in conflict_manager.cc keeps growing in size under a certain circumstance.

Setup:

CREATE TABLE t (i int PRIMARY KEY, j int);
INSERT INTO t VALUES (1, 10), (2, 20), (3, 30);

Session A:

SELECT * FROM t FOR KEY SHARE; COMMIT; INSERT INTO t VALUES (2, 20); BEGIN;

Session B:

DELETE FROM t WHERE i = 2;

Alternate statements from each session quickly. If they are done quickly enough, the error "Conflicts with higher priority transaction" sometimes appears (otherwise, you get "Value write after transaction start"). The more these errors occur, the larger the transaction_ vector gets holding uncommitted transactions. It is not expected for this accumulation to happen. Even after closing both sessions, there is no cleanup.

jaki commented 4 years ago

Here is an easy way to reproduce this:

./bin/ysqlsh -c "CREATE TABLE p (i int PRIMARY KEY); INSERT INTO p VALUES (1), (2), (3);"
./bin/ysqlsh -c "SELECT * FROM p FOR UPDATE;"
for i in $(seq 1 100); do ./bin/ysqlsh -c "BEGIN; SELECT * FROM p FOR UPDATE; COMMIT;" &; done
./bin/ysqlsh -c "SELECT * FROM p FOR SHARE;"

Execute each of the statements with some time apart from each other. The last SELECT should have a lot of aborted transactions in the transaction_ vector, visible by

          VLOG(4) << context_.ToString() << ", aborted: " << transaction.id;