You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/07/19 08:39:18 UTC
[GitHub] [shardingsphere] azexcy opened a new pull request, #19356: Add postgresql data source check at scaling
azexcy opened a new pull request, #19356:
URL: https://github.com/apache/shardingsphere/pull/19356
Fixes #ISSUSE_ID.
Changes proposed in this pull request:
- Add check
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
sandynz commented on code in PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#discussion_r925207489
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,57 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
+
@Override
public void checkPrivilege(final Collection<? extends DataSource> dataSources) {
+ for (DataSource each : dataSources) {
+ checkPrivilege(each);
+ }
+ }
+
+ private void checkPrivilege(final DataSource dataSource) {
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(SHOW_GRANTS_SQL)) {
+ DatabaseMetaData metaData = connection.getMetaData();
+ preparedStatement.setString(1, metaData.getUserName());
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ if (!resultSet.next()) {
+ throw new PipelineJobPrepareFailedException(String.format("No role exists, rolname: %s.", metaData.getUserName()));
+ }
+ String isSuperRole = resultSet.getString(SUPER_ROLE_NAME);
+ String isReplicationRole = resultSet.getString(REPLICATION_ROLE_NAME);
+ log.info("checkPrivilege: isSuperRole: {}, isReplicationRole: {}", isSuperRole, isReplicationRole);
+ if (StringUtils.equalsIgnoreCase(isSuperRole, "f") && StringUtils.equalsIgnoreCase(isReplicationRole, "f")) {
+ throw new PipelineJobPrepareFailedException(String.format("Source data source is lack of REPLICATION privileges, sql example is `ALTER ROLE \"%s\" REPLICATION;`.",
+ metaData.getUserName()));
Review Comment:
`sql example is` could be `you could try`
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,57 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
Review Comment:
Could we just inline these string? It's short enough and just used one time.
Or could we change it to xxx_COLUMN_NAME? It's not ROLE NAME.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
sandynz commented on code in PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#discussion_r925141188
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,55 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
+
@Override
public void checkPrivilege(final Collection<? extends DataSource> dataSources) {
+ for (DataSource each : dataSources) {
+ checkPrivilege(each);
+ }
+ }
+
+ private void checkPrivilege(final DataSource dataSource) {
+ try (Connection connection = dataSource.getConnection()) {
+ DatabaseMetaData metaData = connection.getMetaData();
+ PreparedStatement preparedStatement = connection.prepareStatement(SHOW_GRANTS_SQL);
+ preparedStatement.setString(1, metaData.getUserName());
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ resultSet.next();
+ String isSuperRole = resultSet.getString(SUPER_ROLE_NAME);
+ String isReplicationRole = resultSet.getString(REPLICATION_ROLE_NAME);
+ log.info("checkPrivilege: isSuperRole: {}, isReplicationRole: {}", isSuperRole, isReplicationRole);
+ if (StringUtils.equalsIgnoreCase(isSuperRole, "f") && StringUtils.equalsIgnoreCase(isReplicationRole, "f")) {
+ throw new PipelineJobPrepareFailedException("Source data source is lack of REPLICATION privileges.");
+ }
Review Comment:
Is it possible to supply suggestion of how to add REPLICATION privilege?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
sandynz commented on code in PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#discussion_r925114963
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,55 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
+
@Override
public void checkPrivilege(final Collection<? extends DataSource> dataSources) {
+ for (DataSource each : dataSources) {
+ checkPrivilege(each);
+ }
+ }
+
+ private void checkPrivilege(final DataSource dataSource) {
+ try (Connection connection = dataSource.getConnection()) {
+ DatabaseMetaData metaData = connection.getMetaData();
+ PreparedStatement preparedStatement = connection.prepareStatement(SHOW_GRANTS_SQL);
+ preparedStatement.setString(1, metaData.getUserName());
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ resultSet.next();
+ String isSuperRole = resultSet.getString(SUPER_ROLE_NAME);
+ String isReplicationRole = resultSet.getString(REPLICATION_ROLE_NAME);
Review Comment:
If ResultSet of SHOW_GRANTS_SQL has no result, `resultSet.next()` might return false, could we just run `resultSet.getString`?
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,55 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
+
@Override
public void checkPrivilege(final Collection<? extends DataSource> dataSources) {
+ for (DataSource each : dataSources) {
+ checkPrivilege(each);
+ }
+ }
+
+ private void checkPrivilege(final DataSource dataSource) {
+ try (Connection connection = dataSource.getConnection()) {
+ DatabaseMetaData metaData = connection.getMetaData();
+ PreparedStatement preparedStatement = connection.prepareStatement(SHOW_GRANTS_SQL);
Review Comment:
It's better to put `connection.prepareStatement` in try-resource.
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,55 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
+
@Override
public void checkPrivilege(final Collection<? extends DataSource> dataSources) {
+ for (DataSource each : dataSources) {
+ checkPrivilege(each);
+ }
+ }
+
+ private void checkPrivilege(final DataSource dataSource) {
+ try (Connection connection = dataSource.getConnection()) {
+ DatabaseMetaData metaData = connection.getMetaData();
+ PreparedStatement preparedStatement = connection.prepareStatement(SHOW_GRANTS_SQL);
+ preparedStatement.setString(1, metaData.getUserName());
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ resultSet.next();
+ String isSuperRole = resultSet.getString(SUPER_ROLE_NAME);
+ String isReplicationRole = resultSet.getString(REPLICATION_ROLE_NAME);
+ log.info("checkPrivilege: isSuperRole: {}, isReplicationRole: {}", isSuperRole, isReplicationRole);
+ if (StringUtils.equalsIgnoreCase(isSuperRole, "f") && StringUtils.equalsIgnoreCase(isReplicationRole, "f")) {
+ throw new PipelineJobPrepareFailedException("Source data source is lack of REPLICATION privileges.");
+ }
Review Comment:
Could we not limit role to super role?
If user create a role and grant replication privilege, it should work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
sandynz commented on PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#issuecomment-1189759861
Refer to https://www.postgresql.org/docs/current/sql-createuser.html
> CREATE USER is now an alias for [CREATE ROLE](https://www.postgresql.org/docs/current/sql-createrole.html). The only difference is that when the command is spelled CREATE USER, LOGIN is assumed by default, whereas NOLOGIN is assumed when the command is spelled CREATE ROLE.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz merged pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
sandynz merged PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
azexcy commented on PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#issuecomment-1189778212
Refer to https://www.postgresql.org/docs/current/sql-createrole.html
> The INHERIT attribute governs inheritance of grantable privileges (that is, access privileges for database objects and role memberships). It does not apply to the special role attributes set by CREATE ROLE and ALTER ROLE. For example, being a member of a role with CREATEDB privilege does not immediately grant the ability to create databases, even if INHERIT is set; it would be necessary to become that role via [SET ROLE](https://www.postgresql.org/docs/current/sql-set-role.html) before creating a database.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
azexcy commented on PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#issuecomment-1188953504
Checks only if user is super role or have replication privilege, no check create table or schema, because create table or schema privilege verified before
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] codecov-commenter commented on pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#issuecomment-1189738566
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/19356?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#19356](https://codecov.io/gh/apache/shardingsphere/pull/19356?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (46d786b) into [master](https://codecov.io/gh/apache/shardingsphere/commit/121f1c0e2eb2610f396a3058809d5edc332a9ad7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (121f1c0) will **decrease** coverage by `0.01%`.
> The diff coverage is `13.63%`.
```diff
@@ Coverage Diff @@
## master #19356 +/- ##
============================================
- Coverage 59.62% 59.61% -0.02%
- Complexity 2371 2373 +2
============================================
Files 3817 3818 +1
Lines 54366 54387 +21
Branches 9256 7632 -1624
============================================
+ Hits 32415 32421 +6
+ Misses 19187 19165 -22
- Partials 2764 2801 +37
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/19356?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...acle/ddl/OracleAlterMaterializedViewStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9zdGF0ZW1lbnQvb3JhY2xlL2RkbC9PcmFjbGVBbHRlck1hdGVyaWFsaXplZFZpZXdTdGF0ZW1lbnQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [.../check/datasource/PostgreSQLDataSourceChecker.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLWRhdGEtcGlwZWxpbmUvc2hhcmRpbmdzcGhlcmUtZGF0YS1waXBlbGluZS1kaWFsZWN0L3NoYXJkaW5nc3BoZXJlLWRhdGEtcGlwZWxpbmUtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGF0YS9waXBlbGluZS9wb3N0Z3Jlc3FsL2NoZWNrL2RhdGFzb3VyY2UvUG9zdGdyZVNRTERhdGFTb3VyY2VDaGVja2VyLmphdmE=) | `16.66% <10.00%> (-58.34%)` | :arrow_down: |
| [...r/statement/impl/OracleDDLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1vcmFjbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvb3JhY2xlL3Zpc2l0b3Ivc3RhdGVtZW50L2ltcGwvT3JhY2xlRERMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `88.17% <100.00%> (+0.04%)` | :arrow_up: |
| [...tsql/rdl/resource/AlterResourceBackendHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmRsL3Jlc291cmNlL0FsdGVyUmVzb3VyY2VCYWNrZW5kSGFuZGxlci5qYXZh) | `81.25% <0.00%> (-7.39%)` | :arrow_down: |
| [...ndler/converter/EncryptRuleStatementConverter.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWRpc3RzcWwvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC1kaXN0c3FsLWhhbmRsZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvZGlzdHNxbC9oYW5kbGVyL2NvbnZlcnRlci9FbmNyeXB0UnVsZVN0YXRlbWVudENvbnZlcnRlci5qYXZh) | `88.88% <0.00%> (-7.12%)` | :arrow_down: |
| [...ized/asserts/segment/distsql/DataSourceAssert.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtdGVzdC9zaGFyZGluZ3NwaGVyZS1wYXJzZXItdGVzdC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvdGVzdC9zcWwvcGFyc2VyL3BhcmFtZXRlcml6ZWQvYXNzZXJ0cy9zZWdtZW50L2Rpc3RzcWwvRGF0YVNvdXJjZUFzc2VydC5qYXZh) | `88.23% <0.00%> (-1.24%)` | :arrow_down: |
| [...stsql/handler/query/EncryptRuleQueryResultSet.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWRpc3RzcWwvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC1kaXN0c3FsLWhhbmRsZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvZGlzdHNxbC9oYW5kbGVyL3F1ZXJ5L0VuY3J5cHRSdWxlUXVlcnlSZXN1bHRTZXQuamF2YQ==) | `78.26% <0.00%> (-0.91%)` | :arrow_down: |
| [...ingsphere/agent/core/plugin/AgentPluginLoader.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtYWdlbnQvc2hhcmRpbmdzcGhlcmUtYWdlbnQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvYWdlbnQvY29yZS9wbHVnaW4vQWdlbnRQbHVnaW5Mb2FkZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...backend/text/transaction/TransactionXAHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L3RyYW5zYWN0aW9uL1RyYW5zYWN0aW9uWEFIYW5kbGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| ... and [23 more](https://codecov.io/gh/apache/shardingsphere/pull/19356/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #19356: Add postgresql data source check at scaling
Posted by GitBox <gi...@apache.org>.
sandynz commented on code in PR #19356:
URL: https://github.com/apache/shardingsphere/pull/19356#discussion_r925122171
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java:
##########
@@ -17,18 +17,55 @@
package org.apache.shardingsphere.data.pipeline.postgresql.check.datasource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
/**
* PostgreSQL Data source checker.
*/
+@Slf4j
public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
+ private static final String SHOW_GRANTS_SQL = "SELECT * FROM pg_roles WHERE rolname = ?";
+
+ private static final String SUPER_ROLE_NAME = "rolsuper";
+
+ private static final String REPLICATION_ROLE_NAME = "rolreplication";
+
@Override
public void checkPrivilege(final Collection<? extends DataSource> dataSources) {
+ for (DataSource each : dataSources) {
+ checkPrivilege(each);
+ }
+ }
+
+ private void checkPrivilege(final DataSource dataSource) {
+ try (Connection connection = dataSource.getConnection()) {
+ DatabaseMetaData metaData = connection.getMetaData();
+ PreparedStatement preparedStatement = connection.prepareStatement(SHOW_GRANTS_SQL);
+ preparedStatement.setString(1, metaData.getUserName());
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ resultSet.next();
+ String isSuperRole = resultSet.getString(SUPER_ROLE_NAME);
+ String isReplicationRole = resultSet.getString(REPLICATION_ROLE_NAME);
+ log.info("checkPrivilege: isSuperRole: {}, isReplicationRole: {}", isSuperRole, isReplicationRole);
+ if (StringUtils.equalsIgnoreCase(isSuperRole, "f") && StringUtils.equalsIgnoreCase(isReplicationRole, "f")) {
+ throw new PipelineJobPrepareFailedException("Source data source is lack of REPLICATION privileges.");
+ }
Review Comment:
By mistake, `SELECT * FROM pg_roles WHERE rolname = ?` 's parameter is current login user.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org