Hi Jayanga,

I will send a PR.

Thanks,
Chalitha

On Tue, Aug 23, 2016 at 4:15 PM, Jayanga Kaushalya <jayan...@wso2.com>
wrote:

> Hi Chalitha,
>
> Thanks for checking up on this. It's great if you can send a PR for
> carbon-kernel 4.4.x branch on this.
>
> Thanks!
>
> *Jayanga Kaushalya*
> Software Engineer
> Mobile: +94777860160
> WSO2 Inc. | http://wso2.com
> lean.enterprise.middleware
>
> On Fri, Jun 24, 2016 at 2:00 PM, Chalitha Kulathunga <chalit...@wso2.com>
> wrote:
>
>> + IS team members
>>
>> On Fri, Jun 24, 2016 at 1:37 PM, Chalitha Kulathunga <chalit...@wso2.com>
>> wrote:
>>
>>> Hi kernal team,
>>>
>>> When multiple threads access updatePermissionTree() method for the first
>>> time, they all will end up in the else block. Those threads will call the
>>> updatePermissionTreeFromDB() method one by one. Seems like this is creating
>>> a bottleneck in the execution flow.
>>>
>>> void updatePermissionTree() throws UserStoreException {
>>>     PermissionTreeCacheKey cacheKey = new 
>>> PermissionTreeCacheKey(cacheIdentifier, tenantId);
>>>     GhostResource<TreeNode> cacheEntry = (GhostResource<TreeNode>) 
>>> permissionCache.get(cacheKey);
>>>     if (permissionCache.containsKey(cacheKey)) {
>>>         if (cacheEntry.getResource() == null) {
>>>             synchronized (this) {
>>>                 cacheEntry = (GhostResource<TreeNode>) 
>>> permissionCache.get(cacheKey);
>>>                 if (cacheEntry.getResource() == null) {
>>>                     updatePermissionTreeFromDB();
>>>                     cacheEntry.setResource(root);
>>>                     if (log.isDebugEnabled()) {
>>>                         log.debug("Set resource to true");
>>>                     }
>>>                 }
>>>             }
>>>         }
>>>     } else {
>>>         synchronized (this) {
>>>             updatePermissionTreeFromDB();
>>>             cacheKey = new PermissionTreeCacheKey(cacheIdentifier, 
>>> tenantId);
>>>             cacheEntry = new GhostResource<TreeNode>(root);
>>>             permissionCache.put(cacheKey, cacheEntry);
>>>             if (log.isDebugEnabled()) {
>>>                 log.debug("Loaded from database");
>>>             }
>>>         }
>>>     }
>>> }
>>>
>>>
>>> Can this be modified as follows to avoid the above mentioned issue?
>>>
>>> void updatePermissionTree() throws UserStoreException {
>>>     PermissionTreeCacheKey cacheKey = new 
>>> PermissionTreeCacheKey(cacheIdentifier, tenantId);
>>>     GhostResource<TreeNode> cacheEntry = (GhostResource<TreeNode>) 
>>> permissionCache.get(cacheKey);
>>>     if (cacheEntry != null && cacheEntry.getResource() != null) {
>>>         return;
>>>     }
>>>     synchronized (this) {
>>>         if (cacheEntry != null && cacheEntry.getResource() != null) {
>>>             return;
>>>         }
>>>         if (cacheEntry == null) {
>>>             cacheEntry = new GhostResource<TreeNode>(null);
>>>             permissionCache.put(cacheKey, cacheEntry);
>>>         }
>>>         if (cacheEntry.getResource() == null) {
>>>             updatePermissionTreeFromDB();
>>>             cacheEntry.setResource(root);
>>>             if (log.isDebugEnabled()) {
>>>                 log.debug("Resource Loaded from database for cachekey: " + 
>>> cacheEntry);
>>>             }
>>>         }
>>>     }
>>> }
>>>
>>>
>>> Thanks,
>>> Chalitha
>>>
>>>
>>> --
>>> *Chalitha Sanyuja Kulathunga*
>>> *Software Engineer*
>>> WSO2 Inc.; http://wso2.com
>>> email: chalit...@wso2.com cell: +94 77 5927581 <%2B94%2077%207779495>
>>>
>>
>>
>>
>> --
>> *Chalitha Sanyuja Kulathunga*
>> *Software Engineer*
>> WSO2 Inc.; http://wso2.com
>> email: chalit...@wso2.com cell: +94 77 5927581 <%2B94%2077%207779495>
>>
>
>


-- 
*Chalitha Sanyuja Kulathunga*
*Software Engineer*
WSO2 Inc.; http://wso2.com
email: chalit...@wso2.com cell: +94 77 5927581 <+94+77+5927581>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to