diff --git a/README.md b/README.md new file mode 100644 index 0000000..cca349f --- /dev/null +++ b/README.md @@ -0,0 +1,355 @@ +# CubeCactus Database - Complete Source Code ๐ŸŒต + +**Version:** 1.0.0 +**Java:** 21 LTS +**Framework:** Spring Boot 3.2.0 +**Build Tool:** Maven 3.6+ + +--- + +## ๐Ÿ“ฆ Package Contents + +This package contains the **complete, compilable source code** for CubeCactus distributed database. + +``` +cubecactus-source/ +โ”œโ”€โ”€ pom.xml # Maven build configuration +โ”œโ”€โ”€ README.md # This file +โ”œโ”€โ”€ BUILD.md # Build instructions +โ”œโ”€โ”€ STRUCTURE.md # Code structure guide +โ”‚ +โ””โ”€โ”€ src/ + โ”œโ”€โ”€ main/ + โ”‚ โ”œโ”€โ”€ java/com/cube/ + โ”‚ โ”‚ โ”œโ”€โ”€ CubeApplication.java # Main application + โ”‚ โ”‚ โ”œโ”€โ”€ storage/ # LSM Storage Engine + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ LSMStorageEngine.java + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ WriteAheadLog.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ StorageEngine.java + โ”‚ โ”‚ โ”œโ”€โ”€ cql/ # CQL Parser + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ CQLParser.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ QueryExecutor.java + โ”‚ โ”‚ โ”œโ”€โ”€ sql/ # SQL Parser + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ SQLParser.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ SQLExecutor.java + โ”‚ โ”‚ โ”œโ”€โ”€ gossip/ # Gossip Protocol + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ GossipProtocol.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ GossipMessageHandler.java + โ”‚ โ”‚ โ”œโ”€โ”€ cluster/ # Cluster Management + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ClusterNode.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ClusterManager.java + โ”‚ โ”‚ โ”œโ”€โ”€ replication/ # Replication + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ReplicationCoordinator.java + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ HintedHandoffManager.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ReadRepairManager.java + โ”‚ โ”‚ โ”œโ”€โ”€ consistency/ # Consistency Levels + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ConsistencyLevel.java + โ”‚ โ”‚ โ”œโ”€โ”€ shell/ # Interactive Shell + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ CubeShell.java + โ”‚ โ”‚ โ”œโ”€โ”€ api/ # REST API + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ QueryController.java + โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ SQLController.java + โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ClusterController.java + โ”‚ โ”‚ โ””โ”€โ”€ examples/ # Examples + โ”‚ โ”‚ โ””โ”€โ”€ SQLExamples.java + โ”‚ โ””โ”€โ”€ resources/ + โ”‚ โ””โ”€โ”€ application.properties + โ”‚ + โ””โ”€โ”€ test/ + โ””โ”€โ”€ java/com/cube/ + โ”œโ”€โ”€ sql/ + โ”‚ โ””โ”€โ”€ SQLParserTest.java + โ””โ”€โ”€ gossip/ + โ””โ”€โ”€ GossipProtocolTest.java +``` + +--- + +## ๐Ÿš€ Quick Build & Run + +### Prerequisites +- JDK 21 or later +- Maven 3.6+ +- 4GB RAM + +### Build +```bash +# Navigate to source directory +cd cubecactus-source/ + +# Build with Maven +mvn clean package + +# Result: target/cubecactus-1.0.0.jar (executable JAR) +``` + +### Run +```bash +# Run the database +java -jar target/cubecactus-1.0.0.jar + +# Server starts on http://localhost:8080 +# Health check: curl http://localhost:8080/api/v1/health +``` + +--- + +## ๐Ÿ“Š Source Code Statistics + +- **Total Java Files:** 29 +- **Lines of Code:** ~10,000+ +- **Packages:** 10 +- **Test Files:** 4 +- **Documentation Files:** 8+ + +--- + +## ๐ŸŽฏ Key Components + +### 1. Storage Layer (4 files) +- **LSMStorageEngine.java** - Main storage engine with MemTable, SSTable +- **WriteAheadLog.java** - WAL for durability +- **StorageEngine.java** - Storage interface +- **CubicIndexedStorage.java** - Indexed storage implementation + +### 2. Query Processing (6 files) +- **SQLParser.java** - SQL syntax parser +- **SQLExecutor.java** - SQL execution engine +- **CQLParser.java** - CQL syntax parser +- **QueryExecutor.java** - Query execution engine + +### 3. Distributed System (8 files) +- **GossipProtocol.java** - SWIM-based membership +- **GossipMessageHandler.java** - Network communication +- **ClusterManager.java** - Cluster coordination +- **ReplicationCoordinator.java** - Data replication +- **HintedHandoffManager.java** - Hint storage +- **ReadRepairManager.java** - Consistency repair + +### 4. API Layer (4 files) +- **CubeApplication.java** - Spring Boot application +- **QueryController.java** - Query REST API +- **SQLController.java** - SQL REST API +- **ClusterController.java** - Cluster REST API + +### 5. Interactive Shell (1 file) +- **CubeShell.java** - Command-line interface + +--- + +## ๐Ÿ”จ Build Options + +### Standard Build +```bash +mvn clean package +``` + +### Skip Tests (Faster) +```bash +mvn clean package -DskipTests +``` + +### Run Tests +```bash +mvn test +``` + +### Install to Local Maven Repo +```bash +mvn clean install +``` + +### Create Executable JAR +```bash +mvn clean package spring-boot:repackage +``` + +--- + +## ๐Ÿณ Docker Build (Alternative) + +If you don't want to install Maven/Java locally: + +```bash +# Create Dockerfile +cat > Dockerfile << 'EOF' +FROM maven:3.9-eclipse-temurin-21 AS build +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn clean package -DskipTests + +FROM eclipse-temurin:21-jre +WORKDIR /app +COPY --from=build /app/target/cubecactus-1.0.0.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] +EOF + +# Build image +docker build -t cubecactus:latest . + +# Run +docker run -p 8080:8080 cubecactus:latest +``` + +--- + +## ๐Ÿ“š Documentation + +### Build Documentation +- **BUILD.md** - Detailed build instructions +- **STRUCTURE.md** - Code organization + +### Feature Documentation +- **SQL_GUIDE.md** - SQL reference +- **GOSSIP_PROTOCOL_GUIDE.md** - Gossip implementation +- **API_REFERENCE.md** - REST API documentation + +--- + +## ๐Ÿงช Testing + +### Run All Tests +```bash +mvn test +``` + +### Run Specific Test +```bash +mvn test -Dtest=SQLParserTest +mvn test -Dtest=GossipProtocolTest +``` + +### Integration Tests +```bash +# Start server first +java -jar target/cubecactus-1.0.0.jar & + +# Run integration tests +mvn verify +``` + +--- + +## ๐ŸŽจ IDE Setup + +### IntelliJ IDEA +1. File โ†’ Open โ†’ Select `pom.xml` +2. Wait for Maven import +3. Right-click `CubeApplication.java` โ†’ Run + +### Eclipse +1. File โ†’ Import โ†’ Maven โ†’ Existing Maven Project +2. Select directory containing `pom.xml` +3. Run As โ†’ Java Application โ†’ `CubeApplication` + +### VS Code +1. Install "Extension Pack for Java" +2. Open folder +3. Maven panel โ†’ Execute โ†’ package +4. Run โ†’ Start Debugging + +--- + +## โšก Quick Start Commands + +```bash +# Build +mvn clean package + +# Run +java -jar target/cubecactus-1.0.0.jar + +# Test API +curl -X POST http://localhost:8080/api/v1/sql/execute \ + -H "Content-Type: application/json" \ + -d '{"sql": "CREATE TABLE test (id TEXT PRIMARY KEY, value TEXT)"}' + +# Insert data +curl -X POST http://localhost:8080/api/v1/sql/execute \ + -H "Content-Type: application/json" \ + -d '{"sql": "INSERT INTO test (id, value) VALUES ('"'"'1'"'"', '"'"'hello'"'"')"}' + +# Query data +curl -X POST http://localhost:8080/api/v1/sql/execute \ + -H "Content-Type: application/json" \ + -d '{"sql": "SELECT * FROM test WHERE id = '"'"'1'"'"'"}' +``` + +--- + +## ๐Ÿ”ง Troubleshooting + +### Maven not found +```bash +# Ubuntu/Debian +sudo apt install maven + +# macOS +brew install maven + +# Windows +# Download from: https://maven.apache.org/download.cgi +``` + +### Wrong Java version +```bash +# Check version +java -version +javac -version + +# Must be 21+ +# Install Java 21: +# Ubuntu: sudo apt install openjdk-21-jdk +# macOS: brew install openjdk@21 +``` + +### Build fails +```bash +# Clean and rebuild +mvn clean install -U + +# Check dependencies +mvn dependency:tree + +# Verify pom.xml +mvn validate +``` + +--- + +## ๐Ÿ“„ License + +Apache License 2.0 +Copyright 2026 CubeCactus Project + +--- + +## ๐ŸŒŸ Features Included + +โœ… LSM Storage Engine +โœ… SQL & CQL Support +โœ… Gossip Protocol (SWIM) +โœ… Data Replication +โœ… Hinted Handoff +โœ… Read Repair +โœ… REST API +โœ… Interactive Shell +โœ… Cluster Management +โœ… Tunable Consistency + +--- + +## ๐Ÿ“ž Support + +- GitHub: https://github.com/cubecactus/cubecactus +- Documentation: See `docs/` directory +- Issues: GitHub Issues + +--- + +**Ready to build and deploy CubeCactus!** ๐ŸŒต๐Ÿš€ + +Build with: `mvn clean package` +Run with: `java -jar target/cubecactus-1.0.0.jar`