Support multiple git repositories locations
Gerrit was supporting only one location for git repositories configured with gerrit.basePath. Now supports alternate location for the gerrit.basePath that can be configured with repository.name.basePath. The motivation for this change is to allow to host projects on different storage. This could be required for performance reasons, e.g. use a high performance storage for a heavily used repository. In the following example, all the repositories go in /my/gerrit/site/git, except the ones with a name starting with "organizationA", which go in /other/volume/git. If a new project is created and its name starts with "organizationA", then it will be created and used from /other/volume/git. [gerrit] basePath = /my/gerrit/site/git [repository "organizationA*"] basePath = /other/volume/git An alternative to this change is using soft links in the gerrit.basePath folder to allow putting some repositories on another storage. This solution is not viable if gerrit.basePath folder is not on local storage. For example, if the gerrit site, including the basePath for repositories, are on NFS, then using a soft link on the NFS to link to a high performance storage would not result in the expected performance improvement. That is so because any repositories stored on the high performance storage would be used through the NFS storage. Change-Id: I1212d0226bfbb51ee92be4902c3658078d56b841
This commit is contained in:
@@ -24,6 +24,9 @@ import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RepositoryConfigTest {
|
||||
@@ -144,4 +147,67 @@ public class RepositoryConfigTest {
|
||||
cfg.setStringList(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.OWNER_GROUP_NAME, ownerGroups);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasePathWhenNotConfigured() {
|
||||
assertThat((Object)repoCfg.getBasePath(new NameKey("someProject"))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasePathForStarFilter() {
|
||||
String basePath = "/someAbsolutePath/someDirectory";
|
||||
configureBasePath("*", basePath);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString())
|
||||
.isEqualTo(basePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasePathForSpecificFilter() {
|
||||
String basePath = "/someAbsolutePath/someDirectory";
|
||||
configureBasePath("someProject", basePath);
|
||||
assertThat((Object) repoCfg.getBasePath(new NameKey("someOtherProject")))
|
||||
.isNull();
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString())
|
||||
.isEqualTo(basePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasePathForStartWithFilter() {
|
||||
String basePath1 = "/someAbsolutePath1/someDirectory";
|
||||
String basePath2 = "someRelativeDirectory2";
|
||||
String basePath3 = "/someAbsolutePath3/someDirectory";
|
||||
String basePath4 = "/someAbsolutePath4/someDirectory";
|
||||
|
||||
configureBasePath("pro*", basePath1);
|
||||
configureBasePath("project/project/*", basePath2);
|
||||
configureBasePath("project/*", basePath3);
|
||||
configureBasePath("*", basePath4);
|
||||
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project1")).toString())
|
||||
.isEqualTo(basePath1);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project/project/someProject"))
|
||||
.toString()).isEqualTo(basePath2);
|
||||
assertThat(
|
||||
repoCfg.getBasePath(new NameKey("project/someProject")).toString())
|
||||
.isEqualTo(basePath3);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString())
|
||||
.isEqualTo(basePath4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllBasePath() {
|
||||
List<Path> allBasePaths = Arrays.asList(Paths.get("/someBasePath1"),
|
||||
Paths.get("/someBasePath2"), Paths.get("/someBasePath2"));
|
||||
|
||||
configureBasePath("*", allBasePaths.get(0).toString());
|
||||
configureBasePath("project/*", allBasePaths.get(1).toString());
|
||||
configureBasePath("project/project/*", allBasePaths.get(2).toString());
|
||||
|
||||
assertThat(repoCfg.getAllBasePaths()).isEqualTo(allBasePaths);
|
||||
}
|
||||
|
||||
private void configureBasePath(String projectFilter, String basePath) {
|
||||
cfg.setString(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.BASE_PATH_NAME, basePath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user