Issue with Data Deletion and Garbage Collection in FDS

SDK: nRF5_SDK_17.1.0

I am currently encountering some difficulties regarding data deletion and garbage collection after recording in my Nordic application. I have followed the instructions provided by NRF closely, yet I seem to face persistent issues.

I have the impression that the code indicates that the deletion and garbage collection have been successfully completed, but when I examine the actual dirty records, they are not deleted. It seems that the garbage collection only works successfully during device initialization

Here's a snippet of the code I'm using:

void app_fds_delete_file(uint16_t my_file_id)
{
    ret_code_t rc;

    NRF_LOG_INFO("Deleting files...");
    rc = fds_file_delete(my_file_id);
    APP_ERROR_CHECK(rc);

    wait_for_del_file();

    app_fds_garbage_collection();
}

In the fds_evt_handler, m_fds_del_file is set to true in response to FDS_EVT_DEL_FILE.

static void app_fds_garbage_collection(void)
{
    ret_code_t rc;

    NRF_LOG_INFO("Trying to run garbage collection...");
    rc = fds_gc();
    APP_ERROR_CHECK(rc);

    wait_for_gc();
}
static void wait_for_del_file(void)
{
    while(!m_fds_del_file)
    {
        power_manage();
    }

    m_fds_del_file = false;
}

Here's an excerpt from the log showing the behavior during startup:

<info> app_timer: RTC: initialized.
<info> app: Initializing fds...
<info> app: Event: FDS_EVT_INIT received (NRF_SUCCESS)
<info> app: Reading flash usage statistics...
<info> app: Found 14 valid records.
<info> app: Found 10 dirty records (ready to be garbage collected).
<info> app: Found 16 pages_available.
<info> app: Found 0 open_records.
<info> app: Found 0 words_reserved.
<info> app: Found 1844 words_used.
<info> app: Found 2046 largest_contig.
<info> app: Event: FDS_EVT_GC received (NRF_SUCCESS)
<info> app: GC completed successfully.
<info> app: Sync file found.
<info> app: Sync storage round: 11
<info> app: Thu Jan 01 00:00:00 1970

At this point, querying the dirty records correctly returns 0, but if I save some data and try delete them the dirty records will never go back to 0.

I'm puzzled as to why this is happening. Could someone provide insights or suggestions on how to resolve this issue effectively?

Your assistance and expertise are greatly appreciated.

  • Hello Lara,

    It is a bit difficult to follow whats going on when I only have explanations on how things are implemented. I understand that you can't share your entire project, but is it possible to strip out everything but the fds parts, so that I can have a look? I still have not seen your fds_evt_handler(). I think I understand how you intend for it to work, but since something is not working as intended, it could be a bug in the implementation. 

    lara_ said:
    What I mean is that the number of dirty records doesn't decrease at all when I run the garbage collection.

    I see that the number of dirty records went from 10 to 26, and this is after a GC. But it looks like you update at least one record after the garbage collection as well? This will result in at least one dirty record. Also, you go from 74 to 4 valid records, but the log only says that one record was deleted? I suspect there is a lot more going on than what the logs are saying.

    If you can't share anything more, perhaps you can try to create a minimalistic application only reproducing the issue that you are seeing? 

    Best regards,

    Edvin

Related