Commit graph

35 commits

Author SHA1 Message Date
Roman Gershman
7a68528022
chore: minor refactorings around dense_set deletions (#4390)
chore: refactorings around deletions

Done as a preparation to introduce asynchronous deletions for sets/zsets/hmaps.
1. Restrict the interface around DbSlice::Del. Now it requires for the iterator to be valid and the checks should
be explicit before the call. Most callers already provides a valid iterator.

2. Some minor refactoring in compact_object_test.
3. Expose DenseSet::ClearStep to allow iterative deletions of elements.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2025-01-02 11:35:55 +02:00
Kostas Kyrimis
a012539f2c
fix: remove DenseSet::IteratorBase::TraverseApply (#4170)
Signed-off-by: kostas <kostas@dragonflydb.io>
2024-11-23 18:21:50 +02:00
Kostas Kyrimis
4859077122
chore(DenseSet): defrag all links in a chain (#4019)
* add defrag for all nodes in a link chain
* add tests

---------

Signed-off-by: kostas <kostas@dragonflydb.io>
2024-11-04 08:34:22 +00:00
Roman Gershman
c895b96274
fix: keep the ttl bit when dense_set grows with expiring items (#3995)
Add a test that triggerred a corner case with assertion failure.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-25 22:29:54 +03:00
Roman Gershman
5ce3d82663
fix: properly set ttl bit during object replacement (#3991)
fixes #3984

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-24 23:47:37 +03:00
Roman Gershman
a4659c0843
fix: properly set object with DenseLinkKey (#3980)
The interface around DenseLinkKey is confusing but SetObject
works only for non-link objects.
Added assert to catch these issues in the future.

Fixes #3973

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-24 08:38:43 +00:00
Roman Gershman
07e0b9db4b
chore: ClearInternal now can clear partially (#3867)
* chore: ClearInternal now can clear partially

Intended for future use - to deallocate large objects gradually.
Currently nothing is changed in the functionality besides some cleanups.
---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-04 22:50:43 +03:00
Roman Gershman
bd972b6384
chore: Implement AddMany method (#3866)
* chore: Implement AddMany method

1. Fix a performance bug in Find2 that made redundant comparisons
2. Provide a method to StringSet that adds several items in a batch
3. Use AddMany inside set_family

Before:
```
BM_Add        4253939 ns      4253713 ns          991
```

After:
```
BM_Add        3482177 ns      3482050 ns         1206
BM_AddMany    3101622 ns      3101507 ns         1360
```

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

* chore: fixes

---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-04 22:50:05 +03:00
Roman Gershman
a86fcf80be
chore: Remove DenseSet::AddOrFindDense and AddSds (#3864)
Clean up interface a bit. AddOrFindDense does not make much sense as a single function
because it does not provide any performance benefits - we still must perform a lookup
before inserting. AddSds should have been removed a long time ago.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-04 17:14:49 +03:00
Roman Gershman
2e1d81ac80
chore: improve performance of ClearInternal (#3863)
Before:
`BM_Clear/elements:32000     418763 ns       418749 ns         9965`

After:
`BM_Clear/elements:32000     323252 ns       323239 ns        12790`

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-04 14:26:25 +03:00
Roman Gershman
819f6e125d
chore: simplify CloneBatch code (#3862)
Remove awkward fetch_tail case and streamline the code.
Fix invalid prefetch adresses. Performance improved a little.

Before:
`BM_Fill/elements:32000     874677 ns       874647 ns         4774`

After:
`BM_Fill/elements:32000     831786 ns       831761 ns         5111`

Also added a benchmark for Clear() operation.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-10-04 12:08:41 +03:00
Joakim Rishaug
2ab480e160
add dense_set.SetExpiryTime in preparation for fieldexpire (#3780)
* feat: add DenseSet::IteratorBase::SetExpiryTime

This commit is in preparation for adding FIELDEXPIRE and HEXPIRE.

* fix: 0 is a valid input for MakeSetSds
2024-10-01 08:36:00 +00:00
Roman Gershman
abf3acec4a
chore: introduce a Clone function for the dense set (#3740)
* chore: introduce a Clone function for the dense set

We use a state machine to prefetch data in batches.
After this change, the hot spots are predominantly inside ObjectClone and
Hash methods.

All in all benchmarks show ~45% CPU reduction:
```
BM_Clone/elements:32000    1517322 ns      1517338 ns         2772
BM_Fill/elements:32000      841087 ns       841097 ns         4900
```

---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-09-19 16:14:33 +03:00
Shahar Mike
4929e3c777
feat(server): Better accounting of DenseSet memory (#2325) 2023-12-21 19:26:16 +02:00
Shahar Mike
d15bcf8392
fix(server): Save element expirations for hash sets & sets (#2223)
* fix(server): Save element expirations for hash sets

* Add support for sets

* Fixes

* Fixes
2023-11-30 14:08:04 +02:00
Shahar Mike
7e23c14c35
fix(DenseSet): Rename Size() to UpperBoundSize() and add SizeSlow() (#2130)
Then use the right version (hopefully) in the right places.

Specifically, this fixes a serialization bug, where we could send
malformed responses when using `UpperBoundSize()` to write array length.
2023-11-06 08:52:08 +02:00
Roman Gershman
47d92fb010
fix: Correctly grow dense_set in the Reserve call (#2087)
Fixes #2066

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-10-29 08:39:33 +02:00
Roman Gershman
215c037e41
feat: implement fieldttl for the hash family (#2040)
Fix some corner case bug with set family as well.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-10-20 21:51:24 +03:00
Roman Gershman
c6946d561c
feat: add fieldttl command that returns the ttl of the member (#2026)
Currently implemented only for saddex.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-10-16 12:12:00 +03:00
Roman Gershman
acc00b77b3
feat: allow extracting the expiry time from string_set (#2020)
We introduce `iterator Find(member)` function
as well as iterator members to actually get the expiry time.
2023-10-15 09:56:17 +03:00
Roman Gershman
00ee506cc8
chore: performance improvements around zset (#1928)
1. ExpireIfNeeded was unjuistifiedly high in the profile topk table.
   Lets make the initial condition within an inline to reduce its impact.
2. Reserve space for hmap/zset if multiple items are added.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-09-25 20:04:59 +03:00
Roman Gershman
4fccda65cf
chore: remove redundant Find calls when inserting into DenseSet (#1917)
A regular DenseSet insertion first checks for uniqueness and then inserts a new element.
Sometimes we know that the new element is new and we can insert it without checking for
uniqueness first.

Also, pass hashcode into internal functions so we could save some hash calls.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-09-22 22:48:06 +03:00
Roman Gershman
cf1ac87156
chore: fix some of FreeBsd compile issues. (#1374)
1. Use experimental/memory_resource because clang on freebsd does not support yet std::memory_resource
2. Pull latest helio with all the compatibility fixes.
3. Replace linux only SOL_TCP constant with IPPROTO_TCP (same value).
4. Fix build files to work on FreeBsd system.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-06-11 23:22:56 +03:00
Roman Gershman
f92403fb09
feat(core): Add Ttl semantics to string_map (#813)
Now string_map respects the optional ttl argument that accepts ttl time in seconds.
Upon traversing and accessing expirerd elements they will be transparently removed and deleted
from the map.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-02-17 10:49:21 +02:00
Roman Gershman
5d34f271e9 feat(server): Extend string_map api, fix AddOrSet method.
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-12-24 17:21:57 +02:00
Roman Gershman
9375a48f71 feat(core): Add StringMap data structure.
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-12-24 17:21:57 +02:00
Kavinli
e9380f24d0
fix: DCHECK_NOTNULL gets WARNING when return value is not used. (#483)
Signed-off-by: Super-long <0x4f4f4f4f@gmail.com>
2022-11-13 08:09:21 +02:00
adiholden
97057cadcf
bug(dense set): fix scan function to return only home bucket data (#474)
dense set: fix scan function to return only home bucket data

Signed-off-by: adi_holden <adi@dragonflydb.io>
2022-11-10 19:24:31 +02:00
Roman Gershman
d2b216077d
feat(setfamily): Add SADDEX command (#348)
Add SADDEX <key> <seconds> member member ....
Provides expiry semantics for set members with seconds resolution.

Important things to note:
1. The expiry is passive only, so if nobody touches that set then its members are being kept.
2. SCARD provides an upper bound estimation of set size for sets holding the expiring members.
   The reason for this is because SCARD returns a cached size and does not go over all members
   to check whether they expired. For regular sets it's exact, of course.

Fixes #335
2022-10-03 13:15:27 +03:00
Roman Gershman
08779b154b
Add expiry semantics to the set. (#340) 2022-10-01 19:45:19 +03:00
Roman Gershman
44f98de128
chore(denseset): Simplify DenseSet, remove empty links. (#339) 2022-10-01 06:58:37 +03:00
Roman Gershman
2686b9316a
chore(DenseSet): Some code reorder without change in functionality. (#338) 2022-09-29 16:13:55 +03:00
Roman Gershman
de9369f518
chore(server): update license text (#312) 2022-09-19 09:01:10 +03:00
Ryan Russell
231ef3d367
docs(src/core): readability improvements (#293)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-14 15:30:05 +03:00
Braydn
b8d791961e
feat(core): Added DenseSet and StringSet types (#268)
* feat(core): Added DenseSet & StringSet types with docs

- Improved documentation by adding labels to chain types & pointer tagging table
- Added potential improvements to the DenseSet types in the docs
- Added excalidraw save file for future editing
- Removed ambiguous overloading types
- Renamed iterators to be more clear


* feat(core): Cleaned up DenseSet and Docs
* feat(core): Made DenseSet more ergonomic
* feat(server): Integration of DenseSet into Server

- Integrated DenseSet with CompactObj and the Set Family commands

Signed-off-by: Braydn <braydn.moore@uwaterloo.ca>
2022-09-14 08:41:54 +03:00