Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
43047: client,kv: new savepoint API r=andreimatei a=knz

This patch introduces the KV savepoint API as discussed in the
savepoints RFC:

```go
	// CreateSavepoint establishes a savepoint.
	// This method is only valid when called on RootTxns.
	CreateSavepoint(context.Context) (SavepointToken, error)

	// RollbackToSavepoint rolls back to the given savepoint. The
	// savepoint must not have been rolled back or released already.
	// All savepoints "under" the savepoint being rolled back
	// are also rolled back and their token must not be used any more.
	// This method is only valid when called on RootTxns.
	RollbackToSavepoint(context.Context, SavepointToken) error

	// ReleaseSavepoint releases the given savepoint. The savepoint
	// must not have been rolled back or released already.
	// All savepoints "under" the savepoint being released
	// are also released and their token must not be used any more.
	// This method is only valid when called on RootTxns.
	ReleaseSavepoint(context.Context, SavepointToken) error
```

Ths initial implementation does not (yet) enable clients to roll back over errors.

Release note: None

44626: workload/tpch: unskip query 12 r=yuzefovich a=yuzefovich

Previously, query 12 was skipped because the results returned by lib/pq
didn't match the expected output. The issue is that the driver returned
[]byte for decimals whereas we expected a string value and `fmt.Sprint`
was giving us the ASCII codes of the digits instead of printing out the
number. This is fixed by checking whether the returned value is []byte,
and if so, converting it to string directly.

Release note: None

44633: sem/tree: fix LIKE ESCAPE when the pattern contains Unicode symbols r=yuzefovich a=yuzefovich

Previously, we were incorrectly updating the pattern when the current
character was Unicode symbol that had the width of more than a single
byte.

Fixes: #44621.

Release note (bug fix): Previously, running a query with LIKE operator
using custom ESCAPE symbol when the pattern contained Unicode characters
could result in an internal error in CockroachDB, and now this has been
fixed.

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
  • Loading branch information
3 people committed Feb 3, 2020
4 parents 31513b7 + 00e69da + 744078c + f25c845 commit 46372d4
Show file tree
Hide file tree
Showing 13 changed files with 946 additions and 33 deletions.
5 changes: 1 addition & 4 deletions pkg/cmd/roachtest/tpchvec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ func registerTPCHVec(r *testRegistry) {
7: "can cause OOM",
8: "can cause OOM",
9: "can cause OOM",
12: "the query is skipped by tpch workload",
19: "can cause OOM",
}
queriesToSkipByVersionPrefix["v20.1"] = map[int]string{
12: "the query is skipped by tpch workload",
}
queriesToSkipByVersionPrefix["v20.1"] = map[int]string{}

runTPCHVec := func(ctx context.Context, t *test, c *cluster) {
TPCHTables := []string{
Expand Down
15 changes: 15 additions & 0 deletions pkg/internal/client/mock_transactional_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ func (m *MockTransactionalSender) IsSerializablePushAndRefreshNotPossible() bool
return false
}

// CreateSavepoint is part of the client.TxnSender interface.
func (m *MockTransactionalSender) CreateSavepoint(context.Context) (SavepointToken, error) {
panic("unimplemented")
}

// RollbackToSavepoint is part of the client.TxnSender interface.
func (m *MockTransactionalSender) RollbackToSavepoint(context.Context, SavepointToken) error {
panic("unimplemented")
}

// ReleaseSavepoint is part of the client.TxnSender interface.
func (m *MockTransactionalSender) ReleaseSavepoint(context.Context, SavepointToken) error {
panic("unimplemented")
}

// Epoch is part of the TxnSender interface.
func (m *MockTransactionalSender) Epoch() enginepb.TxnEpoch { panic("unimplemented") }

Expand Down
35 changes: 35 additions & 0 deletions pkg/internal/client/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,35 @@ type TxnSender interface {
// TxnStatus exports the txn's status.
TxnStatus() roachpb.TransactionStatus

// CreateSavepoint establishes a savepoint.
// This method is only valid when called on RootTxns.
//
// Committing (or aborting) the transaction causes every open
// savepoint to be released (or, respectively, rolled back)
// implicitly.
CreateSavepoint(context.Context) (SavepointToken, error)

// RollbackToSavepoint rolls back to the given savepoint.
// All savepoints "under" the savepoint being rolled back
// are also rolled back and their token must not be used any more.
// The token of the savepoint being rolled back remains valid
// and can be reused later (e.g. to release or roll back again).
// Aborting the txn implicitly rolls back all savepoints
// that are still open.
//
// This method is only valid when called on RootTxns.
RollbackToSavepoint(context.Context, SavepointToken) error

// ReleaseSavepoint releases the given savepoint.
// The savepoint must not have been rolled back or released already.
// All savepoints "under" the savepoint being released
// are also released and their token must not be used any more.
// Committing the txn implicitly releases all savepoints
// that are still open.
//
// This method is only valid when called on RootTxns.
ReleaseSavepoint(context.Context, SavepointToken) error

// SetFixedTimestamp makes the transaction run in an unusual way, at
// a "fixed timestamp": Timestamp and ReadTimestamp are set to ts,
// there's no clock uncertainty, and the txn's deadline is set to ts
Expand Down Expand Up @@ -274,6 +303,12 @@ const (
SteppingEnabled SteppingMode = true
)

// SavepointToken represents a savepoint.
type SavepointToken interface {
// SavepointToken is a marker interface.
SavepointToken()
}

// TxnStatusOpt represents options for TxnSender.GetMeta().
type TxnStatusOpt int

Expand Down
32 changes: 32 additions & 0 deletions pkg/internal/client/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,35 @@ func (txn *Txn) ConfigureStepping(ctx context.Context, mode SteppingMode) (prevM
defer txn.mu.Unlock()
return txn.mu.sender.ConfigureStepping(ctx, mode)
}

// CreateSavepoint establishes a savepoint.
// This method is only valid when called on RootTxns.
func (txn *Txn) CreateSavepoint(ctx context.Context) (SavepointToken, error) {
txn.mu.Lock()
defer txn.mu.Unlock()
return txn.mu.sender.CreateSavepoint(ctx)
}

// RollbackToSavepoint rolls back to the given savepoint.
// All savepoints "under" the savepoint being rolled back
// are also rolled back and their token must not be used any more.
// The token of the savepoint being rolled back remains valid
// and can be reused later (e.g. to release or roll back again).
//
// This method is only valid when called on RootTxns.
func (txn *Txn) RollbackToSavepoint(ctx context.Context, s SavepointToken) error {
txn.mu.Lock()
defer txn.mu.Unlock()
return txn.mu.sender.RollbackToSavepoint(ctx, s)
}

// ReleaseSavepoint releases the given savepoint. The savepoint
// must not have been rolled back or released already.
// All savepoints "under" the savepoint being released
// are also released and their token must not be used any more.
// This method is only valid when called on RootTxns.
func (txn *Txn) ReleaseSavepoint(ctx context.Context, s SavepointToken) error {
txn.mu.Lock()
defer txn.mu.Unlock()
return txn.mu.sender.ReleaseSavepoint(ctx, s)
}
Loading

0 comments on commit 46372d4

Please sign in to comment.