tianhang tang created HBASE-26850: ------------------------------------- Summary: Optimize the implementation of LRUCache in LRUDictionary Key: HBASE-26850 URL: https://issues.apache.org/jira/browse/HBASE-26850 Project: HBase Issue Type: Improvement Components: wal Affects Versions: 2.4.11, 3.0.0-alpha-2, 1.7.1 Reporter: tianhang tang Assignee: tianhang tang Attachments: image-2022-03-16-17-13-00-871.png
During my research on HBASE-26849, I found that there seems to be something wrong with the implementation of LRUDictionary. It uses array to save data, and uses hashMap to save array index. If there are multiple identical elements, multiple copies will be stored in the array, but there is only one mapping from one element to the array index in the map. In this way, when the first element is eliminated, there is no way for the other elements to find the index. Then i try to dig out the write link. The stack of write is: {code:java} RingBufferEventHandler#onEvent -> RingBufferEventHandler#append -> ProtobufLogWriter#append -> CompressedKvEncoder#write -> LRUDictionary#findEntry{code} BidirectionalLRUMap#findIdx will be executed first in LRUDictionary#findEntry: !image-2022-03-16-17-13-00-871.png! If the LRUCache already exists, it will moveToHead directly and return the existing node, and will not write multiple times in the array. After debug verification, it is indeed the case. However, the current LRUCache directly exposes _addEntry_ to the outside, which I think we can do it a little more elegantly. -- This message was sent by Atlassian Jira (v8.20.1#820001)