Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ public void truncate() {
"Failed to truncate table for '%s' store", e, this.store);
}
Copy link
Member

Choose a reason for hiding this comment

The 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.


this.init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ Root cause analysis: Design issue in truncate implementation

After reviewing the code, I found the real problem:

Current Issue:

  • HbaseSystemStore.tableNames() (line 572-576) includes the meta table in the list
  • truncate() clears ALL tables returned by tableNames(), including the meta table
  • Adding init() is a workaround, but meta table should never be cleared in the first place

Proper Fix:
Override truncate() in HbaseSystemStore to exclude meta table:

@Override
public void truncate() {
    // Save meta table before truncate
    List<String> originalTables = this.tableNames();
    
    // Temporarily remove meta table from truncation
    // Then call super.truncate() on data tables only
    // Or better: add a separate method tableNamesToTruncate()
}

Alternative approach (cleaner):

protected List<String> tableNamesToTruncate() {
    // Only return data tables, not meta/system tables
    return super.tableNames(); // Don't include meta.table()
}

Then use tableNamesToTruncate() in the truncate() method instead of tableNames().

This matches how MySQL backend works - it only truncates data tables, never system tables.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution is indeed a superior approach. By overriding the truncate() method to exclude metadata tables, we are solving the problem at the design level, which is far more elegant and robust than relying on a temporary solution involving initialization calls.

I will proceed with the modifications as suggested, implementing this fix for the HBase backend. For consistency, I will also apply the same change to the MySQL backend in the corresponding PR (#2888).

Regarding the current implementation for the RocksDB backend, which uses the direct init() call workaround, I believe it should also be optimized. Adopting this unified strategy of overriding the truncate() method will enhance code consistency and maintainability across all backends.Here is the implementation of the truncate() method in RocksStore.

    @Override
    public synchronized void truncate() {
        Lock writeLock = this.storeLock.writeLock();
        writeLock.lock();
        try {
            this.checkOpened();

            this.clear(false);
            this.init();
            // Clear write-batch
            this.dbs.values().forEach(BackendSessionPool::forceResetSessions);
            LOG.debug("Store truncated: {}", this.store);
        } finally {
            writeLock.unlock();
        }
    }

Thank you again for your valuable feedback. It has truly helped me arrive at a much more elegant solution!


LOG.debug("Store truncated: {}", this.store);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
*
* * 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong header format

*
*/

package org.apache.hugegraph.unit.hbase;

import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.hbase.HbaseStoreProvider;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.unit.BaseUnitTest;
import org.apache.hugegraph.unit.FakeObjects;
import org.junit.After;
import org.junit.Before;

Copy link
Member

Choose a reason for hiding this comment

The 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 {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Missing space after class declaration

Suggested change
public class BaseHbaseUnitTest extends BaseUnitTest {

public class BaseHbaseUnitTest extends BaseUnitTest{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Code Style: Formatting

Missing space after class declaration:

Suggested change
public class BaseHbaseUnitTest extends BaseUnitTest{
public class BaseHbaseUnitTest extends BaseUnitTest {


protected BackendStore store;

protected HugeConfig config;
protected HbaseStoreProvider provider;

@Before
public void setup() {
this.config = FakeObjects.newConfig();

this.provider = new HbaseStoreProvider();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ Critical: Potential resource leak in setup()

If any exception occurs after opening stores but before sessions.open(), the opened stores won't be properly closed. This can lead to resource leaks in test execution.

Suggested change
this.provider = new HbaseStoreProvider();
@Before
public void setup() throws IOException {
Configuration conf = Utils.getConf();
this.config = new HugeConfig(conf);
this.provider = new HbaseStoreProvider();
try {
this.provider.open(GRAPH_NAME);
this.provider.loadSystemStore(config).open(config);
this.provider.loadGraphStore(config).open(config);
this.provider.loadSchemaStore(config).open(config);
this.provider.init();
this.sessions = new HbaseSessions(config, GRAPH_NAME,
this.provider.loadGraphStore(config).store());
this.sessions.open();
} catch (Exception e) {
tearDown();
throw e;
}
}


this.store = this.provider.loadSystemStore(config);
}

@After
public void down(){
Copy link
Member

Choose a reason for hiding this comment

The 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
public void down(){
@After
public void down(){
if (this.store != null) {
try {
this.store.close();
} catch (Exception e) {
LOG.warn("Failed to close store", e);
}
}
if (this.provider != null) {
try {
this.provider.close();
} catch (Exception e) {
LOG.warn("Failed to close provider", e);
}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Missing space after comma in log statement

Suggested change
public void down(){
LOG.warn("Failed to close provider", e);

if (this.store != null) {
try {
this.store.close();
} catch (Exception e) {
// pass
}
}
if (this.provider != null) {
try {
this.provider.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Code style: inconsistent spacing

Missing space after catch keyword.

Suggested change
this.provider.close();
} catch (Exception e) {

} catch (Exception e) {
// pass
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
*
* * 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.testutil.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class HbaseUnitTest extends BaseHbaseUnitTest {

private static final String GRAPH_NAME = "test_graph";

@Before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Test setup/teardown issue

Both BaseHbaseUnitTest and HbaseUnitTest have setup/teardown methods that may cause issues:

  1. Duplicate cleanup: @After in both base and child class will close store/provider twice
  2. Setup order: Child's @Before runs after parent's, but calls provider.open() which may conflict

Suggestion:

Suggested change
@Before
@Before
public void setUp(){
super.setup(); // Call parent setup first
this.provider.open(GRAPH_NAME);
this.provider.init();
}
@After
public void teardown(){
// Remove duplicate cleanup - handled by parent
// Only add child-specific cleanup here if needed
}

public void setUp(){
this.provider.open(GRAPH_NAME);
this.provider.init();
}

@After
public void teardown(){
if (this.store != null) {
this.store.close();
}
if (this.provider != null) {
this.provider.close();
}
}

@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Test coverage insufficient

The test only verifies version equality but doesn't validate:

  1. Meta table content: Check that specific meta entries (like backend version, graph name, etc.) are preserved
  2. Data table clearing: Verify that actual graph data (vertices, edges) are properly cleared
  3. Concurrent operations: Test behavior when truncate is called during other operations

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 ...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Incomplete Test Coverage

The test only verifies that meta version is preserved, but doesn't verify the actual truncation behavior. Consider adding assertions to verify:

  1. Data tables are actually truncated (e.g., insert some data, truncate, verify data is gone)
  2. Meta table content remains intact
  3. The graph can be used normally after truncation

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 testHbaseMetaVersion(){
// init store
this.store.init();
String beforeVersion = this.store.storedVersion();
this.store.truncate();
String afterInitVersion = this.store.storedVersion();
Assert.assertNotNull(beforeVersion);
Assert.assertNotNull(afterInitVersion);
Assert.assertEquals(beforeVersion, afterInitVersion);
}
}
Loading