Skip to content

Commit 133a3a5

Browse files
mfmarcherafiss
authored andcommitted
fix: add nested transaction support
run_transaction utilizes the special 'cockroach_restart' protocol, as per: https://www.cockroachlabs.com/blog/nested-transactions-in-cockroachdb-20-1/ In order to support nested transactions, the cockroach_restart protocol for nested transactions can be related on versions after v20.1. The motivation for this change was to allow multiple nested transactions to occur over the same engine connection and high level transaction (BEGIN/COMMIT). This allows one nested transaction to perform an INSERT or UPDATE, while subsequent transactions could retrieve that result (before the final COMMIT). This primarily works around conditions in sqlalchemy, where one would like to perform an orm.flush(), but cannot, when utilizing the cockroach run_transaction model. By default the run_transaction defaults to using the cockroach_restart protocol, so no observed behavior is seen to current users. Signed-off-by: Mike Marchetti <[email protected]>
1 parent eb32469 commit 133a3a5

File tree

6 files changed

+812
-42
lines changed

6 files changed

+812
-42
lines changed

cockroach_helper.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
COCKROACHDB=cockroach-v23.1.13.linux-amd64
3+
CROACHDB=~/.cache/$COCKROACHDB/cockroach
4+
5+
quit_cockroachdb() {
6+
OLDPIDNS=$(ps -o pidns -C cockroach | awk 'NR==2 {print $0}')
7+
if [ -n "$OLDPIDNS" ]; then
8+
pkill --ns $$ $OLDPIDNS
9+
fi
10+
return 0
11+
}
12+
13+
[ -n "$HOST" ] || HOST=localhost
14+
mkdir -p $(dirname $CROACHDB)
15+
[[ -f "$CROACHDB" ]] || wget -qO- https://binaries.cockroachdb.com/$COCKROACHDB.tgz | tar xvz --directory ~/.cache
16+
if [ $1 == "start" ]; then
17+
quit_cockroachdb
18+
$CROACHDB start-single-node --background --insecure --store=type=mem,size=10% --log-dir /tmp/ --listen-addr=$HOST:26257 --http-addr=$HOST:26301
19+
#$CROACHDB sql --host=$HOST:26257 --insecure -e "set sql_safe_updates=false; drop database if exists apibuilder; create database if not exists apibuilder; create user if not exists apibuilder; grant all on database apibuilder to apibuilder;"
20+
else
21+
quit_cockroachdb
22+
fi

0 commit comments

Comments
 (0)