forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: Allow accessing Scylla system tables from alternator
Merged patch series from Piotr Sarna: This series allows reading rows from Scylla's system tables via alternator by using a virtual interface. If a Query or Scan request intercepts a table name with the following pattern: .scylla.alternator.KEYSPACE_NAME.TABLE_NAME, it will read the data from Scylla's KEYSPACE_NAME.TABLE_NAME table. The interface is expected to only return data for Scylla system tables and trying to access regular tables via this interface is expected to return an error. This series comes with tests (alternator-test, scylla_only). Fixes scylladb#6122 Tests: alternator-test(local,remote (to verify that scylla_only works) Piotr Sarna (5): alternator: add fallback serialization for all types alternator: add fetching static columns if they exist alternator: add a way of accessing system tables from alternator alternator-test: add scylla-only test for querying system tables docs: add an entry about accessing Scylla system tables alternator-test/test_system_tables.py | 61 +++++++++++++++++++++++++++ alternator/executor.cc | 38 ++++++++++++++++- alternator/executor.hh | 1 + alternator/serialization.cc | 11 +++-- docs/alternator/alternator.md | 15 +++++++ 5 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 alternator-test/test_system_tables.py
- Loading branch information
Showing
5 changed files
with
122 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# 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) | ||
response = client.scan(TableName=qualified_name, AttributesToGet=key_columns) | ||
print(ks_name, table_name, response) | ||
|
||
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'}] | ||
) | ||
|