<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110087/issue-with-data-deletion-and-garbage-collection-in-fds</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Apr 2024 12:37:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110087/issue-with-data-deletion-and-garbage-collection-in-fds" /><item><title>RE: Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/thread/478772?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 12:37:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f223452-c315-4de8-9d48-70083fedea53</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Lara,&lt;/p&gt;
&lt;p&gt;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&amp;#39;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.&amp;nbsp;&lt;/p&gt;
[quote user="lara_"]What I mean is that the number of dirty records doesn&amp;#39;t decrease at all when I run the garbage collection.[/quote]
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you can&amp;#39;t share anything more, perhaps you can try to create a minimalistic application only reproducing the issue that you are seeing?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/thread/478409?ContentTypeID=1</link><pubDate>Thu, 11 Apr 2024 23:17:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35224688-8ec2-448c-b178-39f2604df3aa</guid><dc:creator>lara_</dc:creator><description>&lt;p&gt;Hello Edvin,&lt;/p&gt;
&lt;p&gt;In the last snippet within the fds event handler, when I issue the API command &amp;quot;del!&amp;quot;, it&amp;#39;s supposed to delete the data. To achieve this, the delete_file flag is set to true within the fds handler. Then, in the main section, there&amp;#39;s a conditional check for delete_file being true. If it evaluates to true, the function app_fds_delete_file() is executed. This function, in turn, calls the provided functions: fds_file_delete(), wait_for_del_file, and app_fds_garbage_collection(), all of which I&amp;#39;ve linked in my initial post.&lt;/p&gt;
&lt;p&gt;What I mean is that the number of dirty records doesn&amp;#39;t decrease at all when I run the garbage collection.&lt;/p&gt;
&lt;p&gt;The 3 next snippets are: 1) some fds data before the deleting and garbage collection 2) Deleting and garbage collection 3) fds data after&amp;nbsp;&lt;span&gt;&amp;nbsp;deleting and garbage collection&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;debug&amp;gt; app:  66 64 73 64 61 74 61 3F|fdsdata?
&amp;lt;debug&amp;gt; app: Received data from BLE NUS.
&amp;lt;info&amp;gt; app: valid_records: 74
&amp;lt;info&amp;gt; app: dirty_records: 10
&amp;lt;info&amp;gt; app: pages_available: 16
&amp;lt;info&amp;gt; app: open_records: 4
&amp;lt;info&amp;gt; app: words_reserved: 0
&amp;lt;info&amp;gt; app: words_used: 11813
&amp;lt;info&amp;gt; app: largest_contig: 2046
&amp;lt;info&amp;gt; app: freeable_words: 40
&amp;lt;info&amp;gt; app: corruption: false
&amp;lt;info&amp;gt; app: ble_send_data: 32
&amp;lt;info&amp;gt; app: Thu Jan 01 00:34:27 1970&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
&amp;lt;debug&amp;gt; app:  64 65 6C 21            |del!    
&amp;lt;debug&amp;gt; app: Received data from BLE NUS.
&amp;lt;info&amp;gt; app: Delete Mode
&amp;lt;info&amp;gt; app: Deleting files...
&amp;lt;info&amp;gt; app: Event: FDS_EVT_DEL_FILE received (NRF_SUCCESS)
&amp;lt;info&amp;gt; app: File ID:	0x0001
&amp;lt;info&amp;gt; app: Record KEY:	0x0000
&amp;lt;info&amp;gt; app: Record ID:	0x0000
&amp;lt;info&amp;gt; app: Trying to run garbage collection...
&amp;lt;info&amp;gt; app: Thu Jan 01 00:35:14 1970

&amp;lt;info&amp;gt; app: Thu Jan 01 00:35:15 1970

&amp;lt;info&amp;gt; app: Event: FDS_EVT_GC received (NRF_SUCCESS)
&amp;lt;info&amp;gt; app: GC completed successfully.
&amp;lt;info&amp;gt; app: Updating sync data.
&amp;lt;info&amp;gt; app: Sync storage round: 1
&amp;lt;info&amp;gt; app: Updating sync file...
&amp;lt;info&amp;gt; app: Event: FDS_EVT_UPDATE received (NRF_SUCCESS)
&amp;lt;info&amp;gt; app: File ID:	0x0000
&amp;lt;info&amp;gt; app: Record KEY:	0x0001
&amp;lt;info&amp;gt; app: Record ID:	0x2C04
&amp;lt;info&amp;gt; app: ble_send_text: Data deleted.
&amp;lt;info&amp;gt; app: Sent
&amp;lt;info&amp;gt; app: Thu Jan 01 00:35:16 1970&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;debug&amp;gt; app:  66 64 73 64 61 74 61 3F|fdsdata?
&amp;lt;debug&amp;gt; app: Received data from BLE NUS.
&amp;lt;info&amp;gt; app: valid_records: 4
&amp;lt;info&amp;gt; app: dirty_records: 26
&amp;lt;info&amp;gt; app: pages_available: 16
&amp;lt;info&amp;gt; app: open_records: 4
&amp;lt;info&amp;gt; app: words_reserved: 0
&amp;lt;info&amp;gt; app: words_used: 2097
&amp;lt;info&amp;gt; app: largest_contig: 2046
&amp;lt;info&amp;gt; app: freeable_words: 2044
&amp;lt;info&amp;gt; app: corruption: false
&amp;lt;info&amp;gt; app: ble_send_data: 32
&amp;lt;info&amp;gt; app: Sent
&amp;lt;info&amp;gt; app: Thu Jan 01 00:36:25 1970&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Lara&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/thread/478189?ContentTypeID=1</link><pubDate>Thu, 11 Apr 2024 07:03:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45d3a44e-8839-41f0-b737-ca90fefb734f</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Lara,&lt;/p&gt;
&lt;p&gt;I suspect that you attatched the wrong snippet.&amp;nbsp;&lt;/p&gt;
[quote user="lara_"]However, if I record data, delete it, and then perform GC, the number of dirty records doesn&amp;#39;t reset to 0. Instead, it persists[/quote]
&lt;p&gt;Are you saying that it doesn&amp;#39;t decrease at all, or does it decrease, but never reach 0?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you please show the snippets where you delete the records and where you run GC, in addition to your fds evt_handler?&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/thread/478159?ContentTypeID=1</link><pubDate>Thu, 11 Apr 2024 01:06:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0bd0de3-4c7a-4bb1-8437-b026d83fe85a</guid><dc:creator>lara_</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/edvin-holmseth"&gt;Edvin&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;Thank you for your prompt response,&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;I&amp;#39;m afraid I can&amp;#39;t provide the entire application, but I&amp;#39;ve implemented an API command to query the fds data.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s what I&amp;#39;m observing: Upon firmware initiation, if there are dirty records, querying the number of dirty records after garbage collection shows 0, indicating successful GC.&lt;/p&gt;
&lt;p&gt;However, if I record data, delete it, and then perform GC, the number of dirty records doesn&amp;#39;t reset to 0. Instead, it persists, necessitating FW restart to clear them.&lt;/p&gt;
&lt;p&gt;Moreover, as I record and delete data without FW restarts, the available space for recording diminishes gradually. For instance, after FW restart, I can record 200 values. But after subsequent data deletion without restarts, the recording capacity decreases (e.g., to 180 values). I suspect this degradation results from ineffective deletion and garbage collection of dirty records, leading to flash space not being reclaimed properly.&lt;/p&gt;
&lt;p&gt;Regarding the fds event handler, here&amp;#39;s a snippet:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void nus_data_handler(ble_nus_evt_t * p_evt)
{
    if(p_evt-&amp;gt;type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_HEXDUMP_DEBUG(p_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);
        NRF_LOG_DEBUG(&amp;quot;Received data from BLE NUS.&amp;quot;);

        /* perform action according to command */
        
        else if((memcmp(p_evt-&amp;gt;params.rx_data.p_data, &amp;quot;del!&amp;quot;, 4) == 0))
        {
            if(can_query == true)
            {
                NRF_LOG_INFO(&amp;quot;Delete Mode&amp;quot;);

                /* delete all data files */
                delete_file = true;
                return;
            }
        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This function is called from the main(), where there&amp;#39;s a conditional check for &lt;/span&gt;&lt;code&gt;delete_file&lt;/code&gt;&lt;span&gt; being true. If it evaluates to true, the function &lt;/span&gt;&lt;code&gt;app_fds_delete_file()&lt;/code&gt;&lt;span&gt; is executed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Hope this clarifies the situation. Let me know if further details are needed.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Lara&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/thread/477948?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2024 07:38:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13104a22-00e0-4ae7-a0f1-f2795d2580ff</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you please share the entire application so that I can try to replicate what you are seeing?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t understand exactly what you were trying to say with the attached log. It doesn&amp;#39;t say that there are any dirty records after the GC? How do you determine that there are still dirty records after the GC?&lt;/p&gt;
&lt;p&gt;And what does your fds event handler look like?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue with Data Deletion and Garbage Collection in FDS</title><link>https://devzone.nordicsemi.com/thread/477927?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2024 06:12:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:204fbcc5-02d5-487a-aa92-bd0671796efe</guid><dc:creator>lara_</dc:creator><description>&lt;p&gt;Here is the correct wait_for_gc:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void wait_for_gc(void)
{
    while(!m_gc_complete)
    {
        power_manage();
    }

    m_gc_complete = false;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>