$ show MyCATApache/Mycat-Server
Mycat is an open-source database middleware proxy for MySQL, implementing the MySQL protocol to provide sharding, read/write splitting, global tables, XA transactions, and multi-database backend support (MySQL, PostgreSQL, MongoDB, SequoiaDB). The system routes SQL statements to appropriate backend shards based on configurable partition algorithms, merges result sets, and manages connection pooling, caching, and distributed sequence generation. Architecture is a Java NIO-based server with frontend and backend connection handlers, an SQL parser (Druid extended), a routing engine, and a management interface. The codebase is large (1200+ files) and shows significant engineering investment but suffers from heavy technical debt: mixed Chinese and English comments, many hardcoded values, duplicate boilerplate response classes, deprecated internal APIs, and an aging dependency footprint (Java 8, old Druid version, sun.misc.Unsafe usage). The project appears to be in maintenance mode with limited recent contributions, and the configuration/synchronization via ZooKeeper adds operational complexity.
The LLM identified 5 files worth highlighting for reuse:
High-performance external sorter that can spill data to disk when memory is exhausted. It uses off-heap memory (via `sun.misc.Unsafe`) and a `BytesToBytesMap` for in-memory sorting, merging multiple sorted runs from disk. This component is adapted from Apache Spark's Tungsten sort and can be extracted for any project needing large-scale, memory-efficient sorting of key-value records.
Lock-free multi-producer sequencer implementing a ring buffer pattern similar to LMAX Disruptor. It supports multiple producers claiming slots simultaneously using atomic operations and a configurable wait strategy. The class is well-encapsulated and can be reused for high-throughput event processing, message queuing, or any scenario requiring low-latency inter-thread communication.
A partition algorithm that uses hash modulus to distribute rows across shards. Implements the `AbstractPartitionAlgorithm` interface with a simple `calculate` method that computes a hash of the partition key and maps it to a data node. The component is self-contained, configurable via XML, and can be reused in any system requiring deterministic sharding logic.
Abstract memory allocator with on-heap and off-heap implementations. Provides `allocate(long size)` and `free(Object memory)` methods. The off-heap allocator uses `sun.misc.Unsafe` for direct memory operations. This component is the foundation for Mycat's memory pool and can be extracted for any low-level memory management task where performance and control over allocation are critical.
A highly optimized `Set` implementation for storing a small number of elements (typically <= 2). Internally, it uses a single array and linear search without hashing overhead. The component is a clean, reusable drop-in replacement for `HashSet` in performance-sensitive code paths where the set size is known to be small.