<?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>PM handler - deleting lowest ranked peer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75122/pm-handler---deleting-lowest-ranked-peer</link><description>Hi nRF Support, 
 I get nRF5 SDK version 17.0.2 and learn Peer Manager handler implementation (pm_handler_flash_clean function). Lets consider this case: 
 - 2 bonded peers (ranks enabled) that connected one time 
 - another fds user that fill storage</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 14 May 2021 11:23:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75122/pm-handler---deleting-lowest-ranked-peer" /><item><title>RE: PM handler - deleting lowest ranked peer</title><link>https://devzone.nordicsemi.com/thread/309758?ContentTypeID=1</link><pubDate>Fri, 14 May 2021 11:23:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02059a26-758c-43c0-b046-89ca1c0ecef2</guid><dc:creator>kchuva</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thanks for answer. Both strategies looks working. I can implement any in my application.&lt;/p&gt;
&lt;p&gt;Question 1: is implementation below working model?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
// 1) find the lowest ranked peer
pm_peer_id_t peer_id_to_delete;
err_code = pm_peer_ranks_get(NULL, NULL, &amp;amp;peer_id_to_delete, NULL);
if (err_code == NRF_SUCCEESS)
{
    uint16_t handle = BLE_CONN_HANDLE_INVALID;
    err_code = pm_conn_handle_get(peer_id_to_delete, &amp;amp;handle);
    APP_ERROR_CHECK(err_code);
    
    if (handle != BLE_CONN_HANDLE_INVALID)
    {
	    // 2) the lowest ranked peer is currently connected =&amp;gt; delete any nonconnected peer
	    peer_id_to_delete = pm_next_peer_id_get(PM_PEER_ID_INVALID);
	    while (peer_id_to_delete != PM_PEER_ID_INVALID)
	    {
		    err_code = pm_conn_handle_get(peer_id_to_delete, &amp;amp;handle);
		    APP_ERROR_CHECK(err_code);
		    if (handle == BLE_CONN_HANDLE_INVALID)
			    break;

		    peer_id_to_delete = pm_next_peer_id_get(peer_id_to_delete);
	    }
    }
    
    // 3) delete finded peer
    if (peer_id_to_delete != PM_PEER_ID_INVALID)
    {
	    err_code = pm_peer_delete(peer_id_to_delete);
	    APP_ERROR_CHECK(err_code);
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Question 2: will a solution of issue be offered in peer_manager_handler in new version SDK?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Konstantin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PM handler - deleting lowest ranked peer</title><link>https://devzone.nordicsemi.com/thread/309727?ContentTypeID=1</link><pubDate>Fri, 14 May 2021 09:13:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c13d9b81-1995-4568-8c6c-2ce945342fec</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Konstantin,&lt;/p&gt;
&lt;p&gt;Yes, this is a possible issue. The probability of it happening is application dependent, and how to best handle this is also application dependent.&lt;/p&gt;
&lt;p&gt;If you have a application where you blindly write to FDS without thought of it becoming full or not, then this could happen. I would suggest that you regularly check amount of free FDS space and amount that can be garbage collected. If there is almost no free space left and a lot to garbage collect, simply do garbage collection. If there is almost no free space and nothing to garbage collect, you need to either delete some data or stop writing new data. That way you will never end up in a situation where there is no room to update peer manger ranks.&lt;/p&gt;
&lt;p&gt;If the above is not possible, then you should add a check to verify that you never delete the bond of a currently connected peer, as that is as you write not supported and can lead to undefined behavior. Doing this is always a good idea if there is any chance of getting into the&amp;nbsp;situation&amp;nbsp; where you could otherwise delete the bond of a currently connected peer.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>