Skip to content

Commit

Permalink
Move DatabaseMetaDataNodePath.getVersionPath to VersionNodePathGenera…
Browse files Browse the repository at this point in the history
…tor (#34635)
  • Loading branch information
terrymanu authored Feb 12, 2025
1 parent 02e5e17 commit d8dd89c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
import org.apache.shardingsphere.mode.node.path.metadata.DatabaseMetaDataNodePath;
import org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;

Expand Down Expand Up @@ -82,11 +81,11 @@ private List<Integer> getVersions(final String path) {
/**
* Load content.
*
* @param path content path
* @param version content version
* @param activeVersionPath active version path
* @param activeVersion active version
* @return loaded content
*/
public String loadContent(final String path, final int version) {
return repository.query(DatabaseMetaDataNodePath.getVersionPath(path, version));
public String loadContent(final String activeVersionPath, final int activeVersion) {
return repository.query(VersionNodePathGenerator.getVersionPath(activeVersionPath, activeVersion));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public final class DatabaseMetaDataNodePath {

private static final String SCHEMAS_NODE = "schemas";

private static final String VERSIONS_NODE = "versions";

private static final String ACTIVE_VERSION_NODE = "active_version";

/**
Expand Down Expand Up @@ -79,17 +77,6 @@ public static String getSchemaPath(final String databaseName, final String schem
return String.join("/", getSchemaRootPath(databaseName), schemaName);
}

/**
* Get version path.
*
* @param rulePath rule path
* @param activeVersion active version
* @return version path
*/
public static String getVersionPath(final String rulePath, final int activeVersion) {
return rulePath.replace(ACTIVE_VERSION_NODE, VERSIONS_NODE) + "/" + activeVersion;
}

/**
* Find database name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public String getVersionsPath() {
public String getVersionPath(final int version) {
return String.join("/", getVersionsPath(), String.valueOf(version));
}

/**
* Get version path.
*
* @param activeVersionPath active version path
* @param activeVersion active version
* @return version path
*/
public static String getVersionPath(final String activeVersionPath, final int activeVersion) {
return String.join("/", activeVersionPath.replace(ACTIVE_VERSION, VERSIONS), String.valueOf(activeVersion));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ void assertGetSchemaPath() {
assertThat(DatabaseMetaDataNodePath.getSchemaPath("foo_db", "foo_schema"), is("/metadata/foo_db/schemas/foo_schema"));
}

@Test
void assertGetVersionPath() {
assertThat(DatabaseMetaDataNodePath.getVersionPath("foo_rule", 1), is("foo_rule/1"));
}

@Test
void assertFindDatabaseNameWithNotContainsChildPath() {
Optional<String> actual = DatabaseMetaDataNodePath.findDatabaseName("/metadata/foo_db", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ void assertGetVersionsPath() {
void assertGetVersionPath() {
assertThat(new VersionNodePathGenerator("foo").getVersionPath(0), is("foo/versions/0"));
}

@Test
void assertGetVersionPathFromActiveVersion() {
assertThat(VersionNodePathGenerator.getVersionPath("foo_rule/active_version", 1), is("foo_rule/versions/1"));
}
}

0 comments on commit d8dd89c

Please sign in to comment.