@@ -21,17 +21,9 @@ class RocksDBManager(dataDir: Path, columnFamilies: List[String], optionsFilePat
2121
2222 val (db : RocksDB , columnFamilyHandles) = {
2323 RocksDB .loadLibrary()
24- val columnOptions = new ColumnFamilyOptions ()
25- .setArenaBlockSize(4 * 1024 * 1024 ) // 4MB
26- .setTargetFileSizeBase(1024 * 1024 * 1024 ) // 1GB
27- .setMaxBytesForLevelBase(10 * 1024 * 1024 * 1024 ) // 10GB
28- val columnFamilyDescriptors = (columnFamilies.map(_.getBytes) :+ RocksDB .DEFAULT_COLUMN_FAMILY ).map { columnFamily =>
29- new ColumnFamilyDescriptor (columnFamily, columnOptions)
30- }
31- val columnFamilyHandles = new util.ArrayList [ColumnFamilyHandle ]
32- var options = new DBOptions ()
33- var cfListRef : mutable.Buffer [ColumnFamilyDescriptor ] = mutable.Buffer ()
34- optionsFilePathOpt.map { optionsFilePath =>
24+ val options = new DBOptions ().setCreateIfMissing(true ).setCreateMissingColumnFamilies(true )
25+ val cfListRef : mutable.Buffer [ColumnFamilyDescriptor ] = mutable.Buffer ()
26+ optionsFilePathOpt.foreach { optionsFilePath =>
3527 try {
3628 org.rocksdb.OptionsUtil .loadOptionsFromFile(optionsFilePath, Env .getDefault, options, cfListRef.asJava)
3729 logger.info(" successfully loaded rocksdb options from " + optionsFilePath)
@@ -41,10 +33,10 @@ class RocksDBManager(dataDir: Path, columnFamilies: List[String], optionsFilePat
4133 }
4234 }
4335 }
44- options = options
45- .setCreateIfMissing(true )
46- .setCreateMissingColumnFamilies(true )
36+ val newColumnFamilyDescriptors = (columnFamilies.map(_.getBytes) :+ RocksDB .DEFAULT_COLUMN_FAMILY ).diff(cfListRef.toList.map(_.getName)).map(new ColumnFamilyDescriptor (_))
37+ val columnFamilyDescriptors = cfListRef.toList ::: newColumnFamilyDescriptors
4738 logger.info(" Opening RocksDB at " + dataDir.toAbsolutePath)
39+ val columnFamilyHandles = new util.ArrayList [ColumnFamilyHandle ]
4840 val db = RocksDB .open(
4941 options,
5042 dataDir.toAbsolutePath.toString,
@@ -100,7 +92,7 @@ class RocksDBIterator(it: RocksIterator, prefix: Option[String]) extends Iterato
10092 override def hasNext : Boolean = it.isValid && prefix.forall(it.key().startsWith(_))
10193
10294 override def next : KeyValuePair [Array [Byte ]] = {
103- val value = KeyValuePair (new String (it.key().map(_.toChar)) , it.value())
95+ val value = KeyValuePair (new String (it.key().map(_.toChar)), it.value())
10496 it.next()
10597 value
10698 }
0 commit comments