Skip to content

Commit

Permalink
refact(rocksdb): clean & reformat some code
Browse files Browse the repository at this point in the history
also mark TODO in some gists
  • Loading branch information
imbajin committed Apr 17, 2023
1 parent 7b6a4bd commit e7c7558
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.io.FileUtils;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.rocksdb.RocksDBIteratorPool.ReusedRocksIterator;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.rocksdb.Checkpoint;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDB;
import org.rocksdb.SstFileManager;
import org.slf4j.Logger;

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.rocksdb.RocksDBIteratorPool.ReusedRocksIterator;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;

public class OpenedRocksDB implements AutoCloseable {

private static final Logger LOG = Log.logger(OpenedRocksDB.class);
Expand Down Expand Up @@ -118,8 +117,7 @@ public void createCheckpoint(String targetPath) {
tempFile, snapshotFile));
}
} catch (Exception e) {
throw new BackendException("Failed to create checkpoint at path %s",
e, targetPath);
throw new BackendException("Failed to create checkpoint at path %s", e, targetPath);
}
}

Expand All @@ -137,8 +135,7 @@ public CFHandle(RocksDB rocksdb, ColumnFamilyHandle handle) {
}

public synchronized ColumnFamilyHandle get() {
E.checkState(this.handle.isOwningHandle(),
"It seems CF has been closed");
E.checkState(this.handle.isOwningHandle(), "It seems CF has been closed");
assert this.refs.get() >= 1;
return this.handle;
}
Expand All @@ -163,7 +160,7 @@ public void close() {

public synchronized ColumnFamilyHandle waitForDrop() {
assert this.refs.get() >= 1;
// When entering this method, the refs won't increase any more
// When entering this method, the refs won't increase anymore
final long timeout = TimeUnit.MINUTES.toMillis(30L);
final long unit = 100L;
for (long i = 1; this.refs.get() > 1; i++) {
Expand All @@ -173,8 +170,7 @@ public synchronized ColumnFamilyHandle waitForDrop() {
// 30s rest api timeout may cause InterruptedException
}
if (i * unit > timeout) {
throw new BackendException("Timeout after %sms to drop CF",
timeout);
throw new BackendException("Timeout after %sms to drop CF", timeout);
}
}
assert this.refs.get() == 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.util.Log;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.IngestExternalFileOptions;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.slf4j.Logger;

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.util.Log;

public class RocksDBIngester {

public static final String SST = ".sst";
Expand All @@ -52,8 +51,7 @@ public RocksDBIngester(RocksDB rocksdb) {
this.options.setMoveFiles(true);
}

public List<String> ingest(Path path, ColumnFamilyHandle cf)
throws RocksDBException {
public List<String> ingest(Path path, ColumnFamilyHandle cf) throws RocksDBException {
SuffixFileVisitor visitor = new SuffixFileVisitor(SST);
try {
Files.walkFileTree(path, visitor);
Expand All @@ -74,10 +72,8 @@ public List<String> ingest(Path path, ColumnFamilyHandle cf)
return ssts;
}

public void ingest(ColumnFamilyHandle cf, List<String> ssts)
throws RocksDBException {
LOG.info("Ingest sst files to CF '{}': {}",
RocksDBStdSessions.decode(cf.getName()), ssts);
public void ingest(ColumnFamilyHandle cf, List<String> ssts) throws RocksDBException {
LOG.info("Ingest sst files to CF '{}': {}", RocksDBStdSessions.decode(cf.getName()), ssts);
if (!ssts.isEmpty()) {
this.rocksdb.ingestExternalFile(cf, ssts, this.options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.util.Log;
import org.apache.hugegraph.util.StringEncoding;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
import org.slf4j.Logger;

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.util.Log;
import org.apache.hugegraph.util.StringEncoding;

public final class RocksDBIteratorPool implements AutoCloseable {

private static final Logger LOG = Log.logger(RocksDBIteratorPool.class);
Expand Down Expand Up @@ -149,6 +148,7 @@ private void closeIterator(RocksIterator iter) {

protected final class ReusedRocksIterator {

// TODO: is the typo "EREUSING_ENABLED" right? or should be "REUSING_ENABLED"?
private static final boolean EREUSING_ENABLED = false;
private final RocksIterator iterator;
private boolean closed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.hugegraph.util.Bytes;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.apache.hugegraph.util.UnitUtil;

import com.google.common.collect.ImmutableMap;

public class RocksDBMetrics implements BackendMetrics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import static org.apache.hugegraph.config.OptionChecker.rangeDouble;
import static org.apache.hugegraph.config.OptionChecker.rangeInt;

import org.rocksdb.CompactionStyle;
import org.rocksdb.CompressionType;
import org.rocksdb.DataBlockIndexType;
import org.rocksdb.IndexType;

import org.apache.hugegraph.config.ConfigConvOption;
import org.apache.hugegraph.config.ConfigListConvOption;
import org.apache.hugegraph.config.ConfigListOption;
import org.apache.hugegraph.config.ConfigOption;
import org.apache.hugegraph.config.OptionHolder;
import org.apache.hugegraph.util.Bytes;
import org.rocksdb.CompactionStyle;
import org.rocksdb.CompressionType;
import org.rocksdb.DataBlockIndexType;
import org.rocksdb.IndexType;

import com.google.common.collect.ImmutableList;

public class RocksDBOptions extends OptionHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import java.util.Set;

import org.apache.commons.lang3.tuple.Pair;
import org.rocksdb.RocksDBException;

import org.apache.hugegraph.backend.store.BackendEntry.BackendColumnIterator;
import org.apache.hugegraph.backend.store.BackendSession.AbstractBackendSession;
import org.apache.hugegraph.backend.store.BackendSessionPool;
import org.apache.hugegraph.config.HugeConfig;
import org.rocksdb.RocksDBException;

public abstract class RocksDBSessions extends BackendSessionPool {

Expand Down
Loading

0 comments on commit e7c7558

Please sign in to comment.