Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 992e7c4

Browse files
author
Alex Gaetano Padula
committed
must export Operation struct fields for serialization. Fixes for TestWALRecovery tests and skiplist on TTL expiry should mark keys with tombstone value instead of actually deleting key.
1 parent 6d91813 commit 992e7c4

4 files changed

Lines changed: 865 additions & 153 deletions

File tree

README.md

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,30 @@ pkg: github.com/guycipher/k4
99
cpu: 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz
1010
BenchmarkK4_Put
1111
BenchmarkK4_Put-16 131302 8762 ns/op
12+
13+
RocksDB vs K4
14+
+=+=+=+=+=+=+=+=
15+
**RocksDB** 1 million writes sequential key-value pairs default settings = 2.9s-3.1s
16+
**K4** 1 million writes sequential key-value pairs default settings = 1.7s-1.9s
1217
```
1318

1419
### Features
20+
- High speed writes and reads
21+
- Durability
1522
- Variable length binary keys and values
1623
- Write-Ahead Logging (WAL)
1724
- Atomic transactions
18-
- Paired Compaction
25+
- Paired compaction
1926
- Memtable implemented as a skip list
2027
- Disk-based storage
2128
- Configurable memtable flush threshold
2229
- Configurable compaction interval (in seconds)
2330
- Configurable logging
2431
- Bloom filter for faster lookups
2532
- Recovery from WAL
33+
- Granular page locking
2634
- Thread-safe
27-
- Memtable TTL support
35+
- TTL support
2836
- No dependencies
2937

3038

@@ -66,11 +74,12 @@ txn.AddOperation(k4.DELETE, key, nil)
6674

6775
err = txn.Commit()
6876

69-
// Once committed you can rollback before the transaction is cleared
77+
// Once committed you can rollback before the transaction is removed
78+
// On commit error the transaction is automatically rolled back
7079
txn.Rollback()
7180

72-
// Clear the transaction
73-
txn.Clear() // txn now no longer usable nor existent
81+
// Remove the transaction after commit or rollback
82+
txn.Remove() // txn now no longer usable nor existent
7483

7584
```
7685

@@ -114,4 +123,67 @@ if err != nil {
114123

115124
```
116125
126+
### API
127+
```go
128+
129+
// Open a new K4 instance
130+
// you can pass extra arguments to configure memtable such as
131+
// args[0] = max level, must be an int
132+
// args[1] = probability, must be a float64
133+
func Open(directory string, memtableFlushThreshold int, compactionInterval int, logging bool, args ...interface{}) (*K4, error)
134+
135+
// Close the K4 instance gracefully
136+
func (k4 *K4) Close() error
137+
138+
// Put a key-value pair into the db
139+
func (k4 *K4) Put(key, value []byte, ttl *time.Duration) error
140+
141+
// Get a value from the db
142+
func (k4 *K4) Get(key []byte) ([]byte, error)
143+
144+
// Get all key-value pairs not equal to the key
145+
func (k4 *K4) NGet(key []byte) (map[string][]byte, error)
146+
147+
// Get all key-value pairs greater than the key
148+
func (k4 *K4) GreaterThan(key []byte) (map[string][]byte, error)
149+
150+
// Get all key-value pairs greater than or equal to the key
151+
func (k4 *K4) GreaterThanEq(key []byte) (map[string][]byte, error)
152+
153+
// Get all key-value pairs less than the key
154+
func (k4 *K4) LessThan(key []byte) (map[string][]byte, error)
155+
156+
// Get all key-value pairs less than or equal to the key
157+
func (k4 *K4) LessThanEq(key []byte) (map[string][]byte, error)
158+
159+
// Get all key-value pairs in the range of startKey and endKey
160+
func (k4 *K4) Range(startKey, endKey []byte) (map[string][]byte, error)
161+
162+
// Get all key-value pairs not in the range of startKey and endKey
163+
func (k4 *K4) NRange(startKey, endKey []byte) (map[string][]byte, error)
164+
165+
// Delete a key-value pair from the db
166+
func (k4 *K4) Delete(key []byte) error
167+
168+
// Begin a transaction
169+
func (k4 *K4) BeginTransaction() *Transaction
170+
171+
// Add a key-value pair to the transaction OPR_CODE can be PUT or DELETE
172+
func (txn *Transaction) AddOperation(op OPR_CODE, key, value []byte)
173+
174+
// Remove a transaction after it has been committed
175+
func (txn *Transaction) Remove(k4 *K4)
176+
177+
// Rollback a transaction (only after commit or error)
178+
func (txn *Transaction) Rollback(k4 *K4) error
179+
180+
// Commit a transaction
181+
func (txn *Transaction) Commit(k4 *K4) error
182+
183+
// Recover from WAL file
184+
// WAL file must be placed in the data directory
185+
func (k4 *K4) RecoverFromWAL() error
186+
```
187+
188+
117189

0 commit comments

Comments
 (0)