- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
HBASE-23887 AdaptiveLRU cache #2934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-23887 AdaptiveLRU cache #2934
Conversation
| 💔 -1 overall 
 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 💔 -1 overall 
 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 💔 -1 overall 
 This message was automatically generated. | 
fix javadoc warn
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 💔 -1 overall 
 
 This message was automatically generated. | 
dummy commit to re-run unit tests
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pustota2009 . Left some comments, please take a look
| private final AtomicLong count; | ||
|  | ||
| /** hard capacity limit */ | ||
| private float hardCapacityLimitFactor; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| private long maxSize; | ||
|  | ||
| /** Approximate block size */ | ||
| private long blockSize; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting from blockSize till forceInMemory, all can be final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|  | ||
| // check the bounds | ||
| this.heavyEvictionCountLimit = heavyEvictionCountLimit < 0 ? 0 : heavyEvictionCountLimit; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Math.max(heavyEvictionCountLimit, 0) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| heavyEvictionOverheadCoefficient = heavyEvictionOverheadCoefficient < 0.001f | ||
| ? 0.001f : heavyEvictionOverheadCoefficient; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here: Math.max(heavyEvictionOverheadCoefficient, 0.001f)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| public int evictBlocksByHfileName(String hfileName) { | ||
| int numEvicted = 0; | ||
| for (BlockCacheKey key : map.keySet()) { | ||
| if (key.getHfileName().equals(hfileName)) { | ||
| if (evictBlock(key)) { | ||
| ++numEvicted; | ||
| } | ||
| } | ||
| } | ||
| if (victimHandler != null) { | ||
| numEvicted += victimHandler.evictBlocksByHfileName(hfileName); | ||
| } | ||
| return numEvicted; | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced by Stream.count() for simplicity:
  public int evictBlocksByHfileName(String hfileName) {
    int numEvicted = (int) map.keySet().stream().filter(key -> key.getHfileName().equals(hfileName))
      .filter(this::evictBlock).count();
    if (victimHandler != null) {
      numEvicted += victimHandler.evictBlocksByHfileName(hfileName);
    }
    return numEvicted;
  }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| EvictionThread evictionThread = cache.getEvictionThread(); | ||
| assertTrue(evictionThread != null); | ||
| while (!evictionThread.isEnteringRun()) { | ||
| Thread.sleep(1); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 ms is nothing, let's put 1000 ms at least?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| service.execute(new Runnable() { | ||
| @Override | ||
| public void run() { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with lambda?
        service.execute(() -> {
          for (int blockIndex = 0; blockIndex < blocksPerThread
            || (!cache.isEvictionInProgress()); ++blockIndex) {
...
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| assertEquals(cache.getOverhead(), cache.getCurrentSize()); | ||
| } | ||
| } | ||
| @Test | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: leave one line b/ two methods? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|  | ||
| LruAdaptiveBlockCache cache = new LruAdaptiveBlockCache(maxSize,blockSize); | ||
| EvictionThread evictionThread = cache.getEvictionThread(); | ||
| assertTrue(evictionThread != null); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: assertNotNull(evictionThread)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| assertTrue(cache.getBlock(block.cacheKey, true, false, | ||
| true) == null); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: assertNull(cache.getBlock(block.cacheKey, true, false, true));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…BASE-23887-LRU-Adaptive
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Signed-off-by: Viraj Jasani <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
Instead of #1257 (there were some problems with rebase)