Design a Database Partition Split-and-Merge Manager
Design objects that locate key ranges and safely split or merge database partitions as load changes.
A database is divided into partitions. The source asks for a manager that splits a partition when it is above a threshold and otherwise merges suitable partitions.
For this exercise, assume the configured keyspace is completely covered by non-overlapping contiguous partition ranges, load is supplied by a monitoring component, the split threshold is configuration, a split divides one range into two adjacent ranges at a supplied split key, and a merge combines adjacent ranges only when their combined load is at or below the configured threshold.
For this exercise, design the object model and contracts for locating a key, recording observations, planning a split or merge, and applying the change atomically. Storage-engine data movement is represented through an injected collaborator; do not design the distributed database itself.
For the concurrency follow-up, assume two workers may plan or apply changes concurrently and a rejected or uncertain operation may be retried.