You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by Sun Kane <ka...@outlook.com> on 2020/04/21 04:38:01 UTC

回复: Re:the usage about Hint

I see.  maybe I missed some key info , I will check the document again .

BTW, if there is no description about  `DefaultDatbaseStrategy` , I'll add this explaination to current document.

thx Juan , thx the help form comunity
________________________________
发件人: hannkenn@163.com <ha...@163.com> 代表 Juan Pan <pa...@apache.org>
发送时间: 2020年4月21日 11:38
收件人: dev@shardingsphere.apache.org <de...@shardingsphere.apache.org>
抄送: dev <de...@shardingsphere.apache.org>
主题: Re:the usage about Hint

Hi
The first question is bout `hint`, and the second one is `defaultDatbaseStrategy`.
Let me give more explanation one by one.


## Hint
I am sorry `ModuloHintShardingAlgorithm` is not a proper example,
but the key point of `hint` is your sharding values which decide SQL routing come from `hintManager`,
rather than `SQL`.  You can refer to [1] to learn more.


## DefaultDatbaseStrategy
Once there is no specific `DatbaseStrategy` for some logic tables, `DefaultDatbaseStrategy` will take effect.
Sometimes a user is going to use `DefaultDatbaseStrategy`  for many logic tables
so as not to configure specific `DatbaseStrategy` one by one.
You know, it will take a lot of time.
Thanks.


[1] https://shardingsphere.apache.org/document/current/en/features/sharding/other-features/sharding-hint/




Best,
trista


 Juan Pan (Trista)

Senior DBA & PPMC of Apache ShardingSphere(Incubating)
E-mail: panjuan@apache.org




On 04/20/2020 23:54,Sun Kane<ka...@outlook.com> wrote:
hi there

today I got a confusion about the usage of hint , hope someone could help to explian.

as followings are parts of configuration for hint in shardingsphere example :


shardingRule:
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
databaseStrategy:
hint:
algorithmClassName: org.apache.shardingsphere.example.hint.raw.jdbc.ModuloHintShardingAlgorithm
tableStrategy:
hint:
algorithmClassName: org.apache.shardingsphere.example.hint.raw.jdbc.ModuloHintShardingAlgorithm

after I got the code for ModuloHintShardingAlgorithm, I realized this is so similar as `inline` , I'm not sure why not use inline instead of this strategy .


public Collection<String> doSharding(final Collection<String> availableTargetNames, final HintShardingValue<Long> shardingValue) {
Collection<String> result = new ArrayList<>();
for (String each : availableTargetNames) {
System.out.println("each is : "+each);
System.out.println("sharding value  is : "+shardingValue);
for (Long value : shardingValue.getValues()) {
if (each.endsWith(String.valueOf(value % 2))) {
result.add(each);
}
}
}
return result;
}


until I encount following settings


hintManager.addDatabaseShardingValue("t_order", 1L);
hintManager.addTableShardingValue("t_order", 1L);

so , here is my confusion , the `HintShardingValues` that set by hintManager will paticipate in the Sharding Process, I still don't understand what kind of situation will use this kind of strategy ? If I set a collections to TableShardingValue, what does that use for ?

and another question is , when or how the `defaultDatbaseStrategy` and `defaultTableStrategy`  will be triggered  since I already set up the DatabaseStrategy and TalbeStrategy

anybody could help will be grateful