Skip to content

Commit 82d5af2

Browse files
committed
f Add validate_data flag
1 parent 94ce349 commit 82d5af2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lightning/src/util/persist.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,14 @@ pub trait MigratableKVStore: KVStore {
182182
/// might get overriden. User must ensure `source_store` is not modified during operation,
183183
/// otherwise no consistency guarantees can be given.
184184
///
185+
/// Will re-read and validate the written data if `validate_data` is set.
186+
///
185187
/// Will abort and return an error if any IO operation fails. Note that in this case the
186188
/// `target_store` might get left in an intermediate state.
187189
///
188190
/// **Caution**: Will delete all data from `source_store` if `move_data` is set.
189191
pub fn migrate_kv_store_data<S: MigratableKVStore, T: MigratableKVStore>(
190-
source_store: &mut S, target_store: &mut T, move_data: bool,
192+
source_store: &mut S, target_store: &mut T, validate_data: bool, move_data: bool,
191193
) -> Result<(), io::Error> {
192194
let keys_to_migrate = source_store.list_all_keys()?;
193195

@@ -197,11 +199,13 @@ pub fn migrate_kv_store_data<S: MigratableKVStore, T: MigratableKVStore>(
197199
target_store.write(primary_namespace, secondary_namespace, key, &data)?;
198200

199201
// Now validate what we've written.
200-
let read_data = target_store.read(primary_namespace, secondary_namespace, &key)?;
201-
if data != read_data {
202-
let err =
203-
io::Error::new(io::ErrorKind::InvalidData, "Failed to validate migrated data");
204-
return Err(err);
202+
if validate_data {
203+
let read_data = target_store.read(primary_namespace, secondary_namespace, &key)?;
204+
if data != read_data {
205+
let err =
206+
io::Error::new(io::ErrorKind::InvalidData, "Failed to validate migrated data");
207+
return Err(err);
208+
}
205209
}
206210
}
207211

0 commit comments

Comments
 (0)