Skip to content

Commit 22b2407

Browse files
committed
fix(server): ensure graph clear API does not clear system table
1 parent 45d95fe commit 22b2407

4 files changed

Lines changed: 28 additions & 33 deletions

File tree

hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public abstract class MysqlStore extends AbstractBackendStore<Session> {
5454
private final BackendStoreProvider provider;
5555

5656
private final Map<HugeType, MysqlTable> tables;
57-
5857
private MysqlSessions sessions;
5958

6059
public MysqlStore(final BackendStoreProvider provider,
@@ -338,6 +337,9 @@ protected void clearTables() {
338337
protected void truncateTables() {
339338
Session session = this.sessions.session();
340339
for (MysqlTable table : this.tables()) {
340+
if (table instanceof MysqlTables.Meta || table instanceof MysqlTables.Counters){
341+
continue;
342+
}
341343
table.truncate(session);
342344
}
343345
}

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import org.apache.hugegraph.unit.id.IdTest;
4747
import org.apache.hugegraph.unit.id.IdUtilTest;
4848
import org.apache.hugegraph.unit.id.SplicingIdGeneratorTest;
49+
import org.apache.hugegraph.unit.mysql.BaseMysqlUnitTest;
50+
import org.apache.hugegraph.unit.mysql.MysqlTest;
4951
import org.apache.hugegraph.unit.mysql.MysqlUtilTest;
5052
import org.apache.hugegraph.unit.mysql.WhereBuilderTest;
5153
import org.apache.hugegraph.unit.rocksdb.RocksDBCountersTest;
@@ -130,6 +132,8 @@
130132
/* mysql */
131133
MysqlUtilTest.class,
132134
WhereBuilderTest.class,
135+
BaseMysqlUnitTest.class,
136+
MysqlTest.class,
133137

134138
/* rocksdb */
135139
RocksDBSessionsTest.class,

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/mysql/BaseMysqlUnitTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,41 @@
1919

2020
package org.apache.hugegraph.unit.mysql;
2121

22+
import org.apache.commons.configuration2.Configuration;
2223
import org.apache.hugegraph.backend.store.BackendStore;
2324
import org.apache.hugegraph.backend.store.hbase.HbaseStoreProvider;
2425
import org.apache.hugegraph.backend.store.mysql.MysqlStoreProvider;
2526
import org.apache.hugegraph.config.HugeConfig;
27+
import org.apache.hugegraph.testutil.Utils;
2628
import org.apache.hugegraph.unit.BaseUnitTest;
2729
import org.apache.hugegraph.unit.FakeObjects;
2830
import org.junit.After;
2931
import org.junit.Before;
3032

3133
public class BaseMysqlUnitTest extends BaseUnitTest {
32-
protected BackendStore store;
34+
35+
private static final String GRAPH_NAME = "test_graph";
3336

3437
protected HugeConfig config;
3538
protected MysqlStoreProvider provider;
3639

37-
@Before
3840
public void setup() {
39-
this.config = FakeObjects.newConfig();
40-
41+
try {
42+
Configuration conf = Utils.getConf();
43+
this.config = new HugeConfig(conf);
44+
} catch (Exception e) {
45+
this.config = FakeObjects.newConfig();
46+
}
4147
this.provider = new MysqlStoreProvider();
42-
43-
this.store = this.provider.loadSystemStore(config);
48+
this.provider.open(GRAPH_NAME);
49+
this.provider.loadSystemStore(config).open(config);
50+
this.provider.loadGraphStore(config).open(config);
51+
this.provider.loadSchemaStore(config).open(config);
52+
this.provider.init();
4453
}
4554

4655
@After
4756
public void down(){
48-
if (this.store != null) {
49-
try {
50-
this.store.close();
51-
} catch (Exception e) {
52-
// pass
53-
}
54-
}
5557
if (this.provider != null) {
5658
try {
5759
this.provider.close();

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/mysql/MysqlTest.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,24 @@
1919

2020
package org.apache.hugegraph.unit.mysql;
2121

22+
import org.apache.hugegraph.backend.store.BackendStore;
2223
import org.apache.hugegraph.testutil.Assert;
2324
import org.junit.After;
2425
import org.junit.Before;
2526
import org.junit.Test;
2627

2728
public class MysqlTest extends BaseMysqlUnitTest{
28-
private static final String GRAPH_NAME = "test_graph";
29-
3029
@Before
3130
public void setUp(){
32-
this.provider.open(GRAPH_NAME);
33-
this.provider.init();
34-
}
35-
36-
@After
37-
public void teardown(){
38-
if (this.store != null) {
39-
this.store.close();
40-
}
41-
if (this.provider != null) {
42-
this.provider.close();
43-
}
31+
super.setup();
4432
}
4533

4634
@Test
4735
public void testMysqlMetaVersion(){
48-
// init store
49-
this.store.init();
50-
String beforeVersion = this.store.storedVersion();
51-
this.store.truncate();
52-
String afterInitVersion = this.store.storedVersion();
36+
BackendStore systemStore = this.provider.loadSystemStore(config);
37+
String beforeVersion = systemStore.storedVersion();
38+
this.provider.truncate();
39+
String afterInitVersion = systemStore.storedVersion();
5340
Assert.assertNotNull(beforeVersion);
5441
Assert.assertNotNull(afterInitVersion);
5542
Assert.assertEquals(beforeVersion, afterInitVersion);

0 commit comments

Comments
 (0)