Carade v0.2.0 #1

Merged
irammini merged 26 commits from dev into main 2025-12-20 21:02:25 +00:00
irammini commented 2025-12-15 05:02:46 +00:00 (Migrated from github.com)
No description provided.
irammini commented 2025-12-15 05:03:02 +00:00 (Migrated from github.com)

In this commit:

  • Add ZSET support with ZADD, ZRANGE (with WITHSCORES), and ZRANK.
  • Add bulk operations MSET and MGET.
  • Implement CaradeZSet using ConcurrentHashMap and ConcurrentSkipListSet.
  • Update persistence (AOF rewrite and Snapshot) to support ZSET.
  • Update AOF replay logic to handle ZADD with multiple arguments and MSET.
In this commit: - Add `ZSET` support with `ZADD`, `ZRANGE` (with `WITHSCORES`), and `ZRANK`. - Add bulk operations `MSET` and `MGET`. - Implement `CaradeZSet` using `ConcurrentHashMap` and `ConcurrentSkipListSet`. - Update persistence (AOF rewrite and Snapshot) to support `ZSET`. - Update AOF replay logic to handle `ZADD` with multiple arguments and `MSET`.
irammini commented 2025-12-18 10:55:59 +00:00 (Migrated from github.com)

In this commit:

  • Added MULTI, EXEC, DISCARD for atomic transactions.
  • Implemented SISMEMBER, SCARD, HINCRBY.
  • Updated HSET, LPUSH, RPUSH to support variadic arguments.
  • Refactored command execution into executeCommand helper.
  • Introduced globalLock to ensure atomicity for transactions and safe execution.
In this commit: - Added `MULTI`, `EXEC`, `DISCARD` for atomic transactions. - Implemented `SISMEMBER`, `SCARD`, `HINCRBY`. - Updated `HSET`, `LPUSH`, `RPUSH` to support variadic arguments. - Refactored command execution into `executeCommand` helper. - Introduced `globalLock` to ensure atomicity for transactions and safe execution.
irammini commented 2025-12-18 11:21:50 +00:00 (Migrated from github.com)

In this commit:

  • Replaced ReentrantLock with ReentrantReadWriteLock to allow concurrent execution of normal commands while maintaining atomicity for transactions (EXEC).
  • Optimized ValueEntry memory usage by storing values as byte[] instead of String, reducing heap overhead and GC pressure.
  • Improved AOF Rewrite to be non-blocking by using a rewrite buffer to capture incoming commands during the rewrite process.
  • Fixed binary safety issues in RESP protocol handling by supporting direct byte array output.
  • Fixed file handling in AOF rewrite to ensure proper resource cleanup and compatibility with file locking mechanisms.
  • Add a CI workflow.
In this commit: - Replaced `ReentrantLock` with `ReentrantReadWriteLock` to allow concurrent execution of normal commands while maintaining atomicity for transactions (`EXEC`). - Optimized `ValueEntry` memory usage by storing values as `byte[]` instead of `String`, reducing heap overhead and GC pressure. - Improved AOF Rewrite to be non-blocking by using a rewrite buffer to capture incoming commands during the rewrite process. - Fixed binary safety issues in RESP protocol handling by supporting direct byte array output. - Fixed file handling in AOF rewrite to ensure proper resource cleanup and compatibility with file locking mechanisms. - Add a CI workflow.
irammini commented 2025-12-18 12:13:39 +00:00 (Migrated from github.com)

In this commit:

  • Basic: EXISTS, TYPE, RENAME
  • Sorted Set: ZREVRANGE, ZREM, ZSCORE
  • Set: SINTER, SUNION, SDIFF
  • Bitmap: SETBIT, GETBIT (using byte[] storage)

Updated Carade.java to support these commands in both client handler and AOF replay logic.
Ensured AOF replay logic (executeInternal) does not perform client I/O.

In this commit: - Basic: EXISTS, TYPE, RENAME - Sorted Set: ZREVRANGE, ZREM, ZSCORE - Set: SINTER, SUNION, SDIFF - Bitmap: SETBIT, GETBIT (using byte[] storage) Updated `Carade.java` to support these commands in both client handler and AOF replay logic. Ensured AOF replay logic (`executeInternal`) does not perform client I/O.
irammini commented 2025-12-18 12:58:58 +00:00 (Migrated from github.com)

In this commit:

  • Refactored ClientHandler.run to acquire the global Write Lock for RENAME, MSET, FLUSHALL, and BGREWRITEAOF.
  • This ensures these commands are executed atomically, preventing race conditions (e.g., RENAME removing a key that is then read by another thread before being re-inserted).
  • Standard single-key commands continue to use the Read Lock, leveraging ConcurrentHashMap for concurrency.
In this commit: - Refactored `ClientHandler.run` to acquire the global Write Lock for `RENAME`, `MSET`, `FLUSHALL`, and `BGREWRITEAOF`. - This ensures these commands are executed atomically, preventing race conditions (e.g., `RENAME` removing a key that is then read by another thread before being re-inserted). - Standard single-key commands continue to use the Read Lock, leveraging `ConcurrentHashMap` for concurrency.
irammini commented 2025-12-18 15:14:06 +00:00 (Migrated from github.com)

In this commit:

Implemented the WATCH and UNWATCH commands to support optimistic locking in transactions. This ensures that if a watched key is modified by another client, the transaction will be aborted. Modified Carade.java to track watched keys and notify clients upon modification. Updated ClientHandler to manage the watch state and transaction dirty flag. Instrumented all write commands (SET, DEL, HSET, etc.) to trigger notifications. Addressed code review feedback regarding thread safety by making transactionDirty volatile and ensuring atomic cleanup in unwatchAll.

In this commit: Implemented the `WATCH` and `UNWATCH` commands to support optimistic locking in transactions. This ensures that if a watched key is modified by another client, the transaction will be aborted. Modified `Carade.java` to track watched keys and notify clients upon modification. Updated `ClientHandler` to manage the watch state and transaction dirty flag. Instrumented all write commands (SET, DEL, HSET, etc.) to trigger notifications. Addressed code review feedback regarding thread safety by making `transactionDirty` volatile and ensuring atomic cleanup in `unwatchAll`.
irammini commented 2025-12-18 16:54:35 +00:00 (Migrated from github.com)

In this commit:

Refactored Resp.java and ValueEntry (in Carade.java) to use byte[] instead of String to ensure binary safety. Updated AofHandler to support binary data persistence. Verified with a test script sending non-UTF8 bytes.

In this commit: Refactored Resp.java and ValueEntry (in Carade.java) to use byte[] instead of String to ensure binary safety. Updated AofHandler to support binary data persistence. Verified with a test script sending non-UTF8 bytes.
irammini commented 2025-12-18 16:54:54 +00:00 (Migrated from github.com)

gtg, good night.

gtg, good night.
irammini commented 2025-12-19 04:51:59 +00:00 (Migrated from github.com)

In this commit:

  • Added scanRegistry to store stateful iterators for SCAN commands.
  • SCAN iterators expire after 10 minutes.
  • Added handleScan helper method to support MATCH and COUNT.
  • Added ZCARD (O(1)), ZCOUNT (O(N) for range), and ZINCRBY.
  • Updated AOF logging and replay for ZINCRBY.
  • Added necessary imports and AtomicLong for cursor ID generation.
In this commit: - Added `scanRegistry` to store stateful iterators for SCAN commands. - SCAN iterators expire after 10 minutes. - Added `handleScan` helper method to support `MATCH` and `COUNT`. - Added `ZCARD` (O(1)), `ZCOUNT` (O(N) for range), and `ZINCRBY`. - Updated AOF logging and replay for `ZINCRBY`. - Added necessary imports and `AtomicLong` for cursor ID generation.
irammini commented 2025-12-19 11:47:59 +00:00 (Migrated from github.com)

In this commit:

  • Extracted Data Structures: Moved ZNode, CaradeZSet, ValueEntry, DataType to core.structs and core.db.
  • Extracted Storage Engine: Created core.db.CaradeDatabase to manage store, eviction, and atomic operations.
  • Extracted Networking: Moved ClientHandler to core.network, decoupled from Carade main class.
  • Implemented Command Pattern: Created core.commands.Command interface and CommandRegistry.
  • Implemented SetCommand: Migrated SET command to the new pattern.
  • Updated Carade.java to serve as bootstrap and AOF replayer.
  • Updated ClientHandler to use CommandRegistry with fallback to legacy switch-case.
  • Fixed Transaction bug where new Commands wrote directly to socket instead of transaction buffer.
  • Note: This change modifies internal class structures which breaks binary compatibility with previous carade.dump files.
In this commit: - Extracted Data Structures: Moved `ZNode`, `CaradeZSet`, `ValueEntry`, `DataType` to `core.structs` and `core.db`. - Extracted Storage Engine: Created `core.db.CaradeDatabase` to manage `store`, eviction, and atomic operations. - Extracted Networking: Moved `ClientHandler` to `core.network`, decoupled from `Carade` main class. - Implemented Command Pattern: Created `core.commands.Command` interface and `CommandRegistry`. - Implemented `SetCommand`: Migrated `SET` command to the new pattern. - Updated `Carade.java` to serve as bootstrap and AOF replayer. - Updated `ClientHandler` to use `CommandRegistry` with fallback to legacy switch-case. - Fixed Transaction bug where new Commands wrote directly to socket instead of transaction buffer. - Note: This change modifies internal class structures which breaks binary compatibility with previous `carade.dump` files.
irammini commented 2025-12-19 13:43:27 +00:00 (Migrated from github.com)

In this commit:

  • PersistCommand: Removes expiration from a key.
  • ClientSetNameCommand: Sets the name of the current connection.
  • ClientGetNameCommand: Retrieves the name of the current connection.
In this commit: - `PersistCommand`: Removes expiration from a key. - `ClientSetNameCommand`: Sets the name of the current connection. - `ClientGetNameCommand`: Retrieves the name of the current connection.
irammini commented 2025-12-19 17:32:03 +00:00 (Migrated from github.com)

In this commit:

  1. Utilities: Added GeoUtils.java to handle Geohash encoding/decoding and distance calculations (matching Redis logic).
  2. Commands:
    • GEOADD: Adds geospatial items to a ZSet.
    • GEODIST: Calculates distance between two members.
    • GEORADIUS: Finds members within a given radius (implemented via naive iteration for simplicity/speed in prototype).
  3. Protocol Enhancements: Updated Resp.java and ClientHandler.java to support sending mixed-type nested arrays, required by GEORADIUS output options.
  4. Registration: Registered new commands in CommandRegistry.
In this commit: 1. **Utilities:** Added `GeoUtils.java` to handle Geohash encoding/decoding and distance calculations (matching Redis logic). 2. **Commands:** * `GEOADD`: Adds geospatial items to a ZSet. * `GEODIST`: Calculates distance between two members. * `GEORADIUS`: Finds members within a given radius (implemented via naive iteration for simplicity/speed in prototype). 3. **Protocol Enhancements:** Updated `Resp.java` and `ClientHandler.java` to support sending mixed-type nested arrays, required by `GEORADIUS` output options. 4. **Registration:** Registered new commands in `CommandRegistry`.
irammini commented 2025-12-19 17:57:41 +00:00 (Migrated from github.com)

In this commit:

  • Created RdbParser capable of reading standard Redis RDB files, including support for:
    • String, List, Set, Hash, ZSet types.
    • Length encodings (6, 14, 32 bit).
    • LZF Compressed strings.
    • Ziplist encoding (used for List, Hash, ZSet).
    • IntSet encoding (used for Set).
    • QuickList encoding (used for List).
  • Created RdbEncoder to save snapshots in RDB format (Version 9).
  • Updated Carade.java to detect "REDIS" magic header and use RdbParser, falling back to legacy loaders if needed.
  • Switched default saveData to use RDB format.
In this commit: - Created `RdbParser` capable of reading standard Redis RDB files, including support for: - String, List, Set, Hash, ZSet types. - Length encodings (6, 14, 32 bit). - LZF Compressed strings. - Ziplist encoding (used for List, Hash, ZSet). - IntSet encoding (used for Set). - QuickList encoding (used for List). - Created `RdbEncoder` to save snapshots in RDB format (Version 9). - Updated `Carade.java` to detect "REDIS" magic header and use `RdbParser`, falling back to legacy loaders if needed. - Switched default `saveData` to use RDB format.
irammini commented 2025-12-20 08:41:54 +00:00 (Migrated from github.com)

In this commit:

  • Refactor CaradeDatabase to support 16 databases using an array of ConcurrentHashMap.
  • Update ClientHandler to maintain dbIndex and route commands to the correct database.
  • Implement SELECT command to switch databases.
  • Implement LTRIM command for list truncation.
  • Implement RPOPLPUSH command for atomic list moves.
  • Update RDB and AOF persistence layers to support multiple databases and SELECT opcodes.
  • Ensure correct AOF logging for SELECT and FLUSHDB to maintain consistency during replay.
  • Fix BGREWRITEAOF to persist all non-empty databases.
In this commit: - Refactor `CaradeDatabase` to support 16 databases using an array of `ConcurrentHashMap`. - Update `ClientHandler` to maintain `dbIndex` and route commands to the correct database. - Implement `SELECT` command to switch databases. - Implement `LTRIM` command for list truncation. - Implement `RPOPLPUSH` command for atomic list moves. - Update RDB and AOF persistence layers to support multiple databases and `SELECT` opcodes. - Ensure correct AOF logging for `SELECT` and `FLUSHDB` to maintain consistency during replay. - Fix `BGREWRITEAOF` to persist all non-empty databases.
irammini commented 2025-12-20 10:14:26 +00:00 (Migrated from github.com)

This change decouples command execution, introduces a Global Write Sequencer,
and implements a Replication Backlog to ensure strict ordering of data mutations.

Key changes:

  • Created core.server.WriteSequencer to coordinate DB updates, Backlog writes, and AOF logging atomically.
  • Created core.replication.ReplicationBacklog (Ring Buffer) for future PSYNC support.
  • Renamed and refactored AofHandler to CommandLogger, integrating it with the Sequencer.
  • Refactored ClientHandler to route all write commands (e.g., SET, INCR, HSET, ZADD) through the Sequencer.
  • Fixed potential Deadlocks by optimizing lock acquisition in ClientHandler.
  • Addressed time drift issues by converting relative expirations (EXPIRE) to absolute timestamps (PEXPIREAT) during logging.
This change decouples command execution, introduces a Global Write Sequencer, and implements a Replication Backlog to ensure strict ordering of data mutations. Key changes: - Created `core.server.WriteSequencer` to coordinate DB updates, Backlog writes, and AOF logging atomically. - Created `core.replication.ReplicationBacklog` (Ring Buffer) for future PSYNC support. - Renamed and refactored `AofHandler` to `CommandLogger`, integrating it with the Sequencer. - Refactored `ClientHandler` to route all write commands (e.g., SET, INCR, HSET, ZADD) through the Sequencer. - Fixed potential Deadlocks by optimizing lock acquisition in `ClientHandler`. - Addressed time drift issues by converting relative expirations (EXPIRE) to absolute timestamps (PEXPIREAT) during logging.
irammini commented 2025-12-20 18:53:36 +00:00 (Migrated from github.com)

In this commit:

  • Implemented Master-Slave Replication (REPLICAOF, PSYNC, ReplicationManager) using RDB snapshots and Backlog catch-up.
  • Added Keyspace Notifications (__keyspace__ events) in CaradeDatabase.
  • Implemented configurable Eviction Policies (maxmemory-policy) including LRU.
  • Added Memory Optimization capability in ValueEntry (lazy compression of small collections).
  • Refactored ClientHandler and RdbEncoder to use ValueEntry.getValue() for safe access.
In this commit: - Implemented Master-Slave Replication (`REPLICAOF`, `PSYNC`, `ReplicationManager`) using RDB snapshots and Backlog catch-up. - Added Keyspace Notifications (`__keyspace__` events) in `CaradeDatabase`. - Implemented configurable Eviction Policies (`maxmemory-policy`) including LRU. - Added Memory Optimization capability in `ValueEntry` (lazy compression of small collections). - Refactored `ClientHandler` and `RdbEncoder` to use `ValueEntry.getValue()` for safe access.
irammini commented 2025-12-20 19:54:10 +00:00 (Migrated from github.com)

In this commit:

  • Added HMGET command in core.commands.hash.HmgetCommand and registered it.
  • Added keyspaceHits and keyspaceMisses AtomicLong counters to core.Carade.
  • Instrumented core.db.CaradeDatabase.get() to update keyspace stats.
  • Updated INFO command in core.network.ClientHandler to display real keyspace stats.
  • Fixed a potential NPE in core.protocol.Resp.bulkString() when handling null byte arrays.
In this commit: - Added `HMGET` command in `core.commands.hash.HmgetCommand` and registered it. - Added `keyspaceHits` and `keyspaceMisses` AtomicLong counters to `core.Carade`. - Instrumented `core.db.CaradeDatabase.get()` to update keyspace stats. - Updated `INFO` command in `core.network.ClientHandler` to display real keyspace stats. - Fixed a potential NPE in `core.protocol.Resp.bulkString()` when handling null byte arrays.
irammini commented 2025-12-20 21:00:34 +00:00 (Migrated from github.com)

In this commit:

  • Updated GeoAddCommand and ExpireAtCommand to use executeWrite for proper AOF/Replication.
  • Updated Carade.executeInternal to handle GEOADD, EXPIREAT, and PEXPIREAT during AOF replay.
  • Refactored GET, DEL, LPOP, RPOP, HSET, HGET from ClientHandler switch-case to standalone Command classes.
  • Registered new commands in Carade.java.
In this commit: - Updated `GeoAddCommand` and `ExpireAtCommand` to use `executeWrite` for proper AOF/Replication. - Updated `Carade.executeInternal` to handle `GEOADD`, `EXPIREAT`, and `PEXPIREAT` during AOF replay. - Refactored `GET`, `DEL`, `LPOP`, `RPOP`, `HSET`, `HGET` from `ClientHandler` switch-case to standalone Command classes. - Registered new commands in `Carade.java`.
Sign in to join this conversation.
No description provided.