JDA
JDA copied to clipboard
Shardmanager - Dynamic shard startup
General Troubleshooting
- [x] I have checked for similar issues.
- [x] I have updated to the [latest JDA version][download].
- [x] I have checked the branches or the maintainers' PRs for upcoming features.
Feature Request
Adjust the Shardmanager to allow for dynamic clustering without fancy workarounds
Example Use-Case
Feature request originating from chat in #1721
It would be great to allow building the Shardmanager without defining the actual shards it will run later so we can dynamically let those match our needs when we think it is safe to do so.
Current Behaviour
A) We dont define any shards
var sm = DefaultShardManagerBuilder
.createLight("TOUCAN")
.setShardsTotal(totalshards) // lets say its 5
.build(false);
When calling sm.start() the Shardmanager will proceed to start all shards from 0 to 4 in order. When calling start(int) with a shardid the same behaviour can be observed ignoring our selection.
B) We define some shards
var sm = DefaultShardManagerBuilder
.createLight("TOUCAN")
.setShardsTotal(totalshards) // lets say its 5
.setShards(shards) // 0, 2, 3
.build(false);
When calling sm.start() the Shardmanager will proceed to start all shards specified in order. When calling start(int) with a shardid the same behaviour can be observed ignoring our selection.
Expected Behaviour
A) We dont define any shards
No shards will be started when calling sm.start() which will require an explicit definition to use the auto sharding feature. Alternatively the current behaviour of starting all shards might remain tho this might feel a bit inconsistent then. Only the shard specified will be started when calling sm.start(int).
B) We define some shards
No shards will be started when calling sm.start() which will require an explicit definition to use the auto sharding feature. Alternatively the current behaviour of starting all defined shards might remain tho this might feel a bit inconsistent then. Only the shard specified will be started when calling sm.start(int).
Current Workaround
Define only the lowest shardid you would intend to start within the builder. When the shards are supposed to login, beginn calling start(int) starting with the lowest id. It is important that the specified id is the lowest and the same in both cases. As the shardmanager will ignore the id for the initial start, we might start the wrong shard without any simple ways to knowing this. Also this allows for easy sorting which makes it a bit less prone to breaking.
var sm = DefaultShardManagerBuilder
.createLight("TOUCAN")
.setShardsTotal(totalshards) // lets say its 5
.setShards(0) // 0, (2, 3)
.build(false);
...
sm.start(0)
sm.start(2)
sm.start(3)