Skip to content
Snippets Groups Projects
Commit 7c889ac7 authored by Ivan Frade's avatar Ivan Frade Committed by Gerrit Code Review
Browse files

Merge "DfsBlockCacheConfig: propagate hotmap configs to pack ext cache configs"

parents ea4ac5e4 a7b5f056
No related branches found
No related tags found
No related merge requests found
...@@ -179,6 +179,76 @@ public void fromConfig_generatesDfsBlockCachePackExtConfigs() { ...@@ -179,6 +179,76 @@ public void fromConfig_generatesDfsBlockCachePackExtConfigs() {
is(indexConfig)); is(indexConfig));
} }
@Test
public void fromConfig_withExistingCacheHotMap_configWithPackExtConfigsHasHotMaps() {
Config config = new Config();
addPackExtConfigEntry(config, "pack", List.of(PackExt.PACK),
/* blockLimit= */ 20 * 512, /* blockSize= */ 512);
addPackExtConfigEntry(config, "bitmap", List.of(PackExt.BITMAP_INDEX),
/* blockLimit= */ 25 * 1024, /* blockSize= */ 1024);
addPackExtConfigEntry(config, "index",
List.of(PackExt.INDEX, PackExt.OBJECT_SIZE_INDEX,
PackExt.REVERSE_INDEX),
/* blockLimit= */ 30 * 1024, /* blockSize= */ 1024);
Map<PackExt, Integer> cacheHotMap = Map.of(PackExt.PACK, 1,
PackExt.BITMAP_INDEX, 2, PackExt.INDEX, 3, PackExt.REFTABLE, 4);
DfsBlockCacheConfig cacheConfig = new DfsBlockCacheConfig();
cacheConfig.setCacheHotMap(cacheHotMap);
cacheConfig.fromConfig(config);
var configs = cacheConfig.getPackExtCacheConfigurations();
assertThat(cacheConfig.getCacheHotMap(), is(cacheHotMap));
assertThat(configs, hasSize(3));
var packConfig = getConfigForExt(configs, PackExt.PACK);
assertThat(packConfig.getCacheHotMap(), is(Map.of(PackExt.PACK, 1)));
var bitmapConfig = getConfigForExt(configs, PackExt.BITMAP_INDEX);
assertThat(bitmapConfig.getCacheHotMap(),
is(Map.of(PackExt.BITMAP_INDEX, 2)));
var indexConfig = getConfigForExt(configs, PackExt.INDEX);
assertThat(indexConfig.getCacheHotMap(), is(Map.of(PackExt.INDEX, 3)));
}
@Test
public void setCacheHotMap_configWithPackExtConfigs_setsHotMaps() {
Config config = new Config();
addPackExtConfigEntry(config, "pack", List.of(PackExt.PACK),
/* blockLimit= */ 20 * 512, /* blockSize= */ 512);
addPackExtConfigEntry(config, "bitmap", List.of(PackExt.BITMAP_INDEX),
/* blockLimit= */ 25 * 1024, /* blockSize= */ 1024);
addPackExtConfigEntry(config, "index",
List.of(PackExt.INDEX, PackExt.OBJECT_SIZE_INDEX,
PackExt.REVERSE_INDEX),
/* blockLimit= */ 30 * 1024, /* blockSize= */ 1024);
Map<PackExt, Integer> cacheHotMap = Map.of(PackExt.PACK, 1,
PackExt.BITMAP_INDEX, 2, PackExt.INDEX, 3, PackExt.REFTABLE, 4);
DfsBlockCacheConfig cacheConfig = new DfsBlockCacheConfig()
.fromConfig(config);
cacheConfig.setCacheHotMap(cacheHotMap);
var configs = cacheConfig.getPackExtCacheConfigurations();
assertThat(cacheConfig.getCacheHotMap(), is(cacheHotMap));
assertThat(configs, hasSize(3));
var packConfig = getConfigForExt(configs, PackExt.PACK);
assertThat(packConfig.getCacheHotMap(), is(Map.of(PackExt.PACK, 1)));
var bitmapConfig = getConfigForExt(configs, PackExt.BITMAP_INDEX);
assertThat(bitmapConfig.getCacheHotMap(),
is(Map.of(PackExt.BITMAP_INDEX, 2)));
var indexConfig = getConfigForExt(configs, PackExt.INDEX);
assertThat(indexConfig.getCacheHotMap(), is(Map.of(PackExt.INDEX, 3)));
}
@Test @Test
public void fromConfigs_baseConfigOnly_nameSetFromConfigDfsSubSection() { public void fromConfigs_baseConfigOnly_nameSetFromConfigDfsSubSection() {
Config config = new Config(); Config config = new Config();
...@@ -291,6 +361,7 @@ public void writeConfigurationDebug_writesConfigsToWriter() ...@@ -291,6 +361,7 @@ public void writeConfigurationDebug_writesConfigsToWriter()
" Name: dfs.pack", " BlockLimit: " + 20 * 512, " Name: dfs.pack", " BlockLimit: " + 20 * 512,
" BlockSize: 512", " StreamRatio: 0.3", " BlockSize: 512", " StreamRatio: 0.3",
" ConcurrencyLevel: 32", " ConcurrencyLevel: 32",
" CacheHotMapEntry: " + PackExt.PACK + " : " + 10,
" PackExts: " + List.of(PackExt.PACK)))); " PackExts: " + List.of(PackExt.PACK))));
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
...@@ -300,12 +301,24 @@ public Map<PackExt, Integer> getCacheHotMap() { ...@@ -300,12 +301,24 @@ public Map<PackExt, Integer> getCacheHotMap() {
* map of hot count per pack extension for {@code DfsBlockCache}. * map of hot count per pack extension for {@code DfsBlockCache}.
* @return {@code this} * @return {@code this}
*/ */
/*
* TODO The cache HotMap configuration should be set as a config option and
* not passed in through a setter.
*/
public DfsBlockCacheConfig setCacheHotMap( public DfsBlockCacheConfig setCacheHotMap(
Map<PackExt, Integer> cacheHotMap) { Map<PackExt, Integer> cacheHotMap) {
this.cacheHotMap = Collections.unmodifiableMap(cacheHotMap); this.cacheHotMap = Collections.unmodifiableMap(cacheHotMap);
setCacheHotMapToPackExtConfigs(this.cacheHotMap);
return this; return this;
} }
private void setCacheHotMapToPackExtConfigs(
Map<PackExt, Integer> cacheHotMap) {
for (DfsBlockCachePackExtConfig packExtConfig : packExtCacheConfigurations) {
packExtConfig.setCacheHotMap(cacheHotMap);
}
}
/** /**
* Get the consumer of cache index events. * Get the consumer of cache index events.
* *
...@@ -433,6 +446,7 @@ private void loadPackExtConfigs(Config config) { ...@@ -433,6 +446,7 @@ private void loadPackExtConfigs(Config config) {
cacheConfigs.add(cacheConfig); cacheConfigs.add(cacheConfig);
} }
packExtCacheConfigurations = cacheConfigs; packExtCacheConfigurations = cacheConfigs;
setCacheHotMapToPackExtConfigs(this.cacheHotMap);
} }
private static <T> Set<T> intersection(Set<T> first, Set<T> second) { private static <T> Set<T> intersection(Set<T> first, Set<T> second) {
...@@ -551,6 +565,14 @@ DfsBlockCacheConfig getPackExtCacheConfiguration() { ...@@ -551,6 +565,14 @@ DfsBlockCacheConfig getPackExtCacheConfiguration() {
return packExtCacheConfiguration; return packExtCacheConfiguration;
} }
void setCacheHotMap(Map<PackExt, Integer> cacheHotMap) {
Map<PackExt, Integer> packExtHotMap = packExts.stream()
.filter(cacheHotMap::containsKey)
.collect(Collectors.toUnmodifiableMap(Function.identity(),
cacheHotMap::get));
packExtCacheConfiguration.setCacheHotMap(packExtHotMap);
}
private static DfsBlockCachePackExtConfig fromConfig(Config config, private static DfsBlockCachePackExtConfig fromConfig(Config config,
String section, String subSection) { String section, String subSection) {
String packExtensions = config.getString(section, subSection, String packExtensions = config.getString(section, subSection,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment