m1.2 : Added TTL support - #8
Conversation
| } | ||
| } | ||
|
|
||
| func (s *Store) StartExpire(ctx context.Context) { |
There was a problem hiding this comment.
where is this method called?
There was a problem hiding this comment.
sorry missed this added in main.go
| s.mu.RLock() | ||
| snapshot := s.tree | ||
| s.mu.RUnlock() |
There was a problem hiding this comment.
snapshot := s.tree -> does this create a copy?
If not, what purpose does the Rlock serve?
There was a problem hiding this comment.
The iradix returns a reference to the current tree version. The RLock ensures no concurrent writes modify s.tree while we're reading the reference. Once we have the reference, we can safely release the lock because the tree is immutable.
| snapshot.Root().Walk(func(key []byte, value entry) bool { | ||
| if runs >= sampleSize { | ||
| return true | ||
| } | ||
| if value.expireAt > 0 && value.expireAt < time.Now().Unix() { | ||
| expiredKeys = append(expiredKeys, string(key)) | ||
| expiredCount++ | ||
| } | ||
| runs++ | ||
| return false | ||
| }) |
There was a problem hiding this comment.
If we stop walking when runs >= sampleSize, will we be able to reach expired nodes always? Shouldn't we check expiredCount here instead?
There was a problem hiding this comment.
correct point, changed the approach to a last pointer tracking which helps us to make sure we cover the entire tree
|
|
||
| store.Delete(cmd.Args[0]) | ||
| return "OK" | ||
| case "EXPIRE": |
There was a problem hiding this comment.
need to handle writing to wal for expire and setex commands. Also replay for these commands needs to take care of the ttl.
There was a problem hiding this comment.
WAL entry: "SETEX mykey 60 myvalue" // 60 seconds TTL
Written at: 10:00:00 AM
Server crashes at: 10:00:30 AM (key should expire at 10:01:00 AM)
Server restarts at: 11:00:00 AM (1 hour later)
Problem: We only have "60 seconds" in WAL, not the absolute time "10:01:00 AM"
Iss replay ko kaiser handle karre?? TS bei daale kya??
There was a problem hiding this comment.
Instead of writing the ttl, we can write the absolute time when it is supposed to expire. During replay just compare with current time and process accordingly.
|
@SantanuKar43 can u merge this please? |
No description provided.