-
Notifications
You must be signed in to change notification settings - Fork 997
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
[core] Separate index cache and data cache #4438
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,25 +24,31 @@ | |
/** Key for cache manager. */ | ||
public interface CacheKey { | ||
|
||
static CacheKey forPosition(RandomAccessFile file, long position, int length) { | ||
return new PositionCacheKey(file, position, length); | ||
static CacheKey forPosition(RandomAccessFile file, long position, int length, boolean isIndex) { | ||
return new PositionCacheKey(file, position, length, isIndex); | ||
} | ||
|
||
static CacheKey forPageIndex(RandomAccessFile file, int pageSize, int pageIndex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this method? The invoker should always set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But for the |
||
return new PageIndexCacheKey(file, pageSize, pageIndex); | ||
return new PageIndexCacheKey(file, pageSize, pageIndex, false); | ||
} | ||
|
||
/** @return Whether this cache key is for index cache. */ | ||
boolean isIndex(); | ||
|
||
/** Key for file position and length. */ | ||
class PositionCacheKey implements CacheKey { | ||
|
||
private final RandomAccessFile file; | ||
private final long position; | ||
private final int length; | ||
private final boolean isIndex; | ||
|
||
private PositionCacheKey(RandomAccessFile file, long position, int length) { | ||
private PositionCacheKey( | ||
RandomAccessFile file, long position, int length, boolean isIndex) { | ||
this.file = file; | ||
this.position = position; | ||
this.length = length; | ||
this.isIndex = isIndex; | ||
} | ||
|
||
@Override | ||
|
@@ -56,12 +62,18 @@ public boolean equals(Object o) { | |
PositionCacheKey that = (PositionCacheKey) o; | ||
return position == that.position | ||
&& length == that.length | ||
&& isIndex == that.isIndex | ||
&& Objects.equals(file, that.file); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(file, position, length); | ||
return Objects.hash(file, position, length, isIndex); | ||
} | ||
|
||
@Override | ||
public boolean isIndex() { | ||
return isIndex; | ||
} | ||
} | ||
|
||
|
@@ -71,17 +83,25 @@ class PageIndexCacheKey implements CacheKey { | |
private final RandomAccessFile file; | ||
private final int pageSize; | ||
private final int pageIndex; | ||
private final boolean isIndex; | ||
|
||
private PageIndexCacheKey(RandomAccessFile file, int pageSize, int pageIndex) { | ||
private PageIndexCacheKey( | ||
RandomAccessFile file, int pageSize, int pageIndex, boolean isIndex) { | ||
this.file = file; | ||
this.pageSize = pageSize; | ||
this.pageIndex = pageIndex; | ||
this.isIndex = isIndex; | ||
} | ||
|
||
public int pageIndex() { | ||
return pageIndex; | ||
} | ||
|
||
@Override | ||
public boolean isIndex() { | ||
return isIndex; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
|
@@ -93,12 +113,13 @@ public boolean equals(Object o) { | |
PageIndexCacheKey that = (PageIndexCacheKey) o; | ||
return pageSize == that.pageSize | ||
&& pageIndex == that.pageIndex | ||
&& isIndex == that.isIndex | ||
&& Objects.equals(file, that.file); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(file, pageSize, pageIndex); | ||
return Objects.hash(file, pageSize, pageIndex, isIndex); | ||
} | ||
} | ||
} |
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.
What is the source of this default value? 0.1 or 0.25?
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.
if 0.1, the size is 25MB, 0.25 is 64MB. When I test, the bloom filter may occupy 5-10MB. So, I give a bigger (64MB) default index cache here.