@@ -182,12 +182,14 @@ pub trait MigratableKVStore: KVStore {
182
182
/// might get overriden. User must ensure `source_store` is not modified during operation,
183
183
/// otherwise no consistency guarantees can be given.
184
184
///
185
+ /// Will re-read and validate the written data if `validate_data` is set.
186
+ ///
185
187
/// Will abort and return an error if any IO operation fails. Note that in this case the
186
188
/// `target_store` might get left in an intermediate state.
187
189
///
188
190
/// **Caution**: Will delete all data from `source_store` if `move_data` is set.
189
191
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 ,
191
193
) -> Result < ( ) , io:: Error > {
192
194
let keys_to_migrate = source_store. list_all_keys ( ) ?;
193
195
@@ -197,11 +199,13 @@ pub fn migrate_kv_store_data<S: MigratableKVStore, T: MigratableKVStore>(
197
199
target_store. write ( primary_namespace, secondary_namespace, key, & data) ?;
198
200
199
201
// 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
+ }
205
209
}
206
210
}
207
211
0 commit comments