mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-27 20:05:10 +00:00
The test test_fetch_from_system_tables tests Alternator's system-table feature by reading from all system tables. The intention was to confirm we don't crash reading any of them - as they have different schemas and can run into different problems (we had such problems in the initial implementation). The intention was not to read *a lot* from each table - we only make a single "Scan" call on each, to read one page of data. However, the Scan call did not set a Limit, so the single page can get pretty big. This is not normally a problem, but in extremely slow runs - such as when running the debug build on an extremely overcommitted test machine (e.g., issue #7706) reading this large page may take longer than our default timeout. I'll send a separate patch for the timeout issue, but for now, there is really no reason why we need to read a big page. It is good enough to just read 50 rows (with Limit=50). This will still read all the different types and make the test faster. As an example, in the debug run on my laptop, this test spent 2.4 seconds to read the "compaction_history" table before this patch, and only 0.1 seconds after this patch. 2.4 seconds is close to our default timeout (10 seconds), 0.1 is very far. Fixes #7706 Signed-off-by: Nadav Har'El <nyh@scylladb.com> Message-Id: <20201207075112.2548178-1-nyh@scylladb.com>
64 lines
2.9 KiB
Python
64 lines
2.9 KiB
Python
# Copyright 2020 ScyllaDB
|
|
#
|
|
# This file is part of Scylla.
|
|
#
|
|
# Scylla is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Scylla is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Tests for accessing alternator-only system tables (from Scylla).
|
|
|
|
import pytest
|
|
from botocore.exceptions import ClientError
|
|
from boto3.dynamodb.conditions import Key
|
|
|
|
internal_prefix = '.scylla.alternator.'
|
|
|
|
# Test that fetching key columns from system tables works
|
|
def test_fetch_from_system_tables(scylla_only, dynamodb):
|
|
client = dynamodb.meta.client
|
|
tables_response = client.scan(TableName=internal_prefix+'system_schema.tables',
|
|
AttributesToGet=['keyspace_name','table_name'])
|
|
|
|
for item in tables_response['Items']:
|
|
ks_name = item['keyspace_name']
|
|
table_name = item['table_name']
|
|
|
|
if not 'system' in ks_name:
|
|
continue
|
|
|
|
col_response = client.query(TableName=internal_prefix+'system_schema.columns',
|
|
KeyConditionExpression=Key('keyspace_name').eq(ks_name) & Key('table_name').eq(table_name))
|
|
|
|
key_columns = [item['column_name'] for item in col_response['Items'] if item['kind'] == 'clustering' or item['kind'] == 'partition_key']
|
|
qualified_name = "{}{}.{}".format(internal_prefix, ks_name, table_name)
|
|
import time
|
|
start = time.time()
|
|
response = client.scan(TableName=qualified_name, AttributesToGet=key_columns, Limit=50)
|
|
print(ks_name, table_name, len(str(response)), time.time()-start)
|
|
|
|
def test_block_access_to_non_system_tables_with_virtual_interface(scylla_only, test_table_s, dynamodb):
|
|
client = dynamodb.meta.client
|
|
with pytest.raises(ClientError, match='ResourceNotFoundException.*{}'.format(internal_prefix)):
|
|
tables_response = client.scan(TableName="{}alternator_{}.{}".format(internal_prefix, test_table_s.name, test_table_s.name))
|
|
|
|
def test_block_creating_tables_with_reserved_prefix(scylla_only, dynamodb):
|
|
client = dynamodb.meta.client
|
|
for wrong_name_postfix in ['', 'a', 'xxx', 'system_auth.roles', 'table_name']:
|
|
with pytest.raises(ClientError, match=internal_prefix):
|
|
dynamodb.create_table(TableName=internal_prefix+wrong_name_postfix,
|
|
BillingMode='PAY_PER_REQUEST',
|
|
KeySchema=[{'AttributeName':'p', 'KeyType':'HASH'}],
|
|
AttributeDefinitions=[{'AttributeName':'p', 'AttributeType': 'S'}]
|
|
)
|
|
|