World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1772] improvement(conf): Change the default storage directroy of `rocksdbPath` in gravitino.conf.template and support relative path (#1773)
Qi Yu6d5bb647ad16
diff --git a/conf/gravitino.conf.template b/conf/gravitino.conf.templateindex df8e3b1208..3cd1192b69 100644--- a/conf/gravitino.conf.template+++ b/conf/gravitino.conf.template@@ -31,8 +31,10 @@ gravitino.server.webserver.responseHeaderSize = 131072gravitino.entity.store = kv# The RocksDB entity storegravitino.entity.store.kv = RocksDBKvBackend-# The RocksDB backend path for entity store-# gravitino.entity.store.kv.rocksdbPath = /tmp/gravitino+# The storage path for RocksDB storage implementation, it supports both absolute and relative path,+# If the value is a relative path, the final path is "${GRAVITINO_HOME}/${PATH_YOU_HAVA_SET}", default value+# is "${GRAVITINO_HOME}/data/rocksdb", please uncomment and change it in your production environment.+# gravitino.entity.store.kv.rocksdbPath = data/rocksdb# THE CONFIGURATION FOR Gravitino CATALOG# The interval in milliseconds to evict the catalog cachediff --git a/core/src/main/java/com/datastrato/gravitino/Configs.java b/core/src/main/java/com/datastrato/gravitino/Configs.javaindex b53dbd0a33..4cc276c6b1 100644--- a/core/src/main/java/com/datastrato/gravitino/Configs.java+++ b/core/src/main/java/com/datastrato/gravitino/Configs.java@@ -61,7 +61,11 @@ public interface Configs {ConfigEntry<String> ENTRY_KV_ROCKSDB_BACKEND_PATH =new ConfigBuilder(ENTITY_KV_ROCKSDB_BACKEND_PATH_KEY)- .doc("Directory path of `RocksDBKvBackend`")+ .doc(+ "The storage path for RocksDB storage implementation. It supports both absolute and"+ + " relative path, if the value is a relative path, the final path is "+ + "`${GRAVITINO_HOME}/${PATH_YOU_HAVA_SET}`, default value is "+ + "`${GRAVITINO_HOME}/data/rocksdb`").version(ConfigConstants.VERSION_0_1_0).stringConf().createWithDefault(DEFAULT_KV_ROCKSDB_BACKEND_PATH);diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.javaindex 6b0d956043..97dcd29f5e 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java@@ -14,7 +14,10 @@ import com.google.common.annotations.VisibleForTesting;import com.google.common.collect.Lists;import java.io.File;import java.io.IOException;+import java.nio.file.Path;+import java.nio.file.Paths;import java.util.List;+import org.apache.commons.lang3.StringUtils;import org.apache.commons.lang3.tuple.Pair;import org.rocksdb.Options;import org.rocksdb.RocksDB;@@ -40,7 +43,7 @@ public class RocksDBKvBackend implements KvBackend {private RocksDB initRocksDB(Config config) throws RocksDBException {RocksDB.loadLibrary();- String dbPath = config.get(Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH);+ String dbPath = getStoragePath(config);File dbDir = new File(dbPath, "instance");try (final Options options = new Options()) {options.setCreateIfMissing(true);@@ -62,6 +65,23 @@ public class RocksDBKvBackend implements KvBackend {}}+ @VisibleForTesting+ String getStoragePath(Config config) {+ String dbPath = config.get(Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH);+ if (StringUtils.isBlank(dbPath)) {+ return Configs.DEFAULT_KV_ROCKSDB_BACKEND_PATH;+ }++ Path path = Paths.get(dbPath);+ // Relative Path+ if (!path.isAbsolute()) {+ path = Paths.get(System.getenv("GRAVITINO_HOME"), dbPath);+ return path.toString();+ }++ return dbPath;+ }+@Overridepublic void initialize(Config config) throws IOException {try {diff --git a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.javaindex ce89f85eee..2160a213e7 100644--- a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java+++ b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java@@ -36,6 +36,21 @@ public class TestRocksDBKvBackend {return kvBackend;}+ @Test+ void testStoragePath() {+ Config config = Mockito.mock(Config.class);+ Mockito.when(config.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)).thenReturn("/a/b");+ RocksDBKvBackend kvBackend = new RocksDBKvBackend();+ String path = kvBackend.getStoragePath(config);+ Assertions.assertEquals("/a/b", path);++ Mockito.when(config.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)).thenReturn("");+ kvBackend = new RocksDBKvBackend();+ path = kvBackend.getStoragePath(config);+ // We haven't set the GRAVITINO_HOME+ Assertions.assertEquals("null/data/rocksdb", path);+ }+@Testvoid testPutAndGet() throws IOException, RocksDBException {KvBackend kvBackend = getKvBackEnd();diff --git a/docs/gravitino-server-config.md b/docs/gravitino-server-config.mdindex b51a7231a7..7a4072b8db 100644--- a/docs/gravitino-server-config.md+++ b/docs/gravitino-server-config.md@@ -43,14 +43,14 @@ You can also specify filter parameters by setting configuration entries of the f### Storage configuration-| Configuration item | Description | Default value | Required | Since version |-|---------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|----------|---------------|-| `gravitino.entity.store` | Which storage implementation to use. Key-value pair storage is currently supported, and the default value is `kv`. | `kv` | No | 0.1.0 |-| `gravitino.entity.store.kv` | Detailed implementation of KV storage. `RocksDB` storage is currently supported, and the implementation is `RocksDBKvBackend`. | `RocksDBKvBackend` | No | 0.1.0 |-| `gravitino.entity.store.kv.rocksdbPath` | Directory path of `RocksDBKvBackend`. | `${GRAVITINO_HOME}/data/rocksdb` | No | 0.1.0 |-| `graivitino.entity.serde` | The serialization/deserialization class used to support entity storage. `proto' is currently supported. | `proto` | No | 0.1.0 |-| `gravitino.entity.store.maxTransactionSkewTimeMs` | The maximum skew time of transactions in milliseconds. | `2000` | No | 0.3.0 |-| `gravitino.entity.store.kv.deleteAfterTimeMs` | The maximum time in milliseconds that deleted and old-version data is kept. Set to at least 10 minutes and no longer than 30 days. | `604800000`(7 days) | No | 0.3.0 |+| Configuration item | Description | Default value | Required | Since version |+|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|----------|---------------|+| `gravitino.entity.store` | Which storage implementation to use. Key-value pair storage is currently supported, and the default value is `kv`. | `kv` | No | 0.1.0 |+| `gravitino.entity.store.kv` | Detailed implementation of KV storage. `RocksDB` storage is currently supported, and the implementation is `RocksDBKvBackend`. | `RocksDBKvBackend` | No | 0.1.0 |+| `gravitino.entity.store.kv.rocksdbPath` | The storage path for RocksDB storage implementation. It supports both absolute and relative path, if the value is a relative path, the final path is `${GRAVITINO_HOME}/${PATH_YOU_HAVA_SET}`, default value is `${GRAVITINO_HOME}/data/rocksdb` | `${GRAVITINO_HOME}/data/rocksdb` | No | 0.1.0 |+| `graivitino.entity.serde` | The serialization/deserialization class used to support entity storage. `proto' is currently supported. | `proto` | No | 0.1.0 |+| `gravitino.entity.store.maxTransactionSkewTimeMs` | The maximum skew time of transactions in milliseconds. | `2000` | No | 0.3.0 |+| `gravitino.entity.store.kv.deleteAfterTimeMs` | The maximum time in milliseconds that deleted and old-version data is kept. Set to at least 10 minutes and no longer than 30 days. | `604800000`(7 days) | No | 0.3.0 |:::cautionWe strongly recommend that you change the default value of `gravitino.entity.store.kv.rocksdbPath`, as it's under the deployment directory and future version upgrades may remove it.