@@ -77,19 +77,19 @@ typedef struct {
77
77
78
78
// When 'server_memory_in_use' is less than this value, throttling is turned
79
79
// off.
80
- int low_water_mark_bytes ;
80
+ size_t low_water_mark_bytes ;
81
81
82
82
// When 'server_memory_in_use' is greater than this value, throttling is
83
83
// turned on.
84
- int high_water_mark_bytes ;
84
+ size_t high_water_mark_bytes ;
85
85
86
86
// How long to keep adding hashes to the same chunk before making a new chunk
87
87
// (typically 1/2 hour).
88
- int chunk_interval_secs ;
88
+ cdtime_t chunk_interval_secs ;
89
89
90
90
// How long to keep wg_key_history_s chunks before purging them (typically
91
91
// 24 hours).
92
- int purge_interval_secs ;
92
+ cdtime_t purge_interval_secs ;
93
93
} mtg_key_tracker_t ;
94
94
95
95
typedef struct {
@@ -242,30 +242,52 @@ static int mtg_create(const oconfig_item_t *ci, void **user_data)
242
242
} else {
243
243
int k ;
244
244
mtg_key_tracker_t * kt = ctx -> key_tracker ; // Alias
245
- static const char * int_keys [ 4 ] = {
245
+ static const char * size_t_keys [ ] = {
246
246
"LowWaterMark" ,
247
247
"HighWaterMark" ,
248
- "ChunkInterval" ,
249
- "PurgeInterval" ,
250
248
};
251
- int * int_locations [] = {
249
+ size_t * size_t_locations [] = {
252
250
& kt -> low_water_mark_bytes ,
253
251
& kt -> high_water_mark_bytes ,
252
+ };
253
+ static const char * cdtime_keys [] = {
254
+ "ChunkInterval" ,
255
+ "PurgeInterval" ,
256
+ };
257
+ cdtime_t * cdtime_locations [] = {
254
258
& kt -> chunk_interval_secs ,
255
259
& kt -> purge_interval_secs ,
256
260
};
257
- assert (STATIC_ARRAY_SIZE (int_keys ) == STATIC_ARRAY_SIZE (int_locations ));
258
- for (k = 0 ; k < STATIC_ARRAY_SIZE (int_keys ); ++ k ) {
259
- if (strcasecmp (int_keys [k ], child -> key ) == 0 ) {
260
- if (cf_util_get_int (child , int_locations [k ]) != 0 ) {
261
- ERROR ("%s: cf_util_get_int failed for key %s" ,
261
+ assert (STATIC_ARRAY_SIZE (size_t_keys )
262
+ == STATIC_ARRAY_SIZE (size_t_locations ));
263
+ for (k = 0 ; k < STATIC_ARRAY_SIZE (size_t_keys ); ++ k ) {
264
+ if (strcasecmp (size_t_keys [k ], child -> key ) == 0 ) {
265
+ double result ;
266
+ if (cf_util_get_double (child , & result ) != 0 ) {
267
+ ERROR ("%s: cf_util_get_double failed for key %s" ,
268
+ this_plugin_name , child -> key );
269
+ ++ parse_errors ;
270
+ }
271
+ * size_t_locations [k ] = (size_t )result ;
272
+ break ;
273
+ }
274
+ }
275
+ if (k < STATIC_ARRAY_SIZE (size_t_keys )) {
276
+ continue ;
277
+ }
278
+ assert (STATIC_ARRAY_SIZE (cdtime_keys )
279
+ == STATIC_ARRAY_SIZE (cdtime_locations ));
280
+ for (k = 0 ; k < STATIC_ARRAY_SIZE (cdtime_keys ); ++ k ) {
281
+ if (strcasecmp (cdtime_keys [k ], child -> key ) == 0 ) {
282
+ if (cf_util_get_cdtime (child , cdtime_locations [k ]) != 0 ) {
283
+ ERROR ("%s: cf_util_get_cdtime failed for key %s" ,
262
284
this_plugin_name , child -> key );
263
285
++ parse_errors ;
264
286
}
265
287
break ;
266
288
}
267
289
}
268
- if (k < STATIC_ARRAY_SIZE (int_keys )) {
290
+ if (k < STATIC_ARRAY_SIZE (cdtime_keys )) {
269
291
continue ;
270
292
}
271
293
ERROR ("%s: Unknown configuration option %s" ,
@@ -483,7 +505,7 @@ static int mtg_update_stats(size_t server_memory_in_use, _Bool is_throttling)
483
505
static int mtg_retire_old_entries (mtg_key_tracker_t * tracker , cdtime_t now )
484
506
{
485
507
// Trim the key history (removing entries older than 'purge_time')
486
- cdtime_t purge_time = now - TIME_T_TO_CDTIME_T ( tracker -> purge_interval_secs ) ;
508
+ cdtime_t purge_time = now - tracker -> purge_interval_secs ;
487
509
488
510
while (tracker -> key_history_head != NULL &&
489
511
tracker -> key_history_head -> last_append_time < purge_time ) {
@@ -567,8 +589,7 @@ static int mtg_add_new_entries(const mtg_context_t *ctx, cdtime_t now,
567
589
// 1. There is no current history node.
568
590
// 2. The current history node is full.
569
591
// 3. The current history node was created prior to 'chunk_time'.
570
- cdtime_t chunk_time = now -
571
- TIME_T_TO_CDTIME_T (tracker -> chunk_interval_secs );
592
+ cdtime_t chunk_time = now - tracker -> chunk_interval_secs ;
572
593
mtg_key_history_t * tail = tracker -> key_history_tail ; // alias
573
594
if (tail == NULL ||
574
595
tail -> num_hashes == STATIC_ARRAY_SIZE (tail -> hashes ) ||
0 commit comments