]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #20988 from DaanDeMeyer/rotate-reason
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Oct 2021 07:53:31 +0000 (09:53 +0200)
committerGitHub <noreply@github.com>
Tue, 19 Oct 2021 07:53:31 +0000 (09:53 +0200)
journal: Improve rotation logging

1  2 
src/libsystemd/sd-journal/journal-file.c

index 7c88c6614dcb5611e2e472cc35a124e396163469,9f8b02d89b166f72719654c23f8b2d1ef4386231..b4052ad417bfc4f96bd769aa13ad76599b6cbf3c
@@@ -2146,7 -2146,8 +2146,7 @@@ int journal_file_append_entry
                  return r;
  #endif
  
 -        /* alloca() can't take 0, hence let's allocate at least one */
 -        items = newa(EntryItem, MAX(1u, n_iovec));
 +        items = newa(EntryItem, n_iovec);
  
          for (unsigned i = 0; i < n_iovec; i++) {
                  uint64_t p;
@@@ -3315,7 -3316,7 +3315,7 @@@ void journal_file_print_header(JournalF
                 le64toh(f->header->arena_size),
                 le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
                 le64toh(f->header->field_hash_table_size) / sizeof(HashItem),
-                yes_no(journal_file_rotate_suggested(f, 0)),
+                yes_no(journal_file_rotate_suggested(f, 0, LOG_DEBUG)),
                 le64toh(f->header->head_entry_seqnum), le64toh(f->header->head_entry_seqnum),
                 le64toh(f->header->tail_entry_seqnum), le64toh(f->header->tail_entry_seqnum),
                 FORMAT_TIMESTAMP_SAFE(le64toh(f->header->head_entry_realtime)), le64toh(f->header->head_entry_realtime),
@@@ -3872,7 -3873,8 +3872,7 @@@ int journal_file_copy_entry(JournalFil
          boot_id = &o->entry.boot_id;
  
          n = journal_file_entry_n_items(o);
 -        /* alloca() can't take 0, hence let's allocate at least one */
 -        items = newa(EntryItem, MAX(1u, n));
 +        items = newa(EntryItem, n);
  
          for (uint64_t i = 0; i < n; i++) {
                  uint64_t l, h;
@@@ -4105,14 -4107,14 +4105,14 @@@ int journal_file_get_cutoff_monotonic_u
          return 1;
  }
  
- bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec) {
+ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log_level) {
          assert(f);
          assert(f->header);
  
          /* If we gained new header fields we gained new features,
           * hence suggest a rotation */
          if (le64toh(f->header->header_size) < sizeof(Header)) {
-                 log_debug("%s uses an outdated header, suggesting rotation.", f->path);
+                 log_full(log_level, "%s uses an outdated header, suggesting rotation.", f->path);
                  return true;
          }
  
  
          if (JOURNAL_HEADER_CONTAINS(f->header, n_data))
                  if (le64toh(f->header->n_data) * 4ULL > (le64toh(f->header->data_hash_table_size) / sizeof(HashItem)) * 3ULL) {
-                         log_debug("Data hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items, %llu file size, %"PRIu64" bytes per hash table item), suggesting rotation.",
-                                   f->path,
-                                   100.0 * (double) le64toh(f->header->n_data) / ((double) (le64toh(f->header->data_hash_table_size) / sizeof(HashItem))),
-                                   le64toh(f->header->n_data),
-                                   le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
-                                   (unsigned long long) f->last_stat.st_size,
-                                   f->last_stat.st_size / le64toh(f->header->n_data));
+                         log_full(log_level,
+                                  "Data hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items, %llu file size, %"PRIu64" bytes per hash table item), suggesting rotation.",
+                                  f->path,
+                                  100.0 * (double) le64toh(f->header->n_data) / ((double) (le64toh(f->header->data_hash_table_size) / sizeof(HashItem))),
+                                  le64toh(f->header->n_data),
+                                  le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
+                                  (unsigned long long) f->last_stat.st_size,
+                                  f->last_stat.st_size / le64toh(f->header->n_data));
                          return true;
                  }
  
          if (JOURNAL_HEADER_CONTAINS(f->header, n_fields))
                  if (le64toh(f->header->n_fields) * 4ULL > (le64toh(f->header->field_hash_table_size) / sizeof(HashItem)) * 3ULL) {
-                         log_debug("Field hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items), suggesting rotation.",
-                                   f->path,
-                                   100.0 * (double) le64toh(f->header->n_fields) / ((double) (le64toh(f->header->field_hash_table_size) / sizeof(HashItem))),
-                                   le64toh(f->header->n_fields),
-                                   le64toh(f->header->field_hash_table_size) / sizeof(HashItem));
+                         log_full(log_level,
+                                  "Field hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items), suggesting rotation.",
+                                  f->path,
+                                  100.0 * (double) le64toh(f->header->n_fields) / ((double) (le64toh(f->header->field_hash_table_size) / sizeof(HashItem))),
+                                  le64toh(f->header->n_fields),
+                                  le64toh(f->header->field_hash_table_size) / sizeof(HashItem));
                          return true;
                  }
  
           * longest chain is longer than some threshold, let's suggest rotation. */
          if (JOURNAL_HEADER_CONTAINS(f->header, data_hash_chain_depth) &&
              le64toh(f->header->data_hash_chain_depth) > HASH_CHAIN_DEPTH_MAX) {
-                 log_debug("Data hash table of %s has deepest hash chain of length %" PRIu64 ", suggesting rotation.",
-                           f->path, le64toh(f->header->data_hash_chain_depth));
+                 log_full(log_level,
+                          "Data hash table of %s has deepest hash chain of length %" PRIu64 ", suggesting rotation.",
+                          f->path, le64toh(f->header->data_hash_chain_depth));
                  return true;
          }
  
          if (JOURNAL_HEADER_CONTAINS(f->header, field_hash_chain_depth) &&
              le64toh(f->header->field_hash_chain_depth) > HASH_CHAIN_DEPTH_MAX) {
-                 log_debug("Field hash table of %s has deepest hash chain of length at %" PRIu64 ", suggesting rotation.",
-                           f->path, le64toh(f->header->field_hash_chain_depth));
+                 log_full(log_level,
+                          "Field hash table of %s has deepest hash chain of length at %" PRIu64 ", suggesting rotation.",
+                          f->path, le64toh(f->header->field_hash_chain_depth));
                  return true;
          }
  
          if (JOURNAL_HEADER_CONTAINS(f->header, n_data) &&
              JOURNAL_HEADER_CONTAINS(f->header, n_fields) &&
              le64toh(f->header->n_data) > 0 &&
-             le64toh(f->header->n_fields) == 0)
+             le64toh(f->header->n_fields) == 0) {
+                 log_full(log_level,
+                          "Data objects of %s are not indexed by field objects, suggesting rotation.",
+                          f->path);
                  return true;
+         }
  
          if (max_file_usec > 0) {
                  usec_t t, h;
                  h = le64toh(f->header->head_entry_realtime);
                  t = now(CLOCK_REALTIME);
  
-                 if (h > 0 && t > h + max_file_usec)
+                 if (h > 0 && t > h + max_file_usec) {
+                         log_full(log_level,
+                                  "Oldest entry in %s is older than the configured file retention duration (%s), suggesting rotation.",
+                                  f->path, FORMAT_TIMESPAN(max_file_usec, USEC_PER_SEC));
                          return true;
+                 }
          }
  
          return false;