Class SchemaShardingManager
-
- All Implemented Interfaces:
-
pro.fessional.wings.faceless.flywave.InteractiveManager
public final class SchemaShardingManager implements InteractiveManager<SchemaShardingManager.AskType>
Clone the plain table structure to auto create shard table, and auto sharing data.
- Since:
2019-06-06
trydofor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumSchemaShardingManager.AskType
-
Constructor Summary
Constructors Constructor Description SchemaShardingManager(Map<String, DataSource> plainDataSources, DataSource shardDataSource, SqlStatementParser sqlStatementParser, SchemaDefinitionLoader schemaDefinitionLoader)
-
Method Summary
Modifier and Type Method Description BiConsumer<String, String>logWay(BiConsumer<String, String> func)How to log the runtime token and message Function<String, Boolean>askWay(Function<String, Boolean> func)How to confirm, pass message, return to continue or stop BooleanneedAsk(SchemaShardingManager.AskType ask, Boolean yes)Whether to confirm before undofinal UnitpublishShard(String table, Integer number)Check and shard table with table_0 to table_${NUMBER - 1}, total NUMBER tables. final UnitshardingData(String table, Boolean stopOnError)Migrate small size data from the plain table to the shard datasource, it is not recommended to use it for more than one million data. -
-
Constructor Detail
-
SchemaShardingManager
SchemaShardingManager(Map<String, DataSource> plainDataSources, DataSource shardDataSource, SqlStatementParser sqlStatementParser, SchemaDefinitionLoader schemaDefinitionLoader)
-
-
Method Detail
-
logWay
BiConsumer<String, String> logWay(BiConsumer<String, String> func)
How to log the runtime token and message
-
askWay
Function<String, Boolean> askWay(Function<String, Boolean> func)
How to confirm, pass message, return to continue or stop
-
needAsk
Boolean needAsk(SchemaShardingManager.AskType ask, Boolean yes)
Whether to confirm before
undo- Parameters:
ask- ask typeyes- whether to confirm, true by default- Returns:
old value
-
publishShard
final Unit publishShard(String table, Integer number)
Check and shard table with table_0 to table_${NUMBER - 1}, total NUMBER tables. A warning is displayed if the footer is not consecutive or if the total is greater than the NUMBER. If shard table already exist, but none of them have records, delete them all and recreate. If none exist, create new ones. Otherwise, an error will throw. Manual intervention is required
- Parameters:
table- plain tablenumber- count of sharding,0means no sharding.
-
shardingData
final Unit shardingData(String table, Boolean stopOnError)
Migrate small size data from the plain table to the shard datasource, it is not recommended to use it for more than one million data. When migrating data, it is recommended to disable triggers to avoid generating a lot of useless data. The execution process uses 3 threads: select, insert and delete. 2 blocking queue: insert, delete. default size 1024. Execute without transaction. If the target data is successfully inserted, then the source data is deleted. If it fails, there may be dirty data, you need to insert manually, according to the log processing
- Parameters:
table- plain tablestopOnError- Whether to stop when insertion or deletion fails, the default is not to stop, only record error.
-
-
-
-