mirror of https://github.com/redis/redis.git
				
				
				
			Add Statistics hashes_with_expiry_fields to INFO (#13275)
Added hashes_with_expiry_fields. Optimially it would better to have statistic of that counts all fields with expiry. But it requires careful logic and computation to follow and deep dive listpacks and hashes. This statistics is trivial to achieve and reflected by global HFE DS that has builtin enumeration of all the hashes that are registered in it.
This commit is contained in:
		
							parent
							
								
									ae6df30eb1
								
							
						
					
					
						commit
						f34f2ade85
					
				|  | @ -6106,14 +6106,16 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { | ||||||
|         if (sections++) info = sdscat(info,"\r\n"); |         if (sections++) info = sdscat(info,"\r\n"); | ||||||
|         info = sdscatprintf(info, "# Keyspace\r\n"); |         info = sdscatprintf(info, "# Keyspace\r\n"); | ||||||
|         for (j = 0; j < server.dbnum; j++) { |         for (j = 0; j < server.dbnum; j++) { | ||||||
|             long long keys, vkeys; |             long long keys, vkeys, hexpires; | ||||||
| 
 | 
 | ||||||
|             keys = kvstoreSize(server.db[j].keys); |             keys = kvstoreSize(server.db[j].keys); | ||||||
|             vkeys = kvstoreSize(server.db[j].expires); |             vkeys = kvstoreSize(server.db[j].expires); | ||||||
|  |             hexpires = ebGetTotalItems(server.db[j].hexpires, &hashExpireBucketsType); | ||||||
|  | 
 | ||||||
|             if (keys || vkeys) { |             if (keys || vkeys) { | ||||||
|                 info = sdscatprintf(info, |                 info = sdscatprintf(info, | ||||||
|                     "db%d:keys=%lld,expires=%lld,avg_ttl=%lld\r\n", |                     "db%d:keys=%lld,expires=%lld,avg_ttl=%lld,hashes_with_expiry_fields=%lld\r\n", | ||||||
|                     j, keys, vkeys, server.db[j].avg_ttl); |                     j, keys, vkeys, server.db[j].avg_ttl, hexpires); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -24,6 +24,19 @@ set S_FIELD_AND_TTL 3 | ||||||
| 
 | 
 | ||||||
| ############################### AUX FUNCS ###################################### | ############################### AUX FUNCS ###################################### | ||||||
| 
 | 
 | ||||||
|  | proc get_hashes_with_expiry_fields {r} { | ||||||
|  |     set input_string [r info keyspace] | ||||||
|  |     set hash_count 0 | ||||||
|  | 
 | ||||||
|  |     foreach line [split $input_string \n] { | ||||||
|  |         if {[regexp {hashes_with_expiry_fields=(\d+)} $line -> value]} { | ||||||
|  |             return $value | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 0 | ||||||
|  | } | ||||||
|  | 
 | ||||||
| proc create_hash {key entries} { | proc create_hash {key entries} { | ||||||
|     r del $key |     r del $key | ||||||
|     foreach entry $entries { |     foreach entry $entries { | ||||||
|  | @ -1260,4 +1273,23 @@ start_server {tags {"external:skip needs:debug"}} { | ||||||
| 
 | 
 | ||||||
|         r config set hash-max-listpack-value 64 |         r config set hash-max-listpack-value 64 | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     test "Statistics - Hashes with HFEs" { | ||||||
|  |         r config resetstat | ||||||
|  |         r del myhash | ||||||
|  |         r hset myhash f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 | ||||||
|  |         r hpexpire myhash 100 1 f1 f2 f3 | ||||||
|  | 
 | ||||||
|  |         assert_match  [get_hashes_with_expiry_fields r] 1 | ||||||
|  |         r hset myhash2 f1 v1 f2 v2 f3 v3 f4 v4 f5 v5 | ||||||
|  |         assert_match  [get_hashes_with_expiry_fields r] 1 | ||||||
|  |         r hpexpire myhash2 100 1 f1 f2 f3 | ||||||
|  |         assert_match  [get_hashes_with_expiry_fields r] 2 | ||||||
|  | 
 | ||||||
|  |         wait_for_condition 50 50 { | ||||||
|  |                 [get_hashes_with_expiry_fields r] == 0 | ||||||
|  |         } else { | ||||||
|  |                 fail "Hash field expiry statistics failed" | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue