Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Feature Support - Transaction Control Commands #1125

Open
nocaway opened this issue Apr 4, 2019 · 17 comments
Open

[YSQL] Feature Support - Transaction Control Commands #1125

nocaway opened this issue Apr 4, 2019 · 17 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue roadmap-tracking-issue This issue tracks a major roadmap item, and usually appears in the roadmap list.

Comments

@nocaway
Copy link
Contributor

nocaway commented Apr 4, 2019

Jira Link: DB-1016
The following transaction control commands are not yet supported.

  • PREPARE
  • COMMIT PREPARED
  • ROLLBACK PREPARED
  • DEFERRABLE transaction

As well as savepoint related commands: #9219

@nocaway nocaway added kind/enhancement This is an enhancement of an existing feature area/ysql Yugabyte SQL (YSQL) labels Apr 4, 2019
@jaki
Copy link
Contributor

jaki commented Aug 28, 2019

DEFERRABLE is covered in issue #2161.

@andrew-s
Copy link

andrew-s commented Oct 3, 2019

I'd like to see this, my particular use case is for automated migrations.

@danports
Copy link

danports commented Jun 7, 2020

Would be nice to have this for pgloader, which uses SAVEPOINT:

Database error 0A000: SAVEPOINT <transaction> not supported yet
>        HINT: See https://github.com/YugaByte/yugabyte-db/issues/1125. Click '+' on the description to raise its priority
>        QUERY: savepoint pgloader;

@nocaway nocaway assigned m-iancu and ndeodhar and unassigned mbautin and nocaway Jun 8, 2020
@ddorian
Copy link
Contributor

ddorian commented Jul 10, 2020

SAVEPOINT is also used in Elixir ecto_sql for database migrations. Mentioned in slack.

@Amandeepsinghghai
Copy link

package yb

import (
	"context"
	"database/sql"

	"github.com/lib/pq"
)

// https://github.com/lib/pq/blob/master/error.go#L237
const serializationFailureErrorCode string = "40001"

// ExecuteTx runs fn inside a transaction and retries it as needed.
// On non-retryable failures, the transaction is aborted and rolled back;
// On success, the transaction is committed.
func ExecuteTx(ctx context.Context, db *sql.DB, fn func(tx *sql.Tx) error) (e error) {
	tx, err := db.BeginTx(ctx, nil)
	if err != nil {
		return err
	}

	defer func() {
		if err == nil {
			_ = tx.Commit()
		} else {
			_ = tx.Rollback()
		}
	}()

	for {
		err = fn(tx)
		if err == nil || !isErrRetryable(err) {
			return err
		}

		// Use SAVEPOINT AND RELEASE SAVEPOINT when https://github.com/YugaByte/yugabyte-db/issues/1125 is resolved
		err = tx.Rollback()
		if err != nil {
			return err
		}
	}
}

// An error has a proximate cause if it's type is compatible with Go's errors.Unwrap()
// and if possible, return the original cause of the error.
func errorCause(err error) error {
	for err != nil {
		if c, ok := err.(interface{ Unwrap() error }); ok {
			err = c.Unwrap()
		} else {
			break
		}
	}

	return err
}

func isErrRetryable(err error) bool {
	switch e := errorCause(err).(type) {
	case *pq.Error:
		return string(e.Code) == serializationFailureErrorCode
	default:
		return false
	}
}

This is the golang code I ended up writing for transactions. Since SAVEPOINT is not yet there in YB, I have to retry the transaction from scratch(if it is a retryable error) instead of a SAVEPOINT.

@marcusbooyah
Copy link

SAVEPOINT is also used by Harbor

@davidkellis
Copy link

+1'ed due to the Sequel (http://sequel.jeremyevans.net/) library's use of savepoints

@venkatramanm
Copy link

+1'ed SavePoint is crucial for my application.

@skcc321
Copy link

skcc321 commented Oct 14, 2020

+1 SAVEPOINT is widely used in RoR test suites as transactional_fixtures or database_cleaner.strategy :transaction. So right now I have no confidence in Yugabyte compatibility with my legacy application (postgresql). As a workaround I can use strategy :deletion but that slows test suites execution time.

@rkarthik007 rkarthik007 added the roadmap-tracking-issue This issue tracks a major roadmap item, and usually appears in the roadmap list. label Oct 14, 2020
@cyucelen
Copy link

cyucelen commented Nov 5, 2020

I also need this to use txdb for my tests.

@dzirg44
Copy link

dzirg44 commented Nov 5, 2020

https://mikro-orm.io/ migrations

@filipeaguiars
Copy link

+1'ed SavePoint is crucial for my application.

05-11:53:23.642 | main | INFO | Created new number range with id 1 for seqName NumberRangeAssignment - (AbstractNumberRange.java:480)
Error: org.postgresql.util.PSQLException: ERROR: SAVEPOINT not supported yet
Hint: See #1125. Click '+' on the description to raise its priority
Position: 1
java.lang.IllegalStateException: org.postgresql.util.PSQLException: ERROR: SAVEPOINT not supported yet
Hint: See #1125. Click '+' on the description to raise its priority
Position: 1

@trfi
Copy link

trfi commented Apr 19, 2021

I using Postgraphile and when I add data to yugabyte database see error: ROLLBACK <transaction> not supported yet

@ddorian
Copy link
Contributor

ddorian commented Apr 19, 2021

@trfi please check the logs of Postgraphile or increase the verbosity of debug log to get more info regarding the error.

@jannh
Copy link

jannh commented May 16, 2021

SAVEPOINT would also be very helpful for migrations and unittests in Django

@kulminaator
Copy link

This blocks people from using amazon's database migration tool properly to replicate from postgresql to yugabytedb

@kmuthukk
Copy link
Collaborator

@kulminaator -- which specific statement or statements are you referring to? Please note - we recently added support for savepoints and rollback to savepoints.

CC: @robertsami

@SteveXiSong SteveXiSong self-assigned this Jan 19, 2022
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Jun 8, 2022
mdbridge added a commit that referenced this issue Mar 15, 2023
Summary:
Undeprecate --enable_pg_savepoint flag to implement JIRA issue
https://yugabyte.atlassian.net/browse/DB-5396.  This flag was
originally deprecated in https://phabricator.dev.yugabyte.com/D13260

Note that the error message the user will see is:
```
Bad status: Network error (yb/yql/pgwrapper/libpq_utils.cc:329): Execute of 'SAVEPOINT A' failed: 7, message: ERROR:  SAVEPOINT <transaction> not supported yet
LINE 1: SAVEPOINT A
        ^
HINT:  See #1125. React with thumbs up to raise its priority (pgsql error 0A000) (aux msg ERROR:  SAVEPOINT <transaction> not supported yet
```

Test Plan:
Added a test to verify that setting this flag to false causes SAVEPOINT
to produce an error.
```
yb_build.sh --sj  --cxx-test pgwrapper_pg_mini-test --gtest_filter '*TestSavePointCanBeDisabled*'
```

Reviewers: hsunder, jhe, slingam

Reviewed By: slingam

Differential Revision: https://phabricator.dev.yugabyte.com/D23455
mdbridge added a commit that referenced this issue Apr 5, 2023
…pted when disabled by --enable_pg_savepoint

Summary:
When this flag is set to false, use of SAVEPOINT related features in SQL
produces an error like:
```
2023-03-15 23:47:51.117 UTC [722541] ERROR:  SAVEPOINT <transaction> not supported yet at character 1
2023-03-15 23:47:51.117 UTC [722541] HINT:  See #1125. React with thumbs up to raise its priority
```

This is misleading because it implies the entire feature is not yet
supported whereas it's just unsupported because of gflag setting.

Also, the issue pointed to above (1125) --
#1125 -- seems to be out
of date because it claims that many implemented features are still
unimplemented.

This diff changes the error message to:
```
2023-03-15 23:32:20.676 UTC [680415] ERROR:  SAVEPOINT <transaction> not supported due to setting of flag --enable_pg_savepoints at character 1
```

3/29/2023 UPDATE:
error message is now:
```
ERROR:  SAVEPOINT <transaction> not supported due to setting of flag --enable_pg_savepoints
LINE 1: SAVEPOINT A
        ^
HINT:  flag may have set to false because savepoints do not currently work with xCluster replication (see #14308)
```

Fixes #16374

Test Plan:
```
yb_build.sh --sj  --cxx-test pgwrapper_pg_mini-test --gtest_filter
'*TestSavePointCanBeDisabled*'
```
Look at error message in test log.

3/29/2023 UPDATE:
replace that test with one that checks the error message:
```
yb_build.sh --java-test org.yb.pgsql.TestPgSavepoints
```

Reviewers: slingam, jhe, rsami, hsunder

Reviewed By: hsunder

Subscribers: ybase, rsami

Differential Revision: https://phabricator.dev.yugabyte.com/D23625
premkumr pushed a commit to premkumr/yugabyte-db that referenced this issue Apr 10, 2023
…is attempted when disabled by --enable_pg_savepoint

Summary:
When this flag is set to false, use of SAVEPOINT related features in SQL
produces an error like:
```
2023-03-15 23:47:51.117 UTC [722541] ERROR:  SAVEPOINT <transaction> not supported yet at character 1
2023-03-15 23:47:51.117 UTC [722541] HINT:  See yugabyte#1125. React with thumbs up to raise its priority
```

This is misleading because it implies the entire feature is not yet
supported whereas it's just unsupported because of gflag setting.

Also, the issue pointed to above (1125) --
yugabyte#1125 -- seems to be out
of date because it claims that many implemented features are still
unimplemented.

This diff changes the error message to:
```
2023-03-15 23:32:20.676 UTC [680415] ERROR:  SAVEPOINT <transaction> not supported due to setting of flag --enable_pg_savepoints at character 1
```

3/29/2023 UPDATE:
error message is now:
```
ERROR:  SAVEPOINT <transaction> not supported due to setting of flag --enable_pg_savepoints
LINE 1: SAVEPOINT A
        ^
HINT:  flag may have set to false because savepoints do not currently work with xCluster replication (see yugabyte#14308)
```

Fixes yugabyte#16374

Test Plan:
```
yb_build.sh --sj  --cxx-test pgwrapper_pg_mini-test --gtest_filter
'*TestSavePointCanBeDisabled*'
```
Look at error message in test log.

3/29/2023 UPDATE:
replace that test with one that checks the error message:
```
yb_build.sh --java-test org.yb.pgsql.TestPgSavepoints
```

Reviewers: slingam, jhe, rsami, hsunder

Reviewed By: hsunder

Subscribers: ybase, rsami

Differential Revision: https://phabricator.dev.yugabyte.com/D23625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue roadmap-tracking-issue This issue tracks a major roadmap item, and usually appears in the roadmap list.
Projects
Status: No status
Development

No branches or pull requests