-
Notifications
You must be signed in to change notification settings - Fork 615
fix(server): ensure graph clear API does not clear meta table for hbase #2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
fbb5e04
9c810fd
004684e
7676f54
06a09eb
2bba644
77f20b7
3eb35c0
aa5a973
cd658fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -114,6 +114,14 @@ protected List<String> tableNames() { | |||||||||||||||
| .collect(Collectors.toList()); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| protected List<String> truncatedTableNames() { | ||||||||||||||||
| return this.tables.values().stream() | ||||||||||||||||
| .filter(table -> !(table instanceof HbaseTables.Meta || | ||||||||||||||||
| table instanceof HbaseTables.Counters)) | ||||||||||||||||
| .map(BackendTable::table) | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Only the
Suggested change
|
||||||||||||||||
| .collect(Collectors.toList()); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public String namespace() { | ||||||||||||||||
| return this.namespace; | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -371,7 +379,7 @@ public void truncate() { | |||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| // Truncate tables | ||||||||||||||||
| List<String> tables = this.tableNames(); | ||||||||||||||||
| List<String> tables = this.truncatedTableNames(); | ||||||||||||||||
| Map<String, Future<Void>> futures = new HashMap<>(tables.size()); | ||||||||||||||||
|
|
||||||||||||||||
| try { | ||||||||||||||||
|
|
@@ -401,7 +409,6 @@ public void truncate() { | |||||||||||||||
| throw new BackendException( | ||||||||||||||||
| "Failed to truncate table for '%s' store", e, this.store); | ||||||||||||||||
| } | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Minor: Unnecessary Whitespace Change Removing this blank line is cosmetic and adds noise to the diff without functional benefit. Consider keeping the original formatting to make the diff cleaner and focus on actual logic changes. |
||||||||||||||||
|
|
||||||||||||||||
| LOG.debug("Store truncated: {}", this.store); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||
| * * 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. | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong header format |
||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| package org.apache.hugegraph.unit.hbase; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.commons.configuration2.Configuration; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hugegraph.backend.store.hbase.HbaseStoreProvider; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hugegraph.config.HugeConfig; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hugegraph.testutil.Utils; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hugegraph.unit.BaseUnitTest; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.After; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Naming: Space missing in class declaration Minor style issue:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| public class BaseHbaseUnitTest extends BaseUnitTest{ | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Code Style: Formatting Missing space after class declaration:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| private static final String GRAPH_NAME = "test_graph"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| protected HugeConfig config; | ||||||||||||||||||||||||||||||||||||||||||||
| protected HbaseStoreProvider provider; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| public void setup() { | ||||||||||||||||||||||||||||||||||||||||||||
| Configuration conf = Utils.getConf(); | ||||||||||||||||||||||||||||||||||||||||||||
| this.config = new HugeConfig(conf); | ||||||||||||||||||||||||||||||||||||||||||||
| this.provider = new HbaseStoreProvider(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If any exception occurs after opening stores but before
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| this.provider.open(GRAPH_NAME); | ||||||||||||||||||||||||||||||||||||||||||||
| this.provider.loadSystemStore(config).open(config); | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For code consistency, add a space after commas in method calls.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| this.provider.loadGraphStore(config).open(config); | ||||||||||||||||||||||||||||||||||||||||||||
| this.provider.loadSchemaStore(config).open(config); | ||||||||||||||||||||||||||||||||||||||||||||
| this.provider.init(); | ||||||||||||||||||||||||||||||||||||||||||||
|
imbajin marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @After | ||||||||||||||||||||||||||||||||||||||||||||
| public void down(){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Code quality: Silent exception swallowing Using empty catch blocks makes debugging difficult. Consider:
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| if (this.provider != null) { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| this.provider.close(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Code style: inconsistent spacing Missing space after
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||
| LOG.warn("Failed to close provider",e); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||
| * * 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.hugegraph.unit.hbase; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import org.apache.hugegraph.backend.store.BackendStore; | ||||||||||||||||||||||||||||
| import org.apache.hugegraph.testutil.Assert; | ||||||||||||||||||||||||||||
| import org.junit.Before; | ||||||||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public class HbaseUnitTest extends BaseHbaseUnitTest { | ||||||||||||||||||||||||||||
| @Before | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||
| public void setUp(){ | ||||||||||||||||||||||||||||
| super.setup(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test only verifies version equality but doesn't validate:
Suggestion: @Test
public void testHbaseMetaVersion(){
// Insert some test data
// ... add vertices/edges ...
String beforeVersion = this.store.storedVersion();
// Get other meta entries
this.store.truncate();
String afterVersion = this.store.storedVersion();
Assert.assertEquals(beforeVersion, afterVersion);
// Verify data is cleared but meta is intact
// ... check vertices/edges are gone ...
// ... check other meta entries preserved ...
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test only verifies that meta version is preserved, but doesn't verify the actual truncation behavior. Consider adding assertions to verify:
Example enhancement: @Test
public void testHbaseMetaVersionAfterTruncate() {
BackendStore systemStore = this.provider.loadSystemStore(config);
BackendStore graphStore = this.provider.loadGraphStore(config);
// Record initial version
String beforeVersion = systemStore.storedVersion();
// Insert some test data to verify truncation
// ... add test data insertion code ...
// Perform truncation
this.provider.truncate();
// Verify version preserved
String afterVersion = systemStore.storedVersion();
Assert.assertEquals(beforeVersion, afterVersion);
// Verify data tables are empty
// ... add verification code ...
} |
||||||||||||||||||||||||||||
| public void testMysqlMetaVersion(){ | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test method is named
Suggested change
This makes the test's purpose clearer and matches the actual functionality being tested. |
||||||||||||||||||||||||||||
| BackendStore systemStore = this.provider.loadSystemStore(config); | ||||||||||||||||||||||||||||
| String beforeVersion = systemStore.storedVersion(); | ||||||||||||||||||||||||||||
| this.provider.truncate(); | ||||||||||||||||||||||||||||
| String afterInitVersion = systemStore.storedVersion(); | ||||||||||||||||||||||||||||
| Assert.assertNotNull(beforeVersion); | ||||||||||||||||||||||||||||
| Assert.assertNotNull(afterInitVersion); | ||||||||||||||||||||||||||||
| Assert.assertEquals(beforeVersion, afterInitVersion); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name
truncatedTableNames()is grammatically incorrect and misleading. It suggests tables that have already been truncated, when it actually returns tables that SHOULD be truncated.Alternative names:
getClearableTableNames(),getDataTableNames(), orgetTableNamesExcludingMeta()