Commit graph

122 commits

Author SHA1 Message Date
Kostas Kyrimis
3031e7a3ee
fix: non reset fields in command config resetstat (#2425) 2024-01-17 08:21:39 +02:00
adiholden
014a86fc88
feat(lru): add generic lru class (#2351)
Signed-off-by: adi_holden <adi@dragonflydb.io>
2024-01-07 21:51:46 +02:00
Roman Gershman
1fb0a486ac
chore: transaction simplification (#2347)
chore: simplify transaction multi-locking

Also, add the ananlysis routine that determines whether the schewduled transaction is contended with other transaction in a
shard thread.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-12-31 17:02:12 +02:00
Shahar Mike
a360b308c9
refactor(server): Privatize PreUpdate() and PostUpdate() (#2322)
* refactor(server): Privatize `PreUpdate()` and `PostUpdate()`

While at it:
* Make `PreUpdate()` not decrease object size
* Remove redundant leftover call to `PreUpdate()` outside `DbSlice`

* Add pytest

* Test delete leads to 0 counters

* Improve test

* fixes

* comments
2023-12-25 07:49:57 +00:00
Roman Gershman
f90317a795
feat: add keyspace_mutations metric (#2329)
* feat: add keyspace_mutations metric

Currently we expose hits/misses for read only commands only (compatible with redis).
`keyyspace_mutations` complement this providing number of key operations for write commands.
It's interesting because now we can learn the number of key_ops vs API ops, where
key_ops = misses + hits + mutations

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

* chore: address fixes

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-12-24 10:21:36 +02:00
Yue Li
6905389d60
feat(server): Support CLIENT TRACKING subcommand (2/2) (#2280)
fixes https://github.com/dragonflydb/dragonfly/issues/2139

This is part two that implements the logic which notifies tracking clients by sending invalidation messages:

- The client tracking state is set by CLIENT TRACKING subcommand as well
as upon client disconnection.

- Track the keys of a readonly command by maintaining mapping that maps
keys to the sets of tracking clients.

- Send invalidation messages to clients when their tracked keys are
updated.

- Make PerformDeletion a member function of DbSlice, and send 
invalidation message within the function.

- Mock the function for sending invalidation message to avoid test
crash due to lack of real listener in the testing framework.

- Add functional (some) tests for client tracking based on the mocked interfaces.

---------

Signed-off-by: Yue Li <61070669+theyueli@users.noreply.github.com>
2023-12-21 04:40:21 -08:00
adiholden
6398a73942
fix(bug): access invalid prime table iterator (#2300)
The bug:
When running dragonfly in cache mode we bump up items on dash table when we find them. If we access few items on the callback that reside next to each other we will invalidate the first found iterator.

The fix:
After we bump up entry we insert the prime table ref to bump set. When checking if we can bump down an item we check the item is not in this set. Once we finish running the transaction callback we clear the set.

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-12-20 13:05:29 +02:00
Shahar Mike
6c32c8004d
refactor(server): Make FindFirst() read-only (#2317)
* refactor(DbSlice): Replace `FindExt()` with `FindMutable()` and `FindReadOnly`

* fix

* `ExpireConstIterator`

* Don't update stats on FindMutable()

* auto&

* FindFirst

* Remove old Find() method
2023-12-20 09:53:52 +02:00
Shahar Mike
0e4d76cc96
refactor(DbSlice): Replace FindExt() with FindMutable() and FindReadOnly (#2308)
* refactor(DbSlice): Replace `FindExt()` with `FindMutable()` and `FindReadOnly`

* fix

* `ExpireConstIterator`

* Don't update stats on FindMutable()

* auto&

* ReadOnly

* Remove redundant call

* move() before

* Remove redundant post_updater

* Update comment
2023-12-20 08:04:39 +02:00
Shahar Mike
dcedd1645e
feat(server): Convert DbSlice's AddOr* to return AutoUpdater (#2290)
* fix(server): Use AutoUpdater with AddOr* methods

* Remove explicit calls

* `operator=`

* return *this

* PostUpdate twice

* exp it

* bitops

* remove explicit `Run()`

* Explicitly `delete` copy ops

* Remove `AddOrSkip()`
2023-12-17 15:00:10 +02:00
Shahar Mike
8e10c5d88d
refactor(server): Refactor AddOrFind() (#2299)
* refactor(server): Reuse `PreUpdate()` internally

This actually fixes a bug where we did not handle tiering upon
expiration if found via `AddOrFind2()`.

Related to #2252

* Simplify code, remove optimization

* Don't do double lookups

* stats

* PreUpdate()--

* fixes
2023-12-17 10:37:54 +02:00
Shahar Mike
1ce3f983c9
WIP: Auto PostUpdate() (#2268)
* WIP: Auto `PostUpdate()`

* More `Find()` uses

* Final touches

* Fixes

* Fix bug and allow reassigning

* Rename to AutoUpdater

* Fix and add DCHECK

* Also check deletion count

* Use ccache instead of sccache

* Try to upgrade Helio

* off64_t

* off64_t

* Revert changes to CI
2023-12-11 10:07:53 +02:00
Yue Li
64bbfc7063
feat(server): Support CLIENT TRACKING subcommand (1/2) (#2277)
The client tracking state is set by CLIENT TRACKING subcommand as well
as upon client disconnection.

Track the keys of a readonly command by maintaining mapping that maps
keys to the sets of tracking clients.
2023-12-08 23:13:55 -08:00
adiholden
be82c11428
fix(tiering): fix crash when item was deleted before offloaded (#2225)
* fix(teiring): fix crash when item was deleted before offloaded

The bug: On insert key is inserted to bin peinding entries, if this key
was deleted we would check fail on finding this item when tring to flush
bin entries.

The fix: On every insert to bin pending entries erase pending entreis
which were delted or expired

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-12-07 20:38:23 +02:00
Vladislav
fd3fcdcbb4
fix(server): Unwatch keys during connection close (#2231) 2023-11-30 11:56:59 +02:00
Yue Li
00f1e3d578
feat(server): perform eviction upon memory pressure in cache mode (#2084)
* fixes #1936

Eviction Implementation
This patch provides a very simple eviction implementation for the interface mentioned above. In my opinion, the eviction algorithm approximates an LRU policy given that normal buckets always store the most recently accessed data while stash buckets are holding less active data.

The algorithm first selects a small set of segments as eviction targets. Starting from the last slot of the last stash bucket in each of the segments, we walk backward to evict key-value pairs stored in each visited slot. The eviction stopped either when a target memory release goal or the max number of evicted key-value pairs is reached. Therefore, we can upper bound the eviction time through the following two parameters that can be set when DF starts.  Note that these two parameters could be retrieved and changed by user through CONFIG GET and CONFIG SET commands.

---------

Signed-off-by: Yue Li <61070669+theyueli@users.noreply.github.com>
2023-11-01 11:11:27 -07:00
Uku Loskit
e9427dbbbc
feat: Implement options for EXPIRE command (#2051)
Add NX, XX, LT, GT options to EXPIRE, EXPIREAT, PEXPIRE and PEXPIREAT

Signed-off-by: Uku Loskit <ukuloskit@gmail.com>
2023-10-25 11:26:33 +03:00
Shahar Mike
67a4c4e6cb
feat(server): Add --lock_on_hashtags mode. (#1611)
* feat(server): Add `--lock_on_hashtags` mode.

This new mode effectively locks hashtags (i.e. strings within {curly
braces}) instead of the full keys being used.
This can allow scripts to access undeclared keys if they all use a
common hashtag, like for the case of BullMQ.

To make sure this mode is tested, I added a way to specify flags via env
variables, and modified `ci.yml` to run all tests using this mode as well.
While at it, I also added `--cluster_mode=emulated` mode to CI.
2023-08-03 20:13:36 +03:00
Roy Jacobson
4babed54d3
feat: Support atomic replica takeover (#1314)
* fix(server): Initialize ServerFamily with all listeners.

- Add a test for CLIENT LIST which is the visible result of this.

* use std move

* feat: Implement replicas take over

* Basic test

* Address CR comments

* Write a better test. Sadly it fails

* chore: Expose AwaitDispatches for reuse in takeover

* Ensure that no commands can execute during or after a takeover

* CR progress

* Actually disable the expiration

* Improve tests coverage

* Fix the dispatch waiting code

* Improve testing coverage and fix a shutdown snaphot bug

* don't replicate a replica
2023-07-02 16:11:28 +02:00
Kostas Kyrimis
99f3284910
feat(server): Add missing fields to INFO PERSISTENCE command (#1408) (#1438)
* Add loading field
* Add rdb_changes_since_last_save field
2023-06-21 23:35:36 +03:00
Vladislav
f97dbad6f9
feat: track update and delete for search (#1325)
Automatically update search indices

---------

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
2023-06-12 11:43:30 +03:00
adiholden
31043186d3
feat(cluster): cluster config delete now owned slots data (#1241)
* feat(cluster): cluster config delete now owned slots data

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-05-21 11:29:18 +03:00
Roy Jacobson
6697478a28
Feat bzpopmin (#1232)
* chore: Refactor out common code from BPop ops

* feat: Implement blocking ZSET commands

* Add tests for blocking ZSET commands.

* Refactor changes into container_utils
2023-05-21 03:48:45 +03:00
adiholden
f96a083473
feat(cluster): impl slot data delete (#1224)
* feat(cluster): impl slot data delete

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-05-17 11:59:41 +03:00
adiholden
8ae01dbea5
feat(cluser): support GETSLOTINFO (#1217)
feat(cluser): support GETSLOTINFO

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-05-16 14:58:11 +03:00
Roy Jacobson
8749d736dd
chore: Update comments and logs after debugging (#1129) 2023-04-25 08:37:23 +03:00
Roman Gershman
74e94ef9bb
feat: add oom insertion rejections (#1096) 2023-04-16 10:23:09 +03:00
Roman Gershman
0cbd5f0348
chore: remove fiber related names from the codebase (#1018)
Remove Boost.Fibers mentions and remove fibers_ext mentions.
Done in preparation to switch to helio-native fb2 implementation.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-03-31 13:33:20 +03:00
adiholden
d738d8d976
bug(snapshot): Fix unwriten entries in multiple snapshotting
* bug(snapshot): Multiple snapshots at the same time skips serializing some entries
---------

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-02-20 14:46:43 +02:00
Vladislav
2b40a7f324
feat(server): Check locks in heartbeat, allow multiple tx in replica (#815) 2023-02-17 16:50:44 +03:00
Vladislav
1eb227e318
feat(server): Rewrite journal commands (basic) (#651) 2023-01-16 14:52:46 +03:00
Roman Gershman
63b83c5b99
chore: Add tiered_storage_test. (#613)
1. Support tiered deletion.
2. Add notion of tiered entity in "DEBUG OBJECT" output.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-12-28 10:37:55 +02:00
ashotland
e39d266abe
fix(server):set of existing object with expiry (issue#607) (#609)
fix(server):set of existing object with expriy (issue#607)

Signed-off-by: ashotland <ari@dragonflydb.io>

Signed-off-by: ashotland <ari@dragonflydb.io>
2022-12-27 18:09:01 +02:00
ashotland
b48f7557b7
feat(server): track hits and misses stats. (#608)
feat: track hits and misses stats.

Signed-off-by: ashotland <ari@dragonflydb.io>
2022-12-27 13:57:23 +02:00
Vladislav
96c9332297
feat(server): Switch to stable state replication (#473)
* feat(server): Switch to stable state replication

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
2022-11-17 20:41:33 +02:00
Vladislav
b5cbed79d7
feat(server): Implement DFLY EXPIRE command (#404)
* feat(server): Implement DFLY EXPIRE command

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
2022-10-19 12:51:33 +03:00
cui fliter
4e651f8d0f
fix some typos (#398)
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-10-18 14:56:17 +03:00
Roman Gershman
ffc25e6ac2
chore(server): Refactor expire functionality and move it to DbSlice (#388)
This is preparation for https://github.com/dragonflydb/dragonfly/pull/387

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-10-14 13:14:09 +03:00
Roman Gershman
0925829afb feat(server): Introduce transaction clock.
Partially implements #6.
Before, each shard lazily updated its clock used for the expiry evaluation.
Now, the clock value is set during the transaction scheduling phase and is assigned
to each transaction. From now on DbSlice methods use this value when checking whether
the entry is expired via passed DbContext argument.

Also, implemented transactionally consistent TIME command and
verify that time is the same during the transaction. See
https://ably.com/blog/redis-keys-do-not-expire-atomically for motivation.

Still have not implemented any lamport style updates for background processes
(not sure if it's the right way to proceed).
2022-09-25 23:53:08 +03:00
Roman Gershman
de9369f518
chore(server): update license text (#312) 2022-09-19 09:01:10 +03:00
Vladislav
cb024a23ac
feat(server): Watch & Unwatch commands (#277)
* chore(server): Refactor ConnectionState & DbSlice for watched key support

* feat(server): Add WATCH & UNWATCH commands

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
Co-authored-by: Vladislav Oleshko <vlad@dragonflydb.io>
2022-09-13 19:14:11 +03:00
Roman Gershman
cfa1265b29 fix(server): fix a potential bug of loosing changes with multiple concurrent snapshots 2022-09-08 09:01:51 +03:00
Roman Gershman
4e4ed63467
feat(server): tighten memory checks when inseting a new object. (#258)
Before this change Dragonfly evicted items only when it was low on memory and had to grow its main dictionary.
It is not enough because in many cases Dragonfly can grow in memory even when the main dictionary does not grow.
For example, when its dictionary is less than 90% utilized, but the newly added objects require lots of memory.

In addition, the dashtable adds additional segments, when other segments have enough available slots to fill the rest of the free memory.

This change adds another layer of defense that allows evicting items even when dictionary segments are not full.
The eviction is still local with respect to a segment. On my tests it seems that it's much harder to cross maxmemory limit than before.

In addition, we tightened the heuristic that allowes the dashtable to grow. Now it takes into account the average bytes per item
in order to project how much memory the full table takes before adding to it new segments.
This really improves dashtable utilization.

There are still things to improve:
1. the eviction behavior is rough. Once an insert does the eviction it tries to free enough objects to bring memory back.
   This may result in very spiky insertion/eviction patterns.
2. The eviction procedure, even though it's limited to a single segment, is quite heavy because it goes over all buckets
   in the segment. This may result in weird artifacts where we evict just enough to be under the limit, then add and evict
   again and so on.
3. Therefore, we may need a periodic eviction that will compliment this emergency eviction step.

Fixes #224 and partially addresses #256

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-08-26 15:00:08 +03:00
Roman Gershman
cf991deb03 chore(server): add updateval_amount statistic.
This statistic helps understanding how much Dragonfly memory grows via updating the existing value vs the new ones.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-08-02 11:03:46 +03:00
Roman Gershman
05eb323a0d
fix(server): Fix #207 (#208)
1. Erase expiry data from the expire table in case of evictions.
2. Add test that covers the bug.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-07-15 15:14:20 +03:00
Roman Gershman
6b7d2a22df
chore(strings): Simplify Set flow (#164)
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-06-19 23:19:42 +03:00
Ryan Russell
eae5c08e76
Improve Comment Readability (#69)
Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-05-31 23:07:00 +03:00
Roman Gershman
c087f7c61b Update helio version. Add more gc related stats 2022-05-23 08:52:04 +03:00
Roman Gershman
c7d1893478 Add more documentation about dashtable. Tune expiry heuristics a bit 2022-05-21 20:35:19 +03:00
Roman Gershman
599c786c16 This CR fixes #36.
1. Fix a bug in dash table related to snapshotting.
2. Rewrite GlobalState code and make state transitions atomic and well defined.
3. Fix Save/Flush semantics by capturing snapshotted tables together with the snapshot.
2022-05-20 12:35:28 +03:00