Commit graph

153 commits

Author SHA1 Message Date
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
Roman Gershman
d88b2422de
chore: eliminate most of clang++ warnings (#2288)
Not all of them but 90% is done.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-12-11 12:47:53 +02:00
adiholden
dc3bc9e92f
fix(tiering): fix tiering crash on setting expire (#2285)
fixes #2224
the bug: when updateing entry pre update will resets the PrimeValue if
this is an external entries leading to crash if we insert entries with expire
time.

the fix: reserve the expire mask in PrimeValue on pre update

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-12-11 10:29:12 +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
Shahar Mike
636507c356
feat(server): Return per-type memory breakdown from INFO and /metrics (#2262)
* feat(server): Return per-type memory breakdown from INFO and /metrics

* OBJ_TYPE_MAX

* Move AddTypeMemoryUsage, use it from TieredStorage

* Remove strval_memory_usage

* Remove redundant strval_bytes

---------

Signed-off-by: Shahar Mike <chakaz@users.noreply.github.com>
2023-12-07 21:37:09 +02: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
Shahar Mike
b9781c4903
fix(test): Don't access null pointer (#2126)
This caused a UBSan warning to be printed in test `DflyEngineTest.Bug207`

```
/usr/include/c++/11/bits/stl_vector.h:1046:34: runtime error: reference binding to null pointer of type 'struct value_type'
```
2023-11-05 13:31:28 +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
Vladislav
474ea5137a
fix(replica): fix replica reconnect handing (#2068)
* fix(replica): fix replica reconnect handing

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>

---------

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
2023-10-27 11:12:55 +03: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
Roman Gershman
4be9551806
chore: adjust verbosity level 1 not be over-verbose in prod (#1974)
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-10-01 14:31:39 +03:00
Kostas Kyrimis
91e8ead6d1
fix(dragonfly_test): failing bug207 on build opt (#1919)
The issue was that the Heartbeat would run every 1ms and this is problematic because the for-loop would take less than 1ms to finish. Therefore, the memory pool would not adjust and items would not be evicted from the store. By doubling the amount of elements created in the for-loop, we give enough time for the first heartbeat to run and adjust the memory available (which will cause the evictions to happen).
2023-09-25 08:02:53 +00:00
Roman Gershman
8d1474aeac
fix: improve performance of listpack sorted sets (#1885)
1. Cherry-pick changes from Redis 7 that encode integer scores more efficiently
2. Introduces optimization that first checks if the new element should be the last
   for listpack sorted sets.
3. Consolidates listpack related constants and tightens usage for listpack.
4. Introduce MEMORY USAGE command.
5. Introduce a small delay before decommitting memory pages back to OS.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-09-19 19:52:34 +03:00
adiholden
ac3b8b2b74
fix(server): Dont apply memory limit when loading/replicating (#1760)
* fix(server): Dont apply memory limit when loading/replicating

When loading a snapshot created by the same server configuration (memory and
number of shards) we will create a different dash table segment directory tree, because the
tree shape is related to the order of entries insertion. Therefore when loading data from
snapshot or from replication the conservative memory checks might fail as the new tree might
have more segments. Because we dont want to fail loading a snapshot from the same server
configuration we disable this checks on loading and replication.

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-09-03 11:24:52 +03:00
adiholden
6aaa0ee072
feat(server): support multi eval in lock ahead mode (#1662)
* feat(server): support multi eval in lock ahead mode

1. remove validation to allow multi eval only in global script mode
2. send error if there is a mode conflict when running eval inside multi
3. reset uniqe_keys_ when transaction finishes
2023-08-27 09:13:22 +03:00
Roman Gershman
e4ea868175
fix: Fix inconsistency when deleting dash entries (#1734)
Partially addresses #1730.

Beforehand we removed entries from mcflag only inside DbSlice::Del function
but we delete entries in other cases too (like expiration) and in this case we left
dangling entries in mcflag table. The fix adds the deletion of mcflag entries into PerformDeletion function.

It by itself does not explain the crash but
dangling entries cause UB (because the keys are references to non-existent PrimeKeys)
so maybe this somehow causes inconsistency where a key is not present in mcflags.

I am not sure I fixed the original issue but I surely fixed a corruption bug.
In addition, I removed the redundant check fail and added error logs to follow up on this later.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-08-24 17:02:02 +03:00
Vladislav
d8ab016792
feat: Update search index on expiry (#1697)
Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
2023-08-16 16:25:59 +03:00
Roy Jacobson
4001a94b22
chore: Add names to fibers that were missing them (#1667) 2023-08-08 13:01:50 +02: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
Shahar Mike
ef55713dfc
feat(server): Use hashtags for sharding in emulated cluster mode. (#1602)
This PR would have been 1 line change instead of 11 files, but it
required some plumbing and refactoring:
* Now ClusterConfig is aware of emulated cluster mode
* As a result, this API was moved from ClusterFamily
* And so was the flag & its parsing
* ClusterFamily doesn't need is_emulated_cluster_ member
* ServerFamily no longer needs ClusterFamily* member (because the API is
  static)
* I also changed `ClusterConfig::IsClusterEnabled()` to
  `ClusterConfig::IsEnabled()` to be shorter
2023-07-31 13:55:47 +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
adiholden
5b95668676
bug(cluster): fix crash on flush slots with shutdown (#1477)
* bug(cluster): fix crash on flush slots with shutdown

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-06-26 09:39:59 +03: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
Chaka
82c8906eb7
feat(cluster): Add total_reads and total_writes to GETSLOTSINFO. (#1355)
While at it, modify response such that it returns numbers instead of strings for numerical values.
2023-06-05 21:46:02 +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
adiholden
7f56a435c4
bug(server): replicate scripts in stable state (#1114)
* bug(server): replicate scripts in stable state

---------

Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-04-23 23:46:51 +03:00
Roy Jacobson
6632261a2d
fix(server): Prevent preemption inside SerializeBucket (#1111)
* fix(server): Prevent preemption inside SerializeBucket

* Modifications after speaking to Adi
2023-04-20 10:27:47 +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
Roman Gershman
12abe0bc12
chore: update helio dependency (#984)
Also remove direct references for boost fibers from the code.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-03-24 18:04:05 +03:00
chakaz
e9f5039665 feat(server): Introduce and use TopKeys class.
TopKeys uses a custom implementation of HeavyKeeper to track top (hot)
keys usage for debugging purposes.
This commit also integrates TopKeys (default off) into DbTable and counts
usage of (present) key lookups.

Signed-off-by: chakaz <chakaz@chakaz>
2023-03-18 15:27:39 +02:00
chakaz
9add31e20f Get DragonDB to compile with clang.
While at it, fix some compile warnings, 2 of them are actual bugs
(missing virtual d'tor).

Signed-off-by: chakaz <chakaz@chakaz>
2023-03-18 11:02:37 +02:00
adiholden
6a2b152e8b
feat(db slice): add fiber atomic gaurd (#878)
Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-02-26 13:38:37 +02: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
4ef06e759a
Basic multi modes for MULTI/EXEC (#796)
feat(server): Basic multi transaction modes

This commit adds the notion of multi transaction modes that allow controlling the execution and
locking behaviour of multi transactions.
In general, there are four modes:
- GLOBAL: all commands run within a global transaction. There is no need for recording locks. Lua scripts can theoretically run with undeclared keys.
- LOCK_AHEAD: the transaction locks all keys ahead likewise to a regular transaction and schedules itself.
- LOCK_INCREMENTAL: the transaction determines what shards it has keys in and schedules itself on those shards, but locks only when accessing a new key. This allows other transactions to run ooo alonside with a big multi-transaction that accesses a contended key only at its very end.
- NON_ATOMIC: all commands run separately, no atomicity is provided, likewise to a pipeline

This commit only adds support for the first 3 modes to EXEC commands.

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
2023-02-18 20:18:28 +03:00
Vladislav
2b40a7f324
feat(server): Check locks in heartbeat, allow multiple tx in replica (#815) 2023-02-17 16:50:44 +03:00
adiholden
d30ebc5b0d
feat(server): replication should not evict items (#743)
Signed-off-by: adi_holden <adi@dragonflydb.io>
2023-02-05 09:04:08 +02:00
Vladislav
4c9b30ca43
feat(server): Auto expiry + small replica refactor (#718) 2023-01-31 12:55:52 +03:00
Boaz Sade
5af6ee9b27
fix(server): fix getex command with persist can get time overflow (#707)
Signed-off-by: Boaz Sade <boaz@dragonflydb.io>

Signed-off-by: Boaz Sade <boaz@dragonflydb.io>
2023-01-19 18:41:32 +02:00
Vladislav
45162b5c0a
feat(server): Journal rewrite p2 + tests (#699) 2023-01-19 13:55:50 +03:00
Vladislav
1eb227e318
feat(server): Rewrite journal commands (basic) (#651) 2023-01-16 14:52:46 +03:00