EchoVault / SugarDB

Embeddable and distributed in-memory alternative to Redis.
https://sugardb.io
Apache License 2.0
404 stars 21 forks source link

RAFT #82

Open smeadows-okta opened 3 months ago

smeadows-okta commented 3 months ago

I need to run within single node and multi-node environment without reconfiguring. The following messages occur during single node environment and no caching is happening

2024-06-26T16:32:52.327-0400 [INFO] raft: initial configuration: index=1 servers="[{Suffrage:Voter ID:01J1B3A78G06A0HWM86QZYAVB8 Address:localhost:7481}]"

2024-06-26T16:32:52.327-0400 [INFO] raft: entering follower state: follower="Node at 127.0.0.1:7481 [Follower]" leader-address= leader-id=

2024-06-26T16:32:55.204-0400 [WARN] raft: heartbeat timeout reached, not part of a stable configuration or a non-voter, not triggering a leader election

2024/06/26 17:11:14 deleted key 3491595662 2024/06/26 17:11:14 1 keys sampled, 1 keys deleted 2024/06/26 17:11:14 deletion ratio (100 percent) reached threshold (20 percent), sampling again

can you explain EvictionInterval, EvictionSample, and SET EX and how they relate to each other. i have 64mb cache allocated, and the cache contain 2 messages of 1024. Please explain deletion ratio (100 percent) reached threshold (20 percent), sampling again

kelvinmwinuka commented 3 months ago

Hi @smeadows-okta could you please share your configurations so I can attempt to reproduce this?

1) EvictionInterval determines the interval between attempts to evict expired keys. 2) EvictionSample is the number of keys that will be checked for expiry when the node is attempting evicting keys. 3) SET EX allows you to create a key and define its expiry/TTL at the same time. This particular variant sets the number the keys TTL in seconds.

During this sampling, if enough keys are expired and evicted, then the eviction sampling will immediately run again without waiting for the interval. This process continues until the number of evicted keys is below the threshold (in this case, 20 percent of total keys) or there are no more keys left to evict (because the store is empty).

In your example, it seems the 2 keys you set where evicted upon expiry, and because you only had to keys, that was a 100 percent eviction rate so the eviction sampling was restarted. The next round of resampling would have no more keys to delete so the sampling will return to waiting for the interval.

smeadows-okta commented 3 months ago

I've allocated 32MB
config := echovault.DefaultConfig()
config.BootstrapCluster = true
config.MaxMemory = 32 << 20
config.EvictionPolicy = "allkeys-lru"
config.DataDir = "/var/echovault"

it appears EchoVault runs standalone or raft mode. In raft mode, when no other node can be contacted with in specified time, no caching can occur?  Also, I think some of the Raft configuration options should be exposed, especially time frame it takes nodes to form a consensus.