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 8f84e08
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
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 @@ -141,7 +141,7 @@ public boolean close() {
this.doClose();
}
}
LOG.debug("Now(after close({})) session count is: {}, " +
LOG.error("Now(after close({})) session count is: {}, " +
"current session reference is: {}",
this, result.getLeft(), result.getRight());
return result.getLeft() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ public void reloadRocksDB() throws RocksDBException {
this.walPath);
}

public boolean forceCLose() {
if (!this.rocksdb.isOwningHandle()) {
return false;
}
this.rocksdb().close();
return true;
}

@Override
public void forceCloseRocksDB() {
this.rocksdb().close();
Expand Down Expand Up @@ -343,6 +351,14 @@ protected synchronized void doClose() {
this.rocksdb.close();
}

public synchronized void forceClose() {
if (!this.rocksdb.isOwningHandle()) {
return;
}
this.refCount.set(0);
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 8f84e08

Please sign in to comment.