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 2019/12/20 02:52:29 UTC
[GitHub] [incubator-shardingsphere] tmjGitAccount opened a new issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
tmjGitAccount opened a new issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774
Sharding-Sphere VsersionοΌ4.0.0-RC3
I config 2 datasources in my project ,what i want is to use the hint route Strategy
Here is my properties
`spring:
shardingsphere:
props:
sql:
show: true
sharding:
default-database-strategy:
hint:
algorithm-class-name: a.b.c.OrderShardingAlgorithm
default-data-source-name: ds1
datasource:
names: ds1,ds2
ds1:
type: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: xxx
username: xxx
password: xxx
ds2:
type: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl:xxx
username: xxx
password: xxx
`
Here is the code
`
@Slf4j
@NoArgsConstructor
@Component("orderShardingAlgorithm")
public class OrderShardingAlgorithm implements HintShardingAlgorithm<String> {
@Override
public List<String> doSharding(final Collection<String> availableTargetNames, final HintShardingValue<String> shardingValue) {
return Optional.ofNullable(SessionUtils.getAgency())
.map(value -> availableTargetNames.stream().filter(v -> v.equals(value)).collect(Collectors.toList()))
.filter(value -> !value.isEmpty())
.orElse(new ArrayList<>(availableTargetNames));
}
}
`
But it seems the a.b.c.OrderShardingAlgorithm never take effect,I debug into the RoutingEngineFactory.newInstance() method, it always new a **DefaultDatabaseRoutingEngine** rather than a **DatabaseHintRoutingEngine**, so did I miss some config? Or there is a bug here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] SteNicholas commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568326078
@tmjGitAccount You are right. `DatabaseHintRoutingEngine` isn't used in `RoutingEngineFactory `. @terrymanu Could you please assign this to me for fixing?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount edited a comment on issue
#3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount edited a comment on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568713163
> @tmjGitAccount What's more, `DatabaseHintRoutingEngine` isn't used in any routing case and modules. Therefore, the `DatabaseHintRoutingEngine` is necessary to remove. Where load your algorithm is that `StandardRoutingEngine` calls method `route()` to load user-defined algorithm.
@SteNicholas
Thx for your reply, but there is still something wrong for me,
As you can see My perpose is to get sth from session to hint the datasource.
1. if my conf is like what i offered before, it will new a DefaultDatabaseRoutingEngine as follows, it always hint my defaultDatabase.
RoutingEngineFactory:83
```
if (shardingRule.isAllInDefaultDataSource(tableNames)) {
return new DefaultDatabaseRoutingEngine(shardingRule, tableNames);
}
```
2.then i add some confs for tables,confs are as follows:
```
tables:
my_table:
database-strategy:
hint:
algorithm-class-name: a.b.c.OrderShardingAlgorithm
table-strategy:
hint:
algorithm-class-name: a.b.c.OrderShardingAlgorithm
```
then the factory can create a StandardRoutingEngine instance,
and the codes execute as
**route() ->
getDataNodes() ->
routeByHint() ->
route0() ->
getDatabaseShardingValuesFromHint() ->
routeDataSources() ->
myalgorithm.dosharding()**
i don't know if it's the correct way , but currently the method **getDatabaseShardingValuesFromHint()** always retruns an empty list and then the method **routeDataSources()** won't execute my algorithm, it returns directly.
```
public static Collection<Comparable<?>> getDatabaseShardingValues(final String logicTable) {
return null == HINT_MANAGER_HOLDER.get() ? Collections.<Comparable<?>>emptyList() : HINT_MANAGER_HOLDER.get().databaseShardingValues.get(logicTable);
}
```
this code compares my databases with table's name , so it always retruns empty.
```
HINT_MANAGER_HOLDER.get().databaseShardingValues.get(logicTable)
```
so i don't know if i lost some conf or others , could u please help me for this. π
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] terrymanu closed issue #3774: How Can I
config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] SteNicholas commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568669703
@tmjGitAccount What's more, `DatabaseHintRoutingEngine` isn't used in any routing case and modules. Therefore, the `DatabaseHintRoutingEngine` is necessary to remove. Where load your algorithm is that `StandardRoutingEngine` calls method `route()` to load user-defined algorithm.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568769360
> @tmjGitAccount Because you didn't execute `HintAddDatabaseShardingValueCommand` command like `sctl:hint addDatabaseShardingValue xx=yy.`.
@SteNicholas doesn't this command only belongs to sharding-proxy? can i use it in sharding-jdbc?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount edited a comment on issue
#3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount edited a comment on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568769360
> @tmjGitAccount Because you didn't execute `HintAddDatabaseShardingValueCommand` command like `sctl:hint addDatabaseShardingValue xx=yy.`.
@SteNicholas doesn't this command only belongs to sharding-proxy? can i use it in sharding-jdbc?
i tried to use hintmanager also ,but it seems not perfect for me π’,
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568837014
π₯ i mean i use **sharding-jdbc** rather than sharding-proxy,
can't i use my self-defined algorithm in sharding-jdbc?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] SteNicholas edited a comment on issue
#3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas edited a comment on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568664430
@tmjGitAccount Your understood exists mistake. `RoutingEngineFactory.newInstance()` should return `StandardRoutingEngine`, and call method `route()` to load your algorithm. Here isn't through `DatabaseHintRoutingEngine`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568713163
> @tmjGitAccount What's more, `DatabaseHintRoutingEngine` isn't used in any routing case and modules. Therefore, the `DatabaseHintRoutingEngine` is necessary to remove. Where load your algorithm is that `StandardRoutingEngine` calls method `route()` to load user-defined algorithm.
Thx for your reply, but there is still something wrong for me,
As you can see My perpose is to get sth from session to hint the datasource.
1. if my conf is like what i offered before, it will new a DefaultDatabaseRoutingEngine as follows, it always hint my defaultDatabase.
RoutingEngineFactory:83
```
if (shardingRule.isAllInDefaultDataSource(tableNames)) {
return new DefaultDatabaseRoutingEngine(shardingRule, tableNames);
}
```
2.then i add some confs for tables,confs are as follows:
```
tables:
my_table:
database-strategy:
hint:
algorithm-class-name: a.b.c.OrderShardingAlgorithm
table-strategy:
hint:
algorithm-class-name: a.b.c.OrderShardingAlgorithm
```
then the factory can create a StandardRoutingEngine instance,
and the codes execute as
**route() ->
getDataNodes() ->
routeByHint() ->
route0() ->
getDatabaseShardingValuesFromHint() ->
routeDataSources() ->
myalgorithm.dosharding()**
i don't know if it's the correct way , but currently the method **getDatabaseShardingValuesFromHint()** always retruns an empty list and then the method **routeDataSources()** won't execute my algorithm, it returns directly.
```
public static Collection<Comparable<?>> getDatabaseShardingValues(final String logicTable) {
return null == HINT_MANAGER_HOLDER.get() ? Collections.<Comparable<?>>emptyList() : HINT_MANAGER_HOLDER.get().databaseShardingValues.get(logicTable);
}
```
this code compares my databases with table's name , so it always retruns empty.
```
HINT_MANAGER_HOLDER.get().databaseShardingValues.get(logicTable)
```
so i don't know if i lost some conf or others , could u please help me for this. π
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] SteNicholas commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568767822
@tmjGitAccount Because you didn't execute `HintAddDatabaseShardingValueCommand` command like `sctl:hint addDatabaseShardingValue xx=yy.`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [shardingsphere] gongguoyu commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
gongguoyu commented on issue #3774:
URL: https://github.com/apache/shardingsphere/issues/3774#issuecomment-717899547
in 4.1.1 shill have this problem.....
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shardingsphere] terrymanu commented on issue #3774: How
Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568637209
@SteNicholas thank you, assigned.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] SteNicholas commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568810821
@tmjGitAccount You only through `sctl:hint addDatabaseShardingValue xx=yy` to execute `HintAddDatabaseShardingValueCommand `, then `HintAddDatabaseShardingValueExecutor` will execute this command.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568701647
> @tmjGitAccount What's more, `DatabaseHintRoutingEngine` isn't used in any routing case and modules. Therefore, the `DatabaseHintRoutingEngine` is necessary to remove. Where load your algorithm is that `StandardRoutingEngine` calls method `route()` to load user-defined algorithm.
Thx For Your Reply, But there is still something wrong for me ,
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] SteNicholas commented on issue #3774:
How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568664430
@tmjGitAccount Your understood exists mistake. `RoutingEngineFactory.newInstance()` should return `StandardRoutingEngine`, and call method `route()` to load your algorithm. Here isn't through DatabaseHintRoutingEngine.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [shardingsphere] cnlinjie commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
cnlinjie commented on issue #3774:
URL: https://github.com/apache/shardingsphere/issues/3774#issuecomment-800008104
@SteNicholas
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shardingsphere] tmjGitAccount removed a comment on issue
#3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount removed a comment on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568701647
> @tmjGitAccount What's more, `DatabaseHintRoutingEngine` isn't used in any routing case and modules. Therefore, the `DatabaseHintRoutingEngine` is necessary to remove. Where load your algorithm is that `StandardRoutingEngine` calls method `route()` to load user-defined algorithm.
Thx For Your Reply, But there is still something wrong for me ,
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] tmjGitAccount edited a comment on issue
#3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
tmjGitAccount edited a comment on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568837014
@SteNicholas
π₯ i mean i use **sharding-jdbc** rather than sharding-proxy,
can't i use my self-defined algorithm in sharding-jdbc?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [shardingsphere] cnlinjie commented on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
cnlinjie commented on issue #3774:
URL: https://github.com/apache/shardingsphere/issues/3774#issuecomment-800006055
in 4.1.1 shill have this problem.....
πππ
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shardingsphere] SteNicholas removed a comment on issue
#3774: How Can I config To Use DatabaseHintRoutingEngine
Posted by GitBox <gi...@apache.org>.
SteNicholas removed a comment on issue #3774: How Can I config To Use DatabaseHintRoutingEngine
URL: https://github.com/apache/incubator-shardingsphere/issues/3774#issuecomment-568326078
@tmjGitAccount You are right. `DatabaseHintRoutingEngine` isn't used in `RoutingEngineFactory `. @terrymanu Could you please assign this to me for fixing?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services