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
4846int 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-
236111void 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
253128static 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-
736597void 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