-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add basic inode cache #17324
Open
tcrain
wants to merge
8
commits into
Alluxio:master-2.x
Choose a base branch
from
tcrain:inodecache
base: master-2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add basic inode cache #17324
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62bc553
add basic cache
tcrain 0406b65
fix cache size
tcrain 6b3c269
cleanup
tcrain da58af5
Merge branch 'master' into inodecache
tcrain 2043b65
fix version for java 8
tcrain e63ac58
fix tests
tcrain 7d54513
fix remove
tcrain d0cb7c8
add test
tcrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import alluxio.master.metastore.BlockMetaStore; | ||
import alluxio.master.metastore.InodeStore; | ||
import alluxio.master.metastore.MetastoreType; | ||
import alluxio.master.metastore.caching.BasicInodeCache; | ||
import alluxio.master.metastore.caching.CachingInodeStore; | ||
import alluxio.master.metastore.heap.HeapBlockMetaStore; | ||
import alluxio.master.metastore.heap.HeapInodeStore; | ||
|
@@ -90,7 +91,11 @@ public static InodeStore.Factory getInodeStoreFactory(String baseDir) { | |
if (Configuration.getInt(PropertyKey.MASTER_METASTORE_INODE_CACHE_MAX_SIZE) == 0) { | ||
return lockManager -> new RocksInodeStore(baseDir); | ||
} else { | ||
return lockManager -> new CachingInodeStore(new RocksInodeStore(baseDir), lockManager); | ||
if (Configuration.getBoolean(PropertyKey.MASTER_METASTORE_INODE_CACHE_BASIC)) { | ||
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. nit: using "else if" |
||
return lockManager -> new BasicInodeCache(baseDir); | ||
} else { | ||
return lockManager -> new CachingInodeStore(new RocksInodeStore(baseDir), lockManager); | ||
} | ||
} | ||
default: | ||
throw new IllegalStateException("Unknown metastore type: " + type); | ||
|
74 changes: 74 additions & 0 deletions
74
core/server/master/src/main/java/alluxio/master/metastore/caching/BasicInodeCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.metastore.caching; | ||
|
||
import alluxio.conf.Configuration; | ||
import alluxio.conf.PropertyKey; | ||
import alluxio.master.file.meta.MutableInode; | ||
import alluxio.master.metastore.ReadOption; | ||
import alluxio.master.metastore.rocks.RocksInodeStore; | ||
|
||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import com.google.common.base.Preconditions; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* A cache that only caches inodes. | ||
*/ | ||
public class BasicInodeCache extends RocksInodeStore { | ||
|
||
com.github.benmanes.caffeine.cache.Cache<Long, MutableInode<?>> mCache; | ||
|
||
/** | ||
* Creates and initializes a rocks block store. | ||
* | ||
* @param baseDir the base directory in which to store inode metadata | ||
*/ | ||
public BasicInodeCache(String baseDir) { | ||
super(baseDir); | ||
|
||
int maxSize = Configuration.getInt(PropertyKey.MASTER_METASTORE_INODE_CACHE_MAX_SIZE); | ||
Preconditions.checkState(maxSize > 0, | ||
"Maximum cache size %s must be positive, but is set to %s", | ||
PropertyKey.MASTER_METASTORE_INODE_CACHE_MAX_SIZE.getName(), maxSize); | ||
|
||
mCache = Caffeine.newBuilder().initialCapacity(maxSize).maximumSize(maxSize).build(); | ||
} | ||
|
||
@Override | ||
public Optional<MutableInode<?>> getMutable(long inodeId, ReadOption option) { | ||
return Optional.ofNullable(mCache.asMap().computeIfAbsent(inodeId, id -> | ||
BasicInodeCache.super.getMutable(inodeId, option).orElse(null))); | ||
} | ||
|
||
@Override | ||
public void remove(Long inodeId) { | ||
mCache.asMap().compute(inodeId, (id, inode) -> { | ||
BasicInodeCache.super.remove(inodeId); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public void writeInode(MutableInode<?> inode) { | ||
mCache.asMap().compute(inode.getId(), (id, oldInode) -> { | ||
BasicInodeCache.super.writeInode(inode); | ||
return inode; | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean supportsBatchWrite() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
also update line 2689 correspondingly