public void RotateMemTable() {
lock (memTableRotationLock) {
// Double check the flag in case we have multiple threads that make it into this routine
if (_currentJournaledMemTable.Full) {
_rotationSemaphore.WaitOne(); // Wait for the rotation gate to be open, and automatically reset once a single thread gets through.
_rotatedJournaledMemTable = Interlocked.Exchange<JournaledMemTable>(ref _currentJournaledMemTable, new JournaledMemTable(_manifest.BaseFileName, _manifest.NextVersion(0)));
ThreadPool.QueueUserWorkItem((o) => {
try {
_rotatedJournaledMemTable.WriteToSortedBlockTable(_manifest);
_rotatedJournaledMemTable = null;
} finally {
_rotationSemaphore.Release(); // Open the gate for the next rotation
}
});
}
}
}
#pragma warning restore 420