Make wal_storage initialization eager (#1489)

This commit is contained in:
Arthur Petukhovsky
2022-04-11 20:36:26 +03:00
committed by GitHub
parent 214567bf8f
commit 8e2a6661e9
2 changed files with 12 additions and 10 deletions

View File

@@ -517,14 +517,16 @@ where
pub fn new(
ztli: ZTimelineId,
control_store: CTRL,
wal_store: WAL,
mut wal_store: WAL,
state: SafeKeeperState,
) -> SafeKeeper<CTRL, WAL> {
) -> Result<SafeKeeper<CTRL, WAL>> {
if state.timeline_id != ZTimelineId::from([0u8; 16]) && ztli != state.timeline_id {
panic!("Calling SafeKeeper::new with inconsistent ztli ({}) and SafeKeeperState.server.timeline_id ({})", ztli, state.timeline_id);
bail!("Calling SafeKeeper::new with inconsistent ztli ({}) and SafeKeeperState.server.timeline_id ({})", ztli, state.timeline_id);
}
SafeKeeper {
wal_store.init_storage(&state)?;
Ok(SafeKeeper {
metrics: SafeKeeperMetrics::new(state.tenant_id, ztli),
global_commit_lsn: state.commit_lsn,
epoch_start_lsn: Lsn(0),
@@ -537,7 +539,7 @@ where
s: state,
control_store,
wal_store,
}
})
}
/// Get history of term switches for the available WAL
@@ -877,7 +879,7 @@ mod tests {
};
let wal_store = DummyWalStore { lsn: Lsn(0) };
let ztli = ZTimelineId::from([0u8; 16]);
let mut sk = SafeKeeper::new(ztli, storage, wal_store, SafeKeeperState::empty());
let mut sk = SafeKeeper::new(ztli, storage, wal_store, SafeKeeperState::empty()).unwrap();
// check voting for 1 is ok
let vote_request = ProposerAcceptorMessage::VoteRequest(VoteRequest { term: 1 });
@@ -892,7 +894,7 @@ mod tests {
let storage = InMemoryState {
persisted_state: state.clone(),
};
sk = SafeKeeper::new(ztli, storage, sk.wal_store, state);
sk = SafeKeeper::new(ztli, storage, sk.wal_store, state).unwrap();
// and ensure voting second time for 1 is not ok
vote_resp = sk.process_msg(&vote_request);
@@ -909,7 +911,7 @@ mod tests {
};
let wal_store = DummyWalStore { lsn: Lsn(0) };
let ztli = ZTimelineId::from([0u8; 16]);
let mut sk = SafeKeeper::new(ztli, storage, wal_store, SafeKeeperState::empty());
let mut sk = SafeKeeper::new(ztli, storage, wal_store, SafeKeeperState::empty()).unwrap();
let mut ar_hdr = AppendRequestHeader {
term: 1,

View File

@@ -100,7 +100,7 @@ impl SharedState {
let state = SafeKeeperState::new(zttid, peer_ids);
let control_store = control_file::FileStorage::new(zttid, conf);
let wal_store = wal_storage::PhysicalStorage::new(zttid, conf);
let mut sk = SafeKeeper::new(zttid.timeline_id, control_store, wal_store, state);
let mut sk = SafeKeeper::new(zttid.timeline_id, control_store, wal_store, state)?;
sk.control_store.persist(&sk.s)?;
Ok(Self {
@@ -127,7 +127,7 @@ impl SharedState {
Ok(Self {
notified_commit_lsn: Lsn(0),
sk: SafeKeeper::new(zttid.timeline_id, control_store, wal_store, state),
sk: SafeKeeper::new(zttid.timeline_id, control_store, wal_store, state)?,
replicas: Vec::new(),
active: false,
num_computes: 0,