Skip to content

Commit 35db373

Browse files
committed
fix rebase issues
Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
1 parent 274f72f commit 35db373

6 files changed

Lines changed: 15 additions & 200 deletions

File tree

src/db.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,13 @@ static int objectIsExpired(robj *val) {
19671967
static int keyIsExpiredWithDictIndexImpl(serverDb *db, robj *key, int dict_index) {
19681968
/* Don't expire anything while loading. It will be done later. */
19691969
if (server.loading) return 0;
1970+
mstime_t when = getExpireWithDictIndex(db, key, dict_index);
1971+
return timestampIsExpired(when);
1972+
}
1973+
1974+
/* Check if the key is expired. */
1975+
static int keyIsExpiredWithDictIndex(serverDb *db, robj *key, int dict_index) {
1976+
if (!keyIsExpiredWithDictIndexImpl(db, key, dict_index)) return 0;
19701977

19711978
/* See expireIfNeededWithDictIndex for more details. */
19721979
if (server.primary_host == NULL && server.import_mode) {

src/expire.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -827,31 +827,6 @@ int convertExpireArgumentToUnixTime(client *c, robj *arg, long long basetime, in
827827
return C_OK;
828828
}
829829

830-
int convertExpireArgumentToUnixTime(client *c, robj *arg, long long basetime, int unit, long long *unixtime) {
831-
long long when;
832-
if (getLongLongFromObjectOrReply(c, arg, &when, NULL) != C_OK) return C_ERR;
833-
834-
if (when < 0) {
835-
addReplyErrorExpireTime(c);
836-
return C_ERR;
837-
}
838-
839-
if (unit == UNIT_SECONDS) {
840-
if (when > LLONG_MAX / 1000 || when < LLONG_MIN / 1000) {
841-
addReplyErrorExpireTime(c);
842-
return C_ERR;
843-
}
844-
when *= 1000;
845-
}
846-
if (when > LLONG_MAX - basetime) {
847-
addReplyErrorExpireTime(c);
848-
return C_ERR;
849-
}
850-
when += basetime;
851-
if (unixtime) *unixtime = when;
852-
return C_OK;
853-
}
854-
855830
/*-----------------------------------------------------------------------------
856831
* Expires Commands
857832
*----------------------------------------------------------------------------*/

src/hashtable.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,6 @@ static void compactBucketChain(hashtable *ht, size_t bucket_index, int table_ind
886886
}
887887
}
888888

889-
static inline hashtableElementAccessState accessElementIfNeeded(hashtable *ht, void *elem) {
890-
if (ht->type->accessElement == NULL) return ELEMENT_VALID;
891-
return ht->type->accessElement(ht, elem);
892-
}
893-
894889
/* Find an empty position in the table for inserting an entry with the given hash. */
895890
static bucket *findBucketForInsert(hashtable *ht, uint64_t hash, int *pos_in_bucket, int *table_index) {
896891
int table = hashtableIsRehashing(ht) ? 1 : 0;
@@ -2045,9 +2040,6 @@ int hashtableNext(hashtableIterator *iterator, void **elemptr) {
20452040
/* No entry here. */
20462041
continue;
20472042
}
2048-
if (!(iter->flags & HASHTABLE_ITER_AVOID_ACCESS) && accessElementIfNeeded(iter->hashtable, b->entries[iter->pos_in_bucket]) != ELEMENT_VALID) {
2049-
continue;
2050-
}
20512043
if (!(iter->flags & HASHTABLE_ITER_SKIP_VALIDATION) && validateElementIfNeeded(iter->hashtable, b->entries[iter->pos_in_bucket]) != ENTRY_VALID) {
20522044
continue;
20532045
}

src/server.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,6 @@ size_t hashHashtableTypeMetadataSize(void) {
679679

680680
extern hashtableEntryValidationState hashHashtableTypeValidate(hashtable *ht, void *entry);
681681

682-
size_t hashHashtableTypeMetadataSize(void) {
683-
return sizeof(void *);
684-
}
685-
686-
extern hashtableElementAccessState hashHashtableTypeAccess(hashtable *ht, void *entry);
687-
688682
hashtableType hashHashtableType = {
689683
.hashFunction = dictSdsHash,
690684
.entryGetKey = hashHashtableTypeGetKey,
@@ -702,15 +696,6 @@ hashtableType hashWithVolatileItemsHashtableType = {
702696
.validateEntry = hashHashtableTypeValidate,
703697
};
704698

705-
hashtableType hashWithVolatileItemsHashtableType = {
706-
.hashFunction = dictSdsHash,
707-
.entryGetKey = hashHashtableTypeGetKey,
708-
.keyCompare = hashtableSdsKeyCompare,
709-
.entryDestructor = hashHashtableTypeDestructor,
710-
.getMetadataSize = hashHashtableTypeMetadataSize,
711-
.accessElement = hashHashtableTypeAccess,
712-
};
713-
714699
/* Hashtable type without destructor */
715700
hashtableType sdsReplyHashtableType = {
716701
.hashFunction = dictSdsCaseHash,

src/server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,6 @@ struct valkeyServer {
17001700
* Value: RDB client object
17011701
* This structure holds dual-channel sync replicas from the start of their
17021702
* RDB transfer until their main channel establishes partial synchronization. */
1703-
keyAccessContext access_context; /* The current key access context */
17041703

17051704
client *current_client; /* The client that triggered the command execution (External or AOF). */
17061705
client *executing_client; /* The client executing the current command (possibly script or module). */

src/t_hash.c

Lines changed: 8 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@
3636
#include "rax.h"
3737
#include "sds.h"
3838
#include "volatile_set.h"
39-
// #include "server.h"
39+
#include "server.h"
4040
#include "zmalloc.h"
4141
#include <math.h>
4242
#include <string.h>
4343
#include "entry.h"
4444

45-
#include "server.h"
46-
4745

4846
int hashTypeExpireEntry(entry *entry);
4947

@@ -110,129 +108,6 @@ static void hashTypeDeleteVolatileSet(robj *o) {
110108
hashTypeIgnoreTTL(o, true);
111109
}
112110

113-
void hashTypeTrackEntry(robj *o, void *entry) {
114-
volatile_set *set = hashTypeGetOrcreateVolatileSet(o);
115-
serverAssert(volatileSetAddEntry(set, entry, entryGetExpiry(entry)));
116-
}
117-
118-
void hashTypeUntrackEntry(robj *o, void *entry) {
119-
if (!entryHasExpiry(entry)) return;
120-
volatile_set *set = hashTypeGetVolatileSet(o);
121-
debugServerAssert(set);
122-
serverAssert(volatileSetRemoveEntry(set, entry, entryGetExpiry(entry)));
123-
if (volatileSetNumEntries(set) == 0) {
124-
hashTypeDeleteVolatileSet(o);
125-
}
126-
}
127-
128-
static void hashTypeTrackUpdateEntry(robj *o, void *old_entry, void *new_entry, long long old_expiry, long long new_expiry) {
129-
int old_tracked = (old_entry && old_expiry != EXPIRY_NONE);
130-
int new_tracked = (new_entry && new_expiry != EXPIRY_NONE);
131-
/* If entry was not tracked before and not going to be tracked now, we can simply return */
132-
if (!old_tracked && !new_tracked)
133-
return;
134-
135-
volatile_set *set = hashTypeGetOrcreateVolatileSet(o);
136-
debugServerAssert(set);
137-
if (entryHasValuePtr(entry)) {
138-
/* In case the value is not embedded we might not be able to sum all the allocation sizes since the field
139-
* header could be too small for holding the real allocation size. */
140-
mem += zmalloc_usable_size(hashTypeEntryAllocPtr(entry));
141-
} else {
142-
mem += sdsReqSize(sdslen(entry), sdsType(entry));
143-
if (entryHasExpiry(entry)) mem += sizeof(long long);
144-
}
145-
mem += sdsAllocSize(hashTypeEntryGetValue(entry));
146-
return mem;
147-
}
148-
149-
if (old_tracked && !new_tracked)
150-
serverAssert(volatileSetRemoveEntry(set, old_entry, old_expiry));
151-
else if (new_tracked && !old_tracked)
152-
serverAssert(volatileSetAddEntry(set, new_entry, new_expiry));
153-
else {
154-
volatile_set *set = hashTypeGetVolatileSet(o);
155-
debugServerAssert(set);
156-
serverAssert(volatileSetUpdateEntry(set, old_entry, new_entry, old_expiry, new_expiry) == 1);
157-
}
158-
if (volatileSetNumEntries(set) == 0) {
159-
hashTypeDeleteVolatileSet(o);
160-
}
161-
}
162-
163-
int hashTypeExpireEntry(void *entry) {
164-
// TBD
165-
UNUSED(entry);
166-
return 1;
167-
}
168-
169-
hashtableEntryValidationState hashHashtableTypeValidate(hashtable *ht, void *entry) {
170-
UNUSED(ht);
171-
expirationPolicy policy = getExpirationPolicyWithFlags(0);
172-
if (policy == POLICY_IGNORE_EXPIRE) return ENTRY_VALID;
173-
174-
if (!entryIsExpired(entry)) return ENTRY_VALID;
175-
176-
return ENTRY_INVALID;
177-
}
178-
179-
/*-----------------------------------------------------------------------------
180-
* Hash type Expiry API
181-
*----------------------------------------------------------------------------*/
182-
183-
static volatile_set *hashTypeGetVolatileSet(robj *o) {
184-
serverAssert(o->encoding == OBJ_ENCODING_HASHTABLE);
185-
return *(volatile_set **)hashtableMetadata(o->ptr);
186-
}
187-
188-
void hashTypeFreeVolatileSet(robj *o) {
189-
volatile_set *set = hashTypeGetVolatileSet(o);
190-
if (set)
191-
freeVolatileSet(set);
192-
}
193-
194-
int hashTypeHasVolatileElements(robj *o) {
195-
return ((o->encoding == OBJ_ENCODING_HASHTABLE) && (hashTypeGetVolatileSet(o) != NULL));
196-
}
197-
198-
size_t hashTypeNumVolatileElements(robj *o) {
199-
if (hashTypeHasVolatileElements(o)) {
200-
return volatileSetNumEntries(hashTypeGetVolatileSet(o));
201-
}
202-
return 0;
203-
}
204-
205-
void hashTypeIgnoreTTL(robj *o, int ignore) {
206-
if (o->encoding == OBJ_ENCODING_HASHTABLE) {
207-
/* prevent placing access function if not needed */
208-
if (!ignore && !hashTypeHasVolatileElements(o)) {
209-
ignore = 0;
210-
}
211-
hashtableSetType(o->ptr, ignore ? &hashHashtableType : &hashWithVolatileItemsHashtableType);
212-
}
213-
}
214-
215-
static volatile_set *
216-
hashTypeGetOrcreateVolatileSet(robj *o) {
217-
serverAssert(o->encoding == OBJ_ENCODING_HASHTABLE);
218-
volatile_set **volatile_set_ref = hashtableMetadata(o->ptr);
219-
if (*volatile_set_ref == NULL) {
220-
*volatile_set_ref = createVolatileSet(&hashvolatileEntryType);
221-
/* serves mainly for optimization. Use type which supports access function only when needed. */
222-
hashTypeIgnoreTTL(o, 0);
223-
}
224-
return *volatile_set_ref;
225-
}
226-
227-
228-
static void hashTypeDeleteVolatileSet(robj *o) {
229-
volatile_set **volatile_set_ref = hashtableMetadata(o->ptr);
230-
freeVolatileSet(*volatile_set_ref);
231-
*volatile_set_ref = NULL;
232-
/* serves mainly for optimization. by changing the hashtable type we can avoid extra function call in hashtable access */
233-
hashTypeIgnoreTTL(o, 1);
234-
}
235-
236111
void hashTypeTrackEntry(serverDb* db, robj *o, void *entry) {
237112
volatile_set *set = hashTypeGetOrcreateVolatileSet(o);
238113
serverAssert(volatileSetAddEntry(set, entry, entryGetExpiry(entry)));
@@ -247,7 +122,7 @@ void hashTypeUntrackEntry(serverDb* db, robj *o, void *entry) {
247122
if (volatileSetNumEntries(set) == 0) {
248123
hashTypeDeleteVolatileSet(o);
249124
}
250-
// kvstoreHashtableDelete(db->keys_with_volatile_items, 0, o);
125+
// kvstoreHashtableDelete(db->keys_with_volatile_items, 0, o); // TODO
251126
}
252127

253128
static void hashTypeTrackUpdateEntry(serverDb* db, robj *o, void *old_entry, void *new_entry, long long old_expiry, long long new_expiry) {
@@ -281,14 +156,14 @@ int hashTypeExpireEntry(void *entry) {
281156
return 1;
282157
}
283158

284-
hashtableElementAccessState hashHashtableTypeAccess(hashtable *ht, void *entry) {
159+
hashtableEntryValidationState hashHashtableTypeValidate(hashtable *ht, void *entry) {
285160
UNUSED(ht);
161+
expirationPolicy policy = getExpirationPolicyWithFlags(0);
162+
if (policy == POLICY_IGNORE_EXPIRE) return ENTRY_VALID;
286163

287-
if (!canExpireWithFlags(0, NULL)) return ELEMENT_VALID;
288-
289-
if (!entryIsExpired(entry)) return ELEMENT_VALID;
164+
if (!entryIsExpired(entry)) return ENTRY_VALID;
290165

291-
return ELEMENT_INVALID;
166+
return ENTRY_INVALID;
292167
}
293168

294169
/*-----------------------------------------------------------------------------
@@ -719,20 +594,6 @@ void hashTypeInitIterator(robj *subject, hashTypeIterator *hi) {
719594
}
720595
}
721596

722-
void hashTypeInitVolatileIterator(robj *subject, hashTypeIterator *hi) {
723-
hi->subject = subject;
724-
hi->encoding = subject->encoding;
725-
hi->volatile_items = 1;
726-
727-
if (hi->encoding == OBJ_ENCODING_LISTPACK) {
728-
return;
729-
} else if (hi->encoding == OBJ_ENCODING_HASHTABLE) {
730-
volatileSetStart(hashTypeGetVolatileSet(subject), &hi->viter);
731-
} else {
732-
serverPanic("Unknown hash encoding");
733-
}
734-
}
735-
736597
void hashTypeInitVolatileIterator(robj *subject, hashTypeIterator *hi) {
737598
hi->subject = subject;
738599
hi->encoding = subject->encoding;
@@ -1298,8 +1159,6 @@ void hsetexCommand(client *c) {
12981159

12991160
if (convertExpireArgumentToUnixTime(c, expire, basetime, unit, &when) == C_ERR)
13001161
return;
1301-
}
1302-
when += commandTimeSnapshot();
13031162

13041163
if (((flags & OBJ_PXAT) || (flags & OBJ_EXAT)) && checkAlreadyExpired(when)) {
13051164
set_expired = 1;
@@ -1681,9 +1540,7 @@ void httlGenericCommand(client *c, long long basetime, int unit) {
16811540
return;
16821541
}
16831542

1684-
hashTypeSetAccessContext(hash, c->db);
1685-
1686-
if (checkType(c, hash, OBJ_HASH)) return;
1543+
robj *hash = lookupKeyRead(c->db, c->argv[1]);
16871544

16881545
if (checkType(c, hash, OBJ_HASH)) return;
16891546

0 commit comments

Comments
 (0)