blackbox: preserve session_id when replacing singleton

Summary:
The current API replaces `session_id` when the global blackbox switched
from in-memory to on-disk. It should preserve the session id.

Reviewed By: singhsrb

Differential Revision: D17429691

fbshipit-source-id: d37811c3d7622c4f86615c41bce40f4e479eabd2
This commit is contained in:
Jun Wu 2019-09-20 17:43:59 -07:00 committed by Facebook Github Bot
parent a108ea0c6f
commit 2b076c4b17
2 changed files with 4 additions and 1 deletions

View File

@ -26,7 +26,7 @@ pub struct Blackbox {
opts: BlackboxOptions,
// An ID that can be "grouped by" to figure everything about a session.
session_id: u64,
pub(crate) session_id: u64,
// The on-disk files are considered bad (ex. no permissions, or no disk space)
// and further write attempts will be ignored.

View File

@ -20,6 +20,8 @@ lazy_static! {
/// Replace the global [`Blackbox`] instance.
///
/// The session ID of the old blackbox will be reused.
///
/// If [`log`] was called, their side effects will be re-applied to the
/// specified blackbox.
pub fn init(mut blackbox: Blackbox) {
@ -34,6 +36,7 @@ pub fn init(mut blackbox: Blackbox) {
}
}
}
blackbox.session_id = old_blackbox.session_id;
*singleton.deref_mut() = blackbox;
}