return true;
}
+ xpthread_mutex_lock(&rl->mutex);
if (!token_bucket_withdraw(&rl->token_bucket, VLOG_MSG_TOKENS)) {
time_t now = time_now();
if (!rl->n_dropped) {
}
rl->last_dropped = now;
rl->n_dropped++;
+ xpthread_mutex_unlock(&rl->mutex);
return true;
}
- if (rl->n_dropped) {
+ if (!rl->n_dropped) {
+ xpthread_mutex_unlock(&rl->mutex);
+ } else {
time_t now = time_now();
+ unsigned int n_dropped = rl->n_dropped;
unsigned int first_dropped_elapsed = now - rl->first_dropped;
unsigned int last_dropped_elapsed = now - rl->last_dropped;
+ rl->n_dropped = 0;
+ xpthread_mutex_unlock(&rl->mutex);
vlog(module, level,
"Dropped %u log messages in last %u seconds (most recently, "
"%u seconds ago) due to excessive rate",
- rl->n_dropped, first_dropped_elapsed, last_dropped_elapsed);
-
- rl->n_dropped = 0;
+ n_dropped, first_dropped_elapsed, last_dropped_elapsed);
}
+
return false;
}
#include <stdbool.h>
#include <time.h>
#include "compiler.h"
+#include "ovs-thread.h"
#include "sat-math.h"
#include "token-bucket.h"
#include "util.h"
time_t first_dropped; /* Time first message was dropped. */
time_t last_dropped; /* Time of most recent message drop. */
unsigned int n_dropped; /* Number of messages dropped. */
+ pthread_mutex_t mutex; /* Mutual exclusion for rate limit. */
};
/* Number of tokens to emit a message. We add 'rate' tokens per millisecond,
0, /* first_dropped */ \
0, /* last_dropped */ \
0, /* n_dropped */ \
+ PTHREAD_ADAPTIVE_MUTEX_INITIALIZER /* mutex */ \
}
/* Configuring how each module logs messages. */