RocksIterator will sometimes Sigsegv on dispose. Mainly thats related to dispose order. If the related RocksDB instance is freed beforehand RocksIterator.dispose() will fail. Within this commit there is a major change to RocksIterator. RocksIterator will hold a private reference to the RocksDB instance which created the RocksIterator. So even if RocksDB is freed in the same GC cycle the RocksIterator instances will be freed prior to related RocksDB instances. Another aspect targets the dispose logic if the RocksDB is freed previously and already gc`ed. On dispose of a RocksIterator the dispose logic will check if the RocksDB instance points to an initialized DB. If not the dispose logic will not perform any further action. The crash can be reproduced by using the related test provided within this commit. Related information: This relates to @adamretter`s facebook rocksdb-dev group post about SigSegv on RocksIterator.dispose().main
parent
c1c68bce43
commit
56ef2caaa5
@ -0,0 +1,48 @@ |
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
package org.rocksdb.test; |
||||
|
||||
import org.rocksdb.ColumnFamilyHandle; |
||||
import org.rocksdb.Options; |
||||
import org.rocksdb.RocksDB; |
||||
import org.rocksdb.RocksDBException; |
||||
import org.rocksdb.RocksIterator; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class RocksIteratorTest { |
||||
static final String DB_PATH = "/tmp/rocksdbjni_iterator_test"; |
||||
static { |
||||
RocksDB.loadLibrary(); |
||||
} |
||||
|
||||
public static void main(String[] args){ |
||||
RocksDB db; |
||||
Options options = new Options(); |
||||
options.setCreateIfMissing(true) |
||||
.setCreateMissingColumnFamilies(true); |
||||
try { |
||||
db = RocksDB.open(options, DB_PATH); |
||||
db.put("key".getBytes(), "value".getBytes()); |
||||
RocksIterator iter = db.newIterator(); |
||||
RocksIterator iter2 = db.newIterator(); |
||||
RocksIterator iter3 = db.newIterator(); |
||||
iter = null; |
||||
db.close(); |
||||
db = null; |
||||
iter2 = null; |
||||
System.gc(); |
||||
System.runFinalization(); |
||||
System.out.println("Passed RocksIterator Test"); |
||||
iter3.dispose(); |
||||
System.gc(); |
||||
System.runFinalization(); |
||||
}catch (RocksDBException e){ |
||||
e.printStackTrace(); |
||||
assert(false); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue