Skip to content

Commit

Permalink
fix: rocksdb lock avaliable
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Dec 16, 2023
1 parent c0e05d0 commit 20704bb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ public synchronized void close() throws Exception {
this.closeTx();
} finally {
this.closed = true;
this.storeProvider.close();
LockUtil.destroy(this.name);
this.storeProvider.close();
}
// Make sure that all transactions are closed in all threads
if (!tx.closed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ protected synchronized void doClose() {
this.rocksdb.close();
}

public synchronized void forceClose() {
if (!this.rocksdb.isOwningHandle()) {
return;
}
this.rocksdb.close();
}

private void checkValid() {
E.checkState(this.rocksdb.isOwningHandle(),
"It seems RocksDB has been closed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ public void close() {
this.closeSessions();
}

public void forceClose() {
try {
this.checkOpened();
this.closeSessions();
} catch (Throwable ignore) {
return;
}
((RocksDBStdSessions)this.sessions).forceClose();
}

@Override
public boolean opened() {
this.checkDbOpened();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@

import java.io.File;

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.AbstractBackendStoreProvider;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.util.ConfigUtil;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;

public class RocksDBStoreProvider extends AbstractBackendStoreProvider {

private static final Logger LOG = Log.logger(RocksDBStoreProvider.class);

protected String database() {
return this.graph().toLowerCase();
}
Expand Down Expand Up @@ -68,6 +73,29 @@ protected BackendStore newSystemStore(HugeConfig config, String store) {
return new RocksDBStore.RocksDBSystemStore(this, this.database(), store);
}

@Override
public void close() throws BackendException {
super.close();
if (this.stores == null) {
return;
}
this.stores.values().forEach(store -> {
try {
if (!store.opened()) {
return;
}
} catch (Throwable ignore) {
return;
}
try {
((RocksDBStore)store).forceClose();
} catch (Exception e) {
LOG.error("Failed to close store '%s'", store.store(), e);
throw new BackendException("Failed to close store '%s'", store.store(), e);
}
});
}

@Override
public String type() {
return "rocksdb";
Expand Down

0 comments on commit 20704bb

Please sign in to comment.