This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch vipul/juul-master-steam-10-18-2023
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 211219d7ce98e6ef9bea14174043bffc60cf3114
Author: Ben McCrea <[email protected]>
AuthorDate: Thu Jun 29 14:20:08 2023 -0700

    sys/log: Don't increment global log index unless log is persisted.
    
    The global index is only useful for persisted logs, and if it is incremented
    for non-persisted logs there will be jumps in the log indexes of the 
persisted
    logs. This makes detection of missing logs a challenging task. By 
incrementing
    the global index only for persisted logs, it becomes sequentially 
increasing,
    which makes detection of missing/dropped logs trivial for upstream consumers
    of the logs.
---
 sys/log/full/src/log.c       | 5 ++++-
 sys/log/full/src/log_shell.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 4ef785ebf..5a2c823ea 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -540,7 +540,10 @@ log_append_prepare(struct log *log, uint8_t module, 
uint8_t level,
 
     OS_ENTER_CRITICAL(sr);
 #if MYNEWT_VAL(LOG_GLOBAL_IDX)
-    idx = g_log_info.li_next_index++;
+    if (log->l_log->log_type == LOG_TYPE_STORAGE) {
+        g_log_info.li_next_index++;
+    }
+    idx = g_log_info.li_next_index;
 #else
     idx = log->l_idx++;
 #endif
diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 48db8a822..cf3017a70 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -69,7 +69,7 @@ shell_log_dump_entry(struct log *log, struct log_offset 
*log_offset,
         console_printf("[ih=0x%x%x%x%x]", ueh->ue_imghash[0], 
ueh->ue_imghash[1],
                        ueh->ue_imghash[2], ueh->ue_imghash[3]);
     }
-    console_printf(" [%llu] ", ueh->ue_ts);
+    console_printf(" [%llu]  [ix=%lu]", ueh->ue_ts, ueh->ue_index);
 
     switch (ueh->ue_etype) {
     case LOG_ETYPE_STRING:

Reply via email to