This is an automated email from the ASF dual-hosted git repository.

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f0ca58d442c Add memory repository for standalone mode (#35918)
f0ca58d442c is described below

commit f0ca58d442ce624e7f42d2519aba6e4f5c72aa9b
Author: Haoran Meng <[email protected]>
AuthorDate: Wed Jul 9 09:47:00 2025 +0800

    Add memory repository for standalone mode (#35918)
    
    * Add memory repository for standalone mode
    
    * Fix checkstyle
    
    * Fix checkstyle
    
    * Refactor MemoryRepository
    
    * Fix checkstyle
    
    * Fix checkstyle for MemoryRepository
    
    * Fix checkstyle for pom
    
    * Fix checkstyle
    
    * Remove useless dependency for memory repository
---
 distribution/jdbc/pom.xml                          |  7 +-
 distribution/proxy-native/pom.xml                  |  7 +-
 distribution/proxy/pom.xml                         |  7 +-
 jdbc/pom.xml                                       |  2 +-
 .../repository/standalone/jdbc/JDBCRepository.java |  5 --
 .../repository/provider/{ => memory}/pom.xml       | 22 +++--
 .../standalone/memory/MemoryRepository.java        | 99 ++++++++++++++++++++++
 ...pository.standalone.StandalonePersistRepository | 18 ++++
 .../standalone/memory/MemoryRepositoryTest.java    | 67 +++++++++++++++
 mode/type/standalone/repository/provider/pom.xml   |  1 +
 proxy/bootstrap/pom.xml                            |  7 +-
 test/e2e/agent/fixture/jdbc-fixture/pom.xml        |  6 ++
 test/e2e/driver/pom.xml                            |  6 ++
 test/e2e/fixture/pom.xml                           | 14 ++-
 14 files changed, 249 insertions(+), 19 deletions(-)

diff --git a/distribution/jdbc/pom.xml b/distribution/jdbc/pom.xml
index 8772aafda53..daaa910d95c 100644
--- a/distribution/jdbc/pom.xml
+++ b/distribution/jdbc/pom.xml
@@ -140,7 +140,12 @@
                     <version>${project.version}</version>
                     <scope>runtime</scope>
                 </dependency>
-                
+                <dependency>
+                    <groupId>org.apache.shardingsphere</groupId>
+                    
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+                    <version>${project.version}</version>
+                    <scope>runtime</scope>
+                </dependency>
                 <dependency>
                     <groupId>org.apache.shardingsphere</groupId>
                     
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
diff --git a/distribution/proxy-native/pom.xml 
b/distribution/proxy-native/pom.xml
index 9ce673aa5a3..635be03d6cc 100644
--- a/distribution/proxy-native/pom.xml
+++ b/distribution/proxy-native/pom.xml
@@ -231,7 +231,12 @@
                     <version>${project.version}</version>
                     <scope>runtime</scope>
                 </dependency>
-                
+                <dependency>
+                    <groupId>org.apache.shardingsphere</groupId>
+                    
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+                    <version>${project.version}</version>
+                    <scope>runtime</scope>
+                </dependency>
                 <dependency>
                     <groupId>org.apache.shardingsphere</groupId>
                     
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
diff --git a/distribution/proxy/pom.xml b/distribution/proxy/pom.xml
index e7505b2faf5..3956a02e75a 100644
--- a/distribution/proxy/pom.xml
+++ b/distribution/proxy/pom.xml
@@ -269,7 +269,12 @@
                     <version>${project.version}</version>
                     <scope>runtime</scope>
                 </dependency>
-                
+                <dependency>
+                    <groupId>org.apache.shardingsphere</groupId>
+                    
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+                    <version>${project.version}</version>
+                    <scope>runtime</scope>
+                </dependency>
                 <dependency>
                     <groupId>org.apache.shardingsphere</groupId>
                     
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
diff --git a/jdbc/pom.xml b/jdbc/pom.xml
index 769f75e22f0..77ebb413b7b 100644
--- a/jdbc/pom.xml
+++ b/jdbc/pom.xml
@@ -128,7 +128,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
+            
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
diff --git 
a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
 
b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
index 1e6bfc1322b..1591973c87b 100644
--- 
a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
+++ 
b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
@@ -232,9 +232,4 @@ public final class JDBCRepository implements 
StandalonePersistRepository {
     public String getType() {
         return "JDBC";
     }
-    
-    @Override
-    public boolean isDefault() {
-        return true;
-    }
 }
diff --git a/mode/type/standalone/repository/provider/pom.xml 
b/mode/type/standalone/repository/provider/memory/pom.xml
similarity index 65%
copy from mode/type/standalone/repository/provider/pom.xml
copy to mode/type/standalone/repository/provider/memory/pom.xml
index 0062b84cea6..5c02de5172e 100644
--- a/mode/type/standalone/repository/provider/pom.xml
+++ b/mode/type/standalone/repository/provider/memory/pom.xml
@@ -20,14 +20,22 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-standalone-mode-repository</artifactId>
+        
<artifactId>shardingsphere-standalone-mode-repository-provider</artifactId>
         <version>5.5.3-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-standalone-mode-repository-provider</artifactId>
-    <packaging>pom</packaging>
+    <artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
     <name>${project.artifactId}</name>
-    
-    <modules>
-        <module>jdbc</module>
-    </modules>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-standalone-mode-repository-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-test-util</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 </project>
diff --git 
a/mode/type/standalone/repository/provider/memory/src/main/java/org/apache/shardingsphere/mode/repository/standalone/memory/MemoryRepository.java
 
b/mode/type/standalone/repository/provider/memory/src/main/java/org/apache/shardingsphere/mode/repository/standalone/memory/MemoryRepository.java
new file mode 100644
index 00000000000..3e24e552818
--- /dev/null
+++ 
b/mode/type/standalone/repository/provider/memory/src/main/java/org/apache/shardingsphere/mode/repository/standalone/memory/MemoryRepository.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.repository.standalone.memory;
+
+import 
org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
+
+import java.util.List;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+/**
+ * Memory repository.
+ */
+public final class MemoryRepository implements StandalonePersistRepository {
+    
+    // CHECKSTYLE:OFF
+    private final TreeMap<String, String> metaDataSortedMap = new TreeMap<>();
+    // CHECKSTYLE:ON
+    
+    @Override
+    public String query(final String key) {
+        return metaDataSortedMap.get(key);
+    }
+    
+    @Override
+    public List<String> getChildrenKeys(final String key) {
+        String searchPrefix;
+        if (key.endsWith("/")) {
+            searchPrefix = key;
+        } else {
+            searchPrefix = key + "/";
+        }
+        String endBound = key + Character.MAX_VALUE;
+        return metaDataSortedMap.subMap(searchPrefix, true, endBound, 
false).keySet().stream()
+                .map(each -> {
+                    String remainder = each.substring(searchPrefix.length());
+                    int nextSlashIndex = remainder.indexOf('/');
+                    if (nextSlashIndex == -1) {
+                        return remainder;
+                    } else {
+                        return remainder.substring(0, nextSlashIndex);
+                    }
+                })
+                .filter(node -> !node.isEmpty())
+                .distinct()
+                .collect(Collectors.toList());
+    }
+    
+    @Override
+    public boolean isExisted(final String key) {
+        return metaDataSortedMap.containsKey(key);
+    }
+    
+    @Override
+    public void persist(final String key, final String value) {
+        metaDataSortedMap.put(key, value);
+    }
+    
+    @Override
+    public void update(final String key, final String value) {
+        if (metaDataSortedMap.containsKey(key)) {
+            metaDataSortedMap.put(key, value);
+        }
+    }
+    
+    @Override
+    public void delete(final String key) {
+        metaDataSortedMap.remove(key);
+    }
+    
+    @Override
+    public void close() {
+    }
+    
+    @Override
+    public Object getType() {
+        return "Memory";
+    }
+    
+    @Override
+    public boolean isDefault() {
+        return true;
+    }
+}
diff --git 
a/mode/type/standalone/repository/provider/memory/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository
 
b/mode/type/standalone/repository/provider/memory/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository
new file mode 100644
index 00000000000..ca2e86d56dc
--- /dev/null
+++ 
b/mode/type/standalone/repository/provider/memory/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.mode.repository.standalone.memory.MemoryRepository
diff --git 
a/mode/type/standalone/repository/provider/memory/src/test/java/org/apache/shardingsphere/mode/repository/standalone/memory/MemoryRepositoryTest.java
 
b/mode/type/standalone/repository/provider/memory/src/test/java/org/apache/shardingsphere/mode/repository/standalone/memory/MemoryRepositoryTest.java
new file mode 100644
index 00000000000..8a0fc65fd2e
--- /dev/null
+++ 
b/mode/type/standalone/repository/provider/memory/src/test/java/org/apache/shardingsphere/mode/repository/standalone/memory/MemoryRepositoryTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.repository.standalone.memory;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+class MemoryRepositoryTest {
+    
+    private final MemoryRepository memoryRepository = new MemoryRepository();
+    
+    @BeforeEach
+    void setUp() {
+        
memoryRepository.persist("/metadata/sharding_db/schemas/sharding_db/tables/t_order/versions/0",
 "t_order");
+        
memoryRepository.persist("/metadata/sharding_db/schemas/sharding_db/tables/t_user/versions/0",
 "t_user");
+        
memoryRepository.persist("/metadata/encrypt_db/schemas/encrypt_db/tables/t_encrypt_01/versions/0",
 "t_encrypt_01");
+        
memoryRepository.persist("/metadata/encrypt_db/schemas/encrypt_db/tables/t_encrypt_02/versions/0",
 "t_encrypt_02");
+    }
+    
+    @Test
+    void assertPersist() {
+        memoryRepository.persist("testKey", "testValue");
+        assertThat(memoryRepository.query("testKey"), is("testValue"));
+    }
+    
+    @Test
+    void assertUpdate() {
+        
memoryRepository.update("/metadata/sharding_db/schemas/sharding_db/tables/t_order/versions/0",
 "t_order_updated");
+        
assertThat(memoryRepository.query("/metadata/sharding_db/schemas/sharding_db/tables/t_order/versions/0"),
+                is("t_order_updated"));
+    }
+    
+    @Test
+    void assertDelete() {
+        
memoryRepository.delete("/metadata/sharding_db/schemas/sharding_db/tables/t_order/versions/0");
+        
assertThat(memoryRepository.isExisted("/metadata/sharding_db/schemas/sharding_db/tables/t_order/versions/0"),
 is(false));
+        
assertThat(memoryRepository.query("/metadata/sharding_db/schemas/sharding_db/tables/t_order/versions/0"),
 is((String) null));
+    }
+    
+    @Test
+    void assertGetChildrenKeys() {
+        assertThat(memoryRepository.getChildrenKeys("/metadata").size(), 
is(2));
+        
assertThat(memoryRepository.getChildrenKeys("/metadata").containsAll(Arrays.asList("encrypt_db",
 "sharding_db")), is(true));
+        
assertThat(memoryRepository.getChildrenKeys("/metadata/sharding_db/schemas/sharding_db/tables/").size(),
 is(2));
+        
assertThat(memoryRepository.getChildrenKeys("/metadata/encrypt_db/schemas/encrypt_db/tables/").size(),
 is(2));
+    }
+}
diff --git a/mode/type/standalone/repository/provider/pom.xml 
b/mode/type/standalone/repository/provider/pom.xml
index 0062b84cea6..2f0964ae358 100644
--- a/mode/type/standalone/repository/provider/pom.xml
+++ b/mode/type/standalone/repository/provider/pom.xml
@@ -29,5 +29,6 @@
     
     <modules>
         <module>jdbc</module>
+        <module>memory</module>
     </modules>
 </project>
diff --git a/proxy/bootstrap/pom.xml b/proxy/bootstrap/pom.xml
index 4b3cafe4998..bd0ff76279f 100644
--- a/proxy/bootstrap/pom.xml
+++ b/proxy/bootstrap/pom.xml
@@ -132,7 +132,12 @@
                     <version>${project.version}</version>
                     <scope>runtime</scope>
                 </dependency>
-                
+                <dependency>
+                    <groupId>org.apache.shardingsphere</groupId>
+                    
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+                    <version>${project.version}</version>
+                    <scope>runtime</scope>
+                </dependency>
                 <dependency>
                     <groupId>org.apache.shardingsphere</groupId>
                     
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
diff --git a/test/e2e/agent/fixture/jdbc-fixture/pom.xml 
b/test/e2e/agent/fixture/jdbc-fixture/pom.xml
index 25c689f8b8c..bd43cdcc2e0 100644
--- a/test/e2e/agent/fixture/jdbc-fixture/pom.xml
+++ b/test/e2e/agent/fixture/jdbc-fixture/pom.xml
@@ -51,6 +51,12 @@
             <version>${project.version}</version>
             <scope>runtime</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+            <version>${project.version}</version>
+            <scope>runtime</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
diff --git a/test/e2e/driver/pom.xml b/test/e2e/driver/pom.xml
index d274dd6e8e4..1758d915822 100644
--- a/test/e2e/driver/pom.xml
+++ b/test/e2e/driver/pom.xml
@@ -51,6 +51,12 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
diff --git a/test/e2e/fixture/pom.xml b/test/e2e/fixture/pom.xml
index 1e6c0ac40ed..27837d29479 100644
--- a/test/e2e/fixture/pom.xml
+++ b/test/e2e/fixture/pom.xml
@@ -78,7 +78,12 @@
             <version>${project.version}</version>
             <scope>runtime</scope>
         </dependency>
-        
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+            <version>${project.version}</version>
+            <scope>runtime</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>
@@ -206,7 +211,12 @@
                     <version>${project.version}</version>
                     <scope>runtime</scope>
                 </dependency>
-                
+                <dependency>
+                    <groupId>org.apache.shardingsphere</groupId>
+                    
<artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+                    <version>${project.version}</version>
+                    <scope>runtime</scope>
+                </dependency>
                 <dependency>
                     <groupId>org.apache.shardingsphere</groupId>
                     
<artifactId>shardingsphere-standalone-mode-repository-jdbc</artifactId>

Reply via email to