-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: apply PCR AOST time stamp for authentication flow #135929
Open
fqazi
wants to merge
1
commit into
cockroachdb:master
Choose a base branch
from
fqazi:authCheckTS
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−78
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import ( | |
"github.com/cockroachdb/cockroach/pkg/util/randutil" | ||
"github.com/cockroachdb/cockroach/pkg/util/timeutil" | ||
"github.com/cockroachdb/errors" | ||
"github.com/jackc/pgx/v4" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
|
@@ -270,6 +271,8 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
srcRunner := sqlutils.MakeSQLRunner(srcConn) | ||
|
||
ddlToExec := []string{ | ||
"CREATE USER bob password 'bob'", | ||
"GRANT ADMIN TO bob;", | ||
"CREATE SEQUENCE sq1;", | ||
"CREATE TYPE IF NOT EXISTS status AS ENUM ('open', 'closed', 'inactive');", | ||
"CREATE TABLE t1(j int default nextval('sq1'), val status);", | ||
|
@@ -297,6 +300,9 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
// Connect only after the reader catalog is setup, so the connection | ||
// executor is aware. | ||
destConn := destTenant.SQLConn(t) | ||
destURL, destURLCleanup := destTenant.PGUrl(t, serverutils.UserPassword("bob", "bob"), serverutils.ClientCerts(false)) | ||
defer destURLCleanup() | ||
require.NoError(t, err) | ||
destRunner := sqlutils.MakeSQLRunner(destConn) | ||
|
||
check := func(query string, isEqual bool) { | ||
|
@@ -322,6 +328,16 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
} else { | ||
require.NotEqualValues(t, srcRes, destRes) | ||
} | ||
|
||
// Sanity: Execute the same query as prepared statement inside the reader | ||
// catalog . | ||
destPgxConn, err := pgx.Connect(ctx, destURL.String()) | ||
_, err = destPgxConn.Prepare(ctx, query, query) | ||
require.NoError(t, err) | ||
rows, err := destPgxConn.Query(ctx, query) | ||
require.NoError(t, err) | ||
defer rows.Close() | ||
require.NoError(t, destPgxConn.Close(ctx)) | ||
} | ||
|
||
compareEqual := func(query string) { | ||
|
@@ -333,6 +349,10 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
|
||
var newTS hlc.Timestamp | ||
descriptorRefreshHookEnabled.Store(true) | ||
existingPgxConn, err := pgx.Connect(ctx, destURL.String()) | ||
require.NoError(t, err) | ||
_, err = existingPgxConn.Prepare(ctx, "basic select", "SELECT * FROM t1, v1, t2") | ||
require.NoError(t, err) | ||
for _, useAOST := range []bool{false, true} { | ||
if useAOST { | ||
closeWaitForRefresh() | ||
|
@@ -385,7 +405,9 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
destRunner.Exec(t, "SET bypass_pcr_reader_catalog_aost='on'") | ||
} | ||
iterationsDone := false | ||
uniqueIdx := 0 | ||
for !iterationsDone { | ||
uniqueIdx++ | ||
if !useAOST { | ||
select { | ||
case waitForRefresh <- struct{}{}: | ||
|
@@ -397,8 +419,27 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
case <-iterationsDoneCh: | ||
iterationsDone = true | ||
default: | ||
// Prepare on an existing connection. | ||
rows, err := existingPgxConn.Query(ctx, "SELECT * FROM t1, v1, t2") | ||
require.NoError(t, err) | ||
rows.Close() | ||
uniqueQuery := fmt.Sprintf("SELECT a.j + %d FROM t1 as a, v1 as b, t2 as c ", uniqueIdx) | ||
_, err = existingPgxConn.Prepare(ctx, fmt.Sprintf("q%d", uniqueIdx), uniqueQuery) | ||
require.NoError(t, err) | ||
rows, err = existingPgxConn.Query(ctx, uniqueQuery) | ||
require.NoError(t, err) | ||
rows.Close() | ||
// Open new connections. | ||
newPgxConn, err := pgx.Connect(ctx, destURL.String()) | ||
require.NoError(t, err) | ||
_, err = newPgxConn.Prepare(ctx, "basic select", "SELECT * FROM t1, v1, t2") | ||
require.NoError(t, err) | ||
rows, err = newPgxConn.Query(ctx, "SELECT * FROM t1, v1, t2") | ||
require.NoError(t, err) | ||
require.NoError(t, newPgxConn.Close(ctx)) | ||
|
||
tx := destRunner.Begin(t) | ||
_, err := tx.Exec("SELECT * FROM t1") | ||
_, err = tx.Exec("SELECT * FROM t1") | ||
checkAOSTError(err) | ||
_, err = tx.Exec("SELECT * FROM v1") | ||
checkAOSTError(err) | ||
|
@@ -414,13 +455,13 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
checkAOSTError(err) | ||
} | ||
} | ||
|
||
// Finally ensure the queries actually match. | ||
require.NoError(t, grp.Wait()) | ||
// Check if the error was detected. | ||
require.Equalf(t, !useAOST, errorDetected, | ||
"error was detected unexpectedly (AOST = %t on connection)", useAOST) | ||
} | ||
require.NoError(t, existingPgxConn.Close(ctx)) | ||
now = newTS | ||
compareEqual("SELECT * FROM t1 ORDER BY j") | ||
compareEqual("SELECT * FROM v1 ORDER BY 1") | ||
|
@@ -432,7 +473,7 @@ func TestReaderCatalogTSAdvance(t *testing.T) { | |
// with PCR even if a long running txn is running. | ||
func TestReaderCatalogTSAdvanceWithLongTxn(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
skip.UnderDuress(t) | ||
// skip.UnderDuress(t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: intended? |
||
|
||
ctx := context.Background() | ||
ts := serverutils.StartServerOnly(t, base.TestServerArgs{ | ||
|
@@ -459,7 +500,6 @@ func TestReaderCatalogTSAdvanceWithLongTxn(t *testing.T) { | |
|
||
ddlToExec := []string{ | ||
"CREATE USER roacher WITH CREATEROLE;", | ||
"GRANT ADMIN TO roacher;", | ||
"ALTER USER roacher SET timezone='America/New_York';", | ||
"CREATE SEQUENCE sq1;", | ||
"CREATE TABLE t1(n int default nextval('sq1'), val TEXT);", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to confirm, were these unit tests with prepared stmts failing before your patch to the source code?