From 378e1f74aa2bdbaf094e691540db17288cfc051e Mon Sep 17 00:00:00 2001 From: kssenii Date: Sat, 28 Aug 2021 19:09:35 +0300 Subject: [PATCH] Fix tests --- .../en/engines/database-engines/materialized-postgresql.md | 4 ++-- src/Access/AccessType.h | 3 ++- .../PostgreSQL/DatabaseMaterializedPostgreSQL.cpp | 1 + src/Interpreters/InterpreterAlterQuery.cpp | 2 +- src/Storages/PostgreSQL/PostgreSQLReplicationHandler.cpp | 7 ++++--- tests/queries/0_stateless/01271_show_privileges.reference | 2 ++ 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/en/engines/database-engines/materialized-postgresql.md b/docs/en/engines/database-engines/materialized-postgresql.md index 986396019da..2272246a7c5 100644 --- a/docs/en/engines/database-engines/materialized-postgresql.md +++ b/docs/en/engines/database-engines/materialized-postgresql.md @@ -23,7 +23,7 @@ ENGINE = MaterializedPostgreSQL('host:port', ['database' | database], 'user', 'p - `user` — PostgreSQL user. - `password` — User password. -## Dynamicaly adding new tables to replication +## Dynamically adding new tables to replication ``` sql ATTACH TABLE postgres_database.new_table; @@ -31,7 +31,7 @@ ATTACH TABLE postgres_database.new_table; It will work as well if there is a setting `materialized_postgresql_tables_list`. -## Dynamicaly removing tables from replication +## Dynamically removing tables from replication ``` sql DETACH TABLE postgres_database.table_to_remove; diff --git a/src/Access/AccessType.h b/src/Access/AccessType.h index 57342ee5503..823ecebe12d 100644 --- a/src/Access/AccessType.h +++ b/src/Access/AccessType.h @@ -71,9 +71,10 @@ enum class AccessType M(ALTER_FETCH_PARTITION, "ALTER FETCH PART, FETCH PARTITION", TABLE, ALTER_TABLE) \ M(ALTER_FREEZE_PARTITION, "FREEZE PARTITION, UNFREEZE", TABLE, ALTER_TABLE) \ \ - M(ALTER_DATABASE_SETTINGS, "ALTER DATABASE SETTING, ALTER MODIFY DATABASE SETTING, MODIFY DATABASE SETTING", TABLE, ALTER_TABLE) /* allows to execute ALTER MODIFY SETTING */\ + M(ALTER_DATABASE_SETTINGS, "ALTER DATABASE SETTING, ALTER MODIFY DATABASE SETTING, MODIFY DATABASE SETTING", DATABASE, ALTER_DATABASE) /* allows to execute ALTER MODIFY SETTING */\ \ M(ALTER_TABLE, "", GROUP, ALTER) \ + M(ALTER_DATABASE, "", GROUP, ALTER) \ \ M(ALTER_VIEW_REFRESH, "ALTER LIVE VIEW REFRESH, REFRESH VIEW", VIEW, ALTER_VIEW) \ M(ALTER_VIEW_MODIFY_QUERY, "ALTER TABLE MODIFY QUERY", VIEW, ALTER_VIEW) \ diff --git a/src/Databases/PostgreSQL/DatabaseMaterializedPostgreSQL.cpp b/src/Databases/PostgreSQL/DatabaseMaterializedPostgreSQL.cpp index bcd80fe62e7..6d4ac96e56a 100644 --- a/src/Databases/PostgreSQL/DatabaseMaterializedPostgreSQL.cpp +++ b/src/Databases/PostgreSQL/DatabaseMaterializedPostgreSQL.cpp @@ -34,6 +34,7 @@ namespace ErrorCodes extern const int LOGICAL_ERROR; extern const int QUERY_NOT_ALLOWED; extern const int UNKNOWN_TABLE; + extern const int BAD_ARGUMENTS; } DatabaseMaterializedPostgreSQL::DatabaseMaterializedPostgreSQL( diff --git a/src/Interpreters/InterpreterAlterQuery.cpp b/src/Interpreters/InterpreterAlterQuery.cpp index 0a40275b4bb..9cc4e02c4c4 100644 --- a/src/Interpreters/InterpreterAlterQuery.cpp +++ b/src/Interpreters/InterpreterAlterQuery.cpp @@ -48,7 +48,7 @@ BlockIO InterpreterAlterQuery::execute() else if (alter.alter_object == ASTAlterQuery::AlterObjectType::TABLE || alter.alter_object == ASTAlterQuery::AlterObjectType::LIVE_VIEW) return executeToTable(alter); - throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unknown alter object type"); + throw Exception(ErrorCodes::LOGICAL_ERROR, "Unknown alter object type"); } diff --git a/src/Storages/PostgreSQL/PostgreSQLReplicationHandler.cpp b/src/Storages/PostgreSQL/PostgreSQLReplicationHandler.cpp index 8974ad93149..24fafff4123 100644 --- a/src/Storages/PostgreSQL/PostgreSQLReplicationHandler.cpp +++ b/src/Storages/PostgreSQL/PostgreSQLReplicationHandler.cpp @@ -166,7 +166,8 @@ void PostgreSQLReplicationHandler::startSynchronization(bool throw_on_error) auto * materialized_storage = storage->as (); try { - /// TODO: THIS IS INCORRENT, we might get here if there is no nested, need to check and reload. + /// FIXME: Looks like it is possible we might get here if there is no nested storage or at least nested storage id field might be empty. + /// Caught it somehow when doing something else incorrectly, but do not see any reason how it could happen. /// Try load nested table, set materialized table metadata. nested_storages[table_name] = materialized_storage->prepare(); } @@ -617,7 +618,7 @@ PostgreSQLTableStructurePtr PostgreSQLReplicationHandler::fetchTableStructure( void PostgreSQLReplicationHandler::addTableToReplication(StorageMaterializedPostgreSQL * materialized_storage, const String & postgres_table_name) { /// Note: we have to ensure that replication consumer task is stopped when we reload table, because otherwise - /// it can read wal beyond start lsn position (from which this table is being loaded), which will result in loosing data. + /// it can read wal beyond start lsn position (from which this table is being loaded), which will result in losing data. consumer_task->deactivate(); try { @@ -663,7 +664,7 @@ void PostgreSQLReplicationHandler::addTableToReplication(StorageMaterializedPost throw Exception(ErrorCodes::POSTGRESQL_REPLICATION_INTERNAL_ERROR, "Failed to add table `{}` to replication. Info: {}", postgres_table_name, error_message); } - consumer_task->schedule(); + consumer_task->activateAndSchedule(); } diff --git a/tests/queries/0_stateless/01271_show_privileges.reference b/tests/queries/0_stateless/01271_show_privileges.reference index 46eb3bf9ba8..07f670e9afb 100644 --- a/tests/queries/0_stateless/01271_show_privileges.reference +++ b/tests/queries/0_stateless/01271_show_privileges.reference @@ -35,7 +35,9 @@ ALTER SETTINGS ['ALTER SETTING','ALTER MODIFY SETTING','MODIFY SETTING','RESET S ALTER MOVE PARTITION ['ALTER MOVE PART','MOVE PARTITION','MOVE PART'] TABLE ALTER TABLE ALTER FETCH PARTITION ['ALTER FETCH PART','FETCH PARTITION'] TABLE ALTER TABLE ALTER FREEZE PARTITION ['FREEZE PARTITION','UNFREEZE'] TABLE ALTER TABLE +ALTER DATABASE SETTINGS ['ALTER DATABASE SETTING','ALTER MODIFY DATABASE SETTING','MODIFY DATABASE SETTING'] DATABASE ALTER DATABASE ALTER TABLE [] \N ALTER +ALTER DATABASE [] \N ALTER ALTER VIEW REFRESH ['ALTER LIVE VIEW REFRESH','REFRESH VIEW'] VIEW ALTER VIEW ALTER VIEW MODIFY QUERY ['ALTER TABLE MODIFY QUERY'] VIEW ALTER VIEW ALTER VIEW [] \N ALTER