-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix cross-close the underlying rocksdb session pool #598
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix cross-close the underlying rocksdb session pool
fix: #597 Change-Id: I8b185cd7f81a9a04bc6fd971490ae887fd4ddbb5
- Loading branch information
commit d4230ce449c521ab13d131655831cfef1f5fd634
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import java.util.Map; | ||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.rocksdb.BlockBasedTableConfig; | ||
import org.rocksdb.BloomFilter; | ||
|
@@ -63,13 +64,14 @@ | |
|
||
public class RocksDBStdSessions extends RocksDBSessions { | ||
|
||
private final Map<String, ColumnFamilyHandle> cfs = new HashMap<>(); | ||
|
||
private final RocksDB rocksdb; | ||
private final SstFileManager sstFileManager; | ||
|
||
public RocksDBStdSessions(HugeConfig config, String dataPath, | ||
String walPath, String database, String store) | ||
private final Map<String, ColumnFamilyHandle> cfs; | ||
private final AtomicInteger refCount; | ||
|
||
public RocksDBStdSessions(HugeConfig config, String database, String store, | ||
String dataPath,String walPath) | ||
throws RocksDBException { | ||
super(config, database, store); | ||
|
||
|
@@ -86,10 +88,13 @@ public RocksDBStdSessions(HugeConfig config, String dataPath, | |
* Don't merge old CFs, we expect a clear DB when using this one | ||
*/ | ||
this.rocksdb = RocksDB.open(options, dataPath); | ||
|
||
this.cfs = new HashMap<>(); | ||
this.refCount = new AtomicInteger(1); | ||
} | ||
|
||
public RocksDBStdSessions(HugeConfig config, String dataPath, | ||
String walPath, String database, String store, | ||
public RocksDBStdSessions(HugeConfig config, String database, String store, | ||
String dataPath, String walPath, | ||
List<String> cfNames) throws RocksDBException { | ||
super(config, database, store); | ||
|
||
|
@@ -121,13 +126,28 @@ public RocksDBStdSessions(HugeConfig config, String dataPath, | |
"Expect same size of cf-handles and cf-names"); | ||
|
||
// Collect CF Handles | ||
this.cfs = new HashMap<>(); | ||
for (int i = 0; i < cfs.size(); i++) { | ||
this.cfs.put(cfs.get(i), cfhs.get(i)); | ||
} | ||
|
||
this.refCount = new AtomicInteger(1); | ||
|
||
ingestExternalFile(); | ||
} | ||
|
||
private RocksDBStdSessions(HugeConfig config, String database, String store, | ||
RocksDBStdSessions origin) { | ||
super(config, database, store); | ||
|
||
this.rocksdb = origin.rocksdb; | ||
this.sstFileManager = origin.sstFileManager; | ||
this.cfs = origin.cfs; | ||
this.refCount = origin.refCount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this.refCount = origin.refCount.incrementAndGet(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They have to share the address of refCount |
||
|
||
this.refCount.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void open() throws Exception { | ||
// pass | ||
|
@@ -182,6 +202,12 @@ public String property(String property) { | |
} | ||
} | ||
|
||
@Override | ||
public RocksDBSessions copy(HugeConfig config, | ||
String database, String store) { | ||
return new RocksDBStdSessions(config, database, store, this); | ||
} | ||
|
||
@Override | ||
public final Session session() { | ||
return (Session) super.getOrNewSession(); | ||
|
@@ -198,6 +224,11 @@ protected final Session newSession() { | |
protected synchronized void doClose() { | ||
this.checkValid(); | ||
|
||
if (this.refCount.decrementAndGet() > 0) { | ||
return; | ||
} | ||
assert this.refCount.get() == 0; | ||
|
||
for (ColumnFamilyHandle cf : this.cfs.values()) { | ||
cf.close(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an empty between args