-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#663] improvement(core): Add storage layout version information and …
…store it in kv store (#701) ### What changes were proposed in this pull request? Save the KV layout version information into KV storage. ### Why are the changes needed? We require storage layout version information to determine the code path we should use. Fix: #663 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New UTs in `TestKvEntityStore`
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
core/src/main/java/com/datastrato/gravitino/storage/StorageLayoutException.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,19 @@ | ||
/* | ||
* Copyright 2023 Datastrato. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.storage; | ||
|
||
import com.datastrato.gravitino.exceptions.GravitinoRuntimeException; | ||
|
||
public class StorageLayoutException extends GravitinoRuntimeException { | ||
|
||
public StorageLayoutException(String message) { | ||
super(message); | ||
} | ||
|
||
public StorageLayoutException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/com/datastrato/gravitino/storage/StorageLayoutVersion.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,31 @@ | ||
/* | ||
* Copyright 2023 Datastrato. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.storage; | ||
|
||
import lombok.Getter; | ||
|
||
/** The storage layer version of the entity store. */ | ||
@Getter | ||
public enum StorageLayoutVersion { | ||
V1("v1"); | ||
|
||
private final String version; | ||
|
||
StorageLayoutVersion(String version) { | ||
this.version = version; | ||
} | ||
|
||
public static StorageLayoutVersion fromString(String version) { | ||
for (StorageLayoutVersion v : StorageLayoutVersion.values()) { | ||
if (v.version.equals(version)) { | ||
return v; | ||
} | ||
} | ||
throw new StorageLayoutException( | ||
"Unknown storage version, maybe the data is broken, please " | ||
+ "check the storage directory."); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
core/src/test/java/com/datastrato/gravitino/storage/TestStorageVersion.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,21 @@ | ||
/* | ||
* Copyright 2023 Datastrato. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.storage; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TestStorageVersion { | ||
|
||
@Test | ||
void testFromString() { | ||
StorageLayoutVersion version = StorageLayoutVersion.fromString("v1"); | ||
Assertions.assertEquals(StorageLayoutVersion.V1, version); | ||
|
||
Assertions.assertThrowsExactly( | ||
StorageLayoutException.class, () -> StorageLayoutVersion.fromString("v200000.0")); | ||
} | ||
} |
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