Skip to content

Commit e93bfc1

Browse files
committed
address reviewers' comments
1 parent ca5d8ad commit e93bfc1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

linera-storage/src/migration.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ use crate::{
2323

2424
#[derive(Debug)]
2525
enum SchemaVersion {
26+
/// No schema version detected.
27+
Uninitialized,
2628
/// Version 0. All the blobs, certificates, confirmed blocks, events and network
2729
/// description are on the same partition.
2830
Version0,
2931
/// Version 1. New partitions are assigned by chain ID, crypto hash, and blob ID.
3032
Version1,
3133
}
3234

33-
/// How long we should wait before retrying when we detect another migration in progress.
35+
/// How long we should wait (in minutes) before retrying when we detect another migration
36+
/// in progress.
3437
const MIGRATION_WAIT_BEFORE_RETRY_MIN: u64 = 3;
3538

3639
const UNUSED_EMPTY_KEY: &[u8] = &[];
@@ -142,7 +145,6 @@ where
142145
for key in chunk_base_keys {
143146
batch.delete_key(key.to_vec());
144147
}
145-
// Migrate chunk.
146148
store.write_batch(batch).await?;
147149
}
148150
Ok(())
@@ -161,7 +163,7 @@ where
161163
loop {
162164
if matches!(
163165
self.get_storage_state().await?,
164-
None | Some(SchemaVersion::Version1)
166+
SchemaVersion::Uninitialized | SchemaVersion::Version1
165167
) {
166168
// Nothing to do.
167169
return Ok(());
@@ -181,26 +183,29 @@ where
181183
}
182184
}
183185

184-
async fn get_storage_state(&self) -> Result<Option<SchemaVersion>, ViewError> {
186+
async fn get_storage_state(&self) -> Result<SchemaVersion, ViewError> {
185187
let store = self.database.open_shared(&[])?;
186188
let key = bcs::to_bytes(&BaseKey::NetworkDescription).unwrap();
187189
if store.contains_key(&key).await? {
188-
return Ok(Some(SchemaVersion::Version0));
190+
return Ok(SchemaVersion::Version0);
189191
}
190192

191193
let root_key = RootKey::NetworkDescription.bytes();
192194
let store = self.database.open_shared(&root_key)?;
193195
if store.contains_key(NETWORK_DESCRIPTION_KEY).await? {
194-
return Ok(Some(SchemaVersion::Version1));
196+
return Ok(SchemaVersion::Version1);
195197
}
196198

197-
Ok(None)
199+
Ok(SchemaVersion::Uninitialized)
198200
}
199201

200202
/// Assert that the storage is at the last version (or not yet initialized).
201203
pub async fn assert_is_migrated_storage(&self) -> Result<(), ViewError> {
202204
let state = self.get_storage_state().await?;
203-
assert!(matches!(state, None | Some(SchemaVersion::Version1)));
205+
assert!(matches!(
206+
state,
207+
SchemaVersion::Uninitialized | SchemaVersion::Version1
208+
));
204209
Ok(())
205210
}
206211
}

0 commit comments

Comments
 (0)