Skip to content

Conversation

@axfor
Copy link
Owner

@axfor axfor commented Oct 26, 2025

apis: added an etcd protocol access interface

axfor added 4 commits October 25, 2025 14:08
This is a major cleanup that removes redundant naming patterns and
legacy code, making the codebase more professional and maintainable.

Key changes:

1. Command-line interface improvement
   - Rename flag --id to --member-id for clarity
   - Update all documentation (README, docs/, test scripts)

2. Remove legacy kvstore implementations (5 files deleted)
   - internal/memory/kvstore.go (old Memory type)
   - internal/memory/kvstore_stubs.go
   - internal/memory/kvstore_test.go
   - internal/rocksdb/kvstore.go (old RocksDB type)
   - internal/rocksdb/kvstore_stubs.go

   These were replaced by the modern etcd-compatible implementations
   but tests still referenced the old types.

3. Restore and adapt HTTP API tests
   - Restore test/http_api_memory_consistency_test.go
   - Restore test/http_api_memory_integration_test.go
   - Restore test/http_api_rocksdb_consistency_test.go
   - Update all tests to use new Memory/RocksDB types

   HTTP API tests provide independent protocol coverage beyond
   etcd compatibility tests.

4. Simplify type naming (remove redundant EtcdRaft suffix)
   - MemoryEtcdRaft → Memory
   - RocksDBEtcdRaft → RocksDB
   - NewMemoryEtcdRaft() → NewMemory()
   - NewRocksDBEtcdRaft() → NewRocksDB()

5. Simplify file naming (10 files renamed)
   - internal/memory/kvstore_etcd_raft.go → kvstore.go
   - internal/memory/kvstore_etcd.go → store.go
   - internal/memory/kvstore_etcd_watch_lease.go → watch.go
   - internal/rocksdb/kvstore_etcd_raft.go → kvstore.go
   - pkg/etcdcompat/ → pkg/etcdapi/ (8 files)

Benefits:
- Cleaner, more professional naming conventions
- No redundant "EtcdRaft" or "compat" suffixes
- Better file organization with clear responsibilities
- Removed ~500 lines of dead code (legacy implementations)
- Comprehensive test coverage (HTTP API + etcd API)
- All tests passing (35 files changed, 5 deleted, 10 renamed)

Migration notes:
- Old Memory/RocksDB types removed (were unused except in deleted tests)
- All production code uses simplified Memory/RocksDB types
- HTTP API tests now use modern etcd-compatible implementations
- No breaking changes to public APIs
This commit implements complete etcd v3 Transaction (Txn) functionality
for both Memory and RocksDB storage engines, with full Compare-Then-Else
semantics and Raft consensus support.

Key Features:
- Complete Transaction implementation with Compare-Then-Else semantics
- Support for all compare targets: Version, CreateRevision, ModRevision, Value, Lease
- Support for all compare operations: Equal, Greater, Less, NotEqual
- Transaction operations: Range (Get), Put, Delete
- Distributed consistency via Raft consensus
- Full etcd v3 client SDK compatibility

Implementation Details:

1. Memory Engine (internal/memory/):
   - Added Txn() method with Raft-based consensus
   - Implemented pendingTxnResults for transaction result synchronization
   - Created txnUnlocked() for deadlock-free execution
   - Extended RaftOperation to support Transaction type
   - Added sequence number mechanism for client-server sync

2. RocksDB Engine (internal/rocksdb/):
   - Implemented complete Txn() method with Raft support
   - Added txnUnlocked() for transaction execution
   - Implemented evaluateCompare() for condition evaluation
   - Added compareInt() and compareBytes() helper methods
   - Extended RaftOperation structure for transaction operations

3. Core Transaction Logic (internal/memory/store.go):
   - Implemented txnUnlocked() method for unlocked execution
   - Added evaluateCompare() for Compare condition evaluation
   - Created compareInt() and compareBytes() comparison helpers
   - Supports nested operations within transactions

4. Test Coverage:
   - Enabled TestTransaction (Memory single-node)
   - Enabled TestTransaction_RocksDB (RocksDB single-node)
   - Enabled TestEtcdMemoryClusterTransactionConsistency (Memory 3-node cluster)
   - Added TestEtcdRocksDBClusterTransactionConsistency (RocksDB 3-node cluster)

Test Results:
- TestTransaction (Memory single-node): PASS (0.11s)
- TestTransaction_RocksDB (RocksDB single-node): PASS (4.52s)
- TestEtcdMemoryClusterTransactionConsistency (Memory cluster): PASS (7.52s)
- TestEtcdRocksDBClusterTransactionConsistency (RocksDB cluster): PASS (8.66s)

Files Modified:
- internal/memory/kvstore.go (+81 lines): Transaction support with Raft
- internal/memory/store.go (+5 lines): Unlocked transaction execution
- internal/rocksdb/kvstore.go (+282 lines): Complete transaction implementation
- test/etcd_memory_consistency_test.go (-4 lines): Enable cluster transaction test
- test/etcd_compatibility_test.go (-2 lines): Enable RocksDB transaction test
- test/etcd_rocksdb_consistency_test.go (+38 lines): Add RocksDB cluster test

Breaking Changes: None

Compatibility:
- Fully compatible with etcd v3 client SDK
- Supports both Memory and RocksDB storage engines
- Works in single-node and cluster deployments
- Maintains backward compatibility with existing operations

Related Issues:
- Implements etcd Transaction feature from prompt/add_etcd_api_compatible_interface.md
- Fulfills requirement for Compare-Then-Else transaction semantics
- Ensures both storage engines have complete transaction support
@axfor axfor added the enhancement New feature or request label Oct 26, 2025
axfor added 2 commits October 27, 2025 07:10
Added comprehensive documentation analyzing the current state of etcd v3
API compatibility, including:

- Complete list of implemented interfaces (KV, Watch, Lease, Maintenance)
- Detailed feature coverage for each service
- Known defects and limitations (RaftTerm hardcoded, Leader detection, etc.)
- Missing services (Auth, Cluster management, Lock/Concurrency)
- Comparison with prompt requirements (65% compliance)
- Prioritized issue list (P0-P3)
- Both Chinese and English versions

Files:
- docs/ETCD_INTERFACE_STATUS.md (558 lines)
- docs/ETCD_INTERFACE_STATUS_EN.md (558 lines)
- README.md (updated documentation index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant