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

opt: enforce_home_region seems to not work for RBT with locality other than primary region #88788

Closed
yuzefovich opened this issue Sep 27, 2022 · 0 comments · Fixed by #90107
Closed
Assignees
Labels
O-qa T-sql-queries SQL Queries Team

Comments

@yuzefovich
Copy link
Member

yuzefovich commented Sep 27, 2022

Consider the following logic test:

# tenant-cluster-setting-override-opt: allow-multi-region-abstractions-for-secondary-tenants
# LogicTest: multiregion-9node-3region-3azs !metamorphic-batch-sizes

# Set the closed timestamp interval to be short to shorten the amount of time
# we need to wait for the system config to propagate.
statement ok
SET CLUSTER SETTING kv.closed_timestamp.side_transport_interval = '10ms';

statement ok
SET CLUSTER SETTING kv.closed_timestamp.target_duration = '10ms';

# Start with SURVIVE ZONE FAILURE for positive tests.
# SURVIVE REGION FAILURE cases will always error out.
statement ok
CREATE DATABASE multi_region_test_db PRIMARY REGION "ca-central-1" REGIONS "ap-southeast-2", "us-east-1" SURVIVE ZONE FAILURE;

# Zone configs sometimes are not available right away. Add a sleep time to the
# test to ensure they're available before running tests.
sleep 2s

statement ok
USE multi_region_test_db

query T
SELECT gateway_region();
----
ap-southeast-2

statement ok
CREATE TABLE messages_rbt (
    account_id INT NOT NULL,
    message_id   UUID DEFAULT gen_random_uuid(),
    message    STRING NOT NULL,
    PRIMARY KEY (account_id),
    INDEX msg_idx(message)
) LOCALITY REGIONAL BY TABLE IN "us-east-1"

statement ok
CREATE TABLE messages_rbr (
    account_id INT NOT NULL,
    message_id   UUID DEFAULT gen_random_uuid(),
    message    STRING NOT NULL,
    crdb_region crdb_internal_region NOT NULL,
    PRIMARY KEY (account_id),
    INDEX msg_idx(message)
)
LOCALITY REGIONAL BY ROW

statement ok
SET enforce_home_region = true

# Locality optimized lookup join is allowed.
query TTTTTTT retry
SELECT * FROM messages_rbr rbr, messages_rbt rbt WHERE rbr.account_id = rbt.account_id LIMIT 1
----

query T retry
EXPLAIN SELECT * FROM messages_rbr rbr, messages_rbt rbt WHERE rbr.account_id = rbt.account_id LIMIT 1
----
distribution: local
vectorized: true
·
• limit
│ count: 1
│
└── • lookup join
    │ table: messages_rbr@messages_rbr_pkey
    │ equality cols are key
    │ lookup condition: (crdb_region = 'ap-southeast-2') AND (account_id = account_id)
    │ remote lookup condition: (crdb_region IN ('ca-central-1', 'us-east-1')) AND (account_id = account_id)
    │
    └── • scan
          missing stats
          table: messages_rbt@messages_rbt_pkey
          spans: FULL SCAN (SOFT LIMIT)

statement ok
RESET enforce_home_region

IIUC the queries with the locality optimized lookup join should not be allowed because they contain a full scan of a RBT table for which the primary region ("us-east-1") is different from the primary region of the database ("ca-central-1") and is also different from the gateway region for the query ("ap-southeast-2").

I could definitely be wrong about the expectations in this case though.

Jira issue: CRDB-20012

@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Sep 27, 2022
msirek pushed a commit to msirek/cockroach that referenced this issue Oct 17, 2022
Fixes cockroachdb#88788

This fixes erroring out of locality-optimized join when the input
table's home region does not match the gateway region and session flag
`enforce_home_region` is true.

Release note (bug fix): This patch fixes detection and erroring out of
queries using locality-optimized join when session setting
enforce_home_region is true and the input table to the join has no home
region or its home region does not match the gateway region.
msirek pushed a commit to msirek/cockroach that referenced this issue Oct 18, 2022
Fixes cockroachdb#88788

This fixes erroring out of locality-optimized join when the input
table's home region does not match the gateway region and session flag
`enforce_home_region` is true.

Release note (bug fix): This patch fixes detection and erroring out of
queries using locality-optimized join when session setting
enforce_home_region is true and the input table to the join has no home
region or its home region does not match the gateway region.
craig bot pushed a commit that referenced this issue Oct 18, 2022
90007: execbuilder: enforce_home_region should only apply to DML r=rytaft a=msirek

Fixes #89875
Fixes #88789

This fixes a problem where the enforce_home_region session flag might
cause non-DML statements to error out, such as SHOW CREATE, if those
statements utilize scans or joins of multiregion tables.

This also fixes issues with proper erroring out of mutation DML like
UPDATE AND DELETE. For example, the following previously did not error:
```
CREATE TABLE messages_rbr (
    account_id INT NOT NULL,
    message_id   UUID DEFAULT gen_random_uuid(),
    message    STRING NOT NULL,
    PRIMARY KEY (account_id),
    INDEX msg_idx(message)
)
LOCALITY REGIONAL BY ROW;

SET enforce_home_region = true;

DELETE FROM messages_rbr WHERE message = 'Hello World!'
ERROR: Query has no home region. Try adding a filter on messages_rbr.crdb_region and/or on key column (messages_rbr.account_id).
SQLSTATE: XCHR2
```

Release note (bug fix): This patch fixes an issue with the
enforce_home_region session setting which may cause SHOW CREATE TABLE or
other non-DML statements to error out if the optimizer plan for the
statement involves accessing a multiregion table.


90106: kv: reacquire proscribed leases on drain, then transfer r=shralex a=nvanbenschoten

Fixes #83372.
Fixes #90022.
Fixes #89963.
Fixes #89962.

This commit instructs stores to reacquire proscribed leases when draining in order to subsequently transfer them away. This addresses a source of flakiness in `transfer-lease` roachtests where some lease would not be transferred away before the drain completed. This could result in range unavailable for up to 9 seconds while other replicas waited out the lease'S expiration. This is because only the previous leaseholder knows that a proscribed lease is invalid. All other replicas still consider the lease to be valid.

This failure mode was always present if a lease transfer failed during a drain. However, it became more likely with 034611b. With that change, we began rejecting lease transfers that were deemed to be "unsafe" more frequently. 034611b introduced a best-effort, graceful version of this check and an airtight, ungraceful version of the check. The former performs the check before revoking the outgoing leaseholder's lease while the latter performs the check after revoking the outgoing leaseholder's lease. In rare cases, it was possible to hit the airtight, ungraceful check and cause the lease to be proscribed. See #83261 (comment) for more details on how this led to test flakiness in the `transfer-lease` roachtest suite.

Release notes: None.

Release justification: Avoids GA-blocking roachtest failures.

90107: execbuilder: fix enforce_home_region erroring of input table to LOJ r=rytaft a=msirek

Fixes #88788

This fixes erroring out of locality-optimized join when the input table's home region does not match the gateway region and session flag `enforce_home_region` is true.

Release note (bug fix): This patch fixes detection and erroring out of queries using locality-optimized join when session setting enforce_home_region is true and the input table to the join has no home region or its home region does not match the gateway region.

90165: sql,server: increase severity of upgraded-related logging r=ajwerner a=knz

Informs #90148.

This increases the severity from INFO in the following cases:

- in the case when `SET CLUSTER SETTING version` is issued from a SQL client (WARNING in case of failure).
- in the case when the server spontaneously decides to upgrade in the background (ERROR in case of failure).

Release note: None

90166: sql/rowenc: remove leftover log in test r=mgartner a=mgartner

Epic: None
Release note: None

Co-authored-by: Mark Sirek <[email protected]>
Co-authored-by: Nathan VanBenschoten <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Marcus Gartner <[email protected]>
@craig craig bot closed this as completed in #90107 Oct 18, 2022
blathers-crl bot pushed a commit that referenced this issue Oct 18, 2022
Fixes #88788

This fixes erroring out of locality-optimized join when the input
table's home region does not match the gateway region and session flag
`enforce_home_region` is true.

Release note (bug fix): This patch fixes detection and erroring out of
queries using locality-optimized join when session setting
enforce_home_region is true and the input table to the join has no home
region or its home region does not match the gateway region.
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-qa T-sql-queries SQL Queries Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants