FastRestore:Fix attempt:Seg fault

This commit is contained in:
Meng Xu 2020-06-19 15:51:36 -07:00
parent 6eb00763bf
commit faec3cc556
1 changed files with 13 additions and 5 deletions

View File

@ -329,6 +329,7 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload {
return Void(); return Void();
} }
// TODO: Add restore request as a parameter so that we only transform contents in restored ranges
ACTOR static Future<Void> transformDatabaseContents(Database cx, Key addPrefix, Key removePrefix) { ACTOR static Future<Void> transformDatabaseContents(Database cx, Key addPrefix, Key removePrefix) {
state ReadYourWritesTransaction tr(cx); state ReadYourWritesTransaction tr(cx);
tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
@ -343,20 +344,27 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload {
state Standalone<VectorRef<KeyValueRef>> newKVs; state Standalone<VectorRef<KeyValueRef>> newKVs;
for (i = 0; i < kvs.size(); ++i) { for (i = 0; i < kvs.size(); ++i) {
Key newKey = kvs[i].key.removePrefix(removePrefix).withPrefix(addPrefix); Key newKey(kvs[i].key);
TraceEvent("TransformDatabaseContents")
.detail("Keys", kvs.size())
.detail("Index", i)
.detail("GetKey", kvs[i].key)
.detail("GetValue", kvs[i].value);
ASSERT(removePrefix.size() >= newKey.size()); // If fail, must check why?!
newKey = newKey.removePrefix(removePrefix).withPrefix(addPrefix);
newKVs.push_back_deep(newKVs.arena(), KeyValueRef(newKey.contents(), kvs[i].value)); newKVs.push_back_deep(newKVs.arena(), KeyValueRef(newKey.contents(), kvs[i].value));
TraceEvent("TransformDatabaseContents") TraceEvent("TransformDatabaseContents")
.detail("Index", i) .detail("Index", i)
.detail("GetKey", kvs[i].key) .detail("NewKey", newKVs[i].key)
.detail("NewKey", newKVs[i].key); .detail("NewValue", newKVs[i].value);
} }
// Clear the transformed data (original data with removePrefix and addPrefix) // Clear the transformed data (original data with removePrefix and addPrefix)
TraceEvent("TransformDatabaseContents").detail("Clear", KeyRangeRef(addPrefix.contents(), strinc(addPrefix))); TraceEvent("TransformDatabaseContents").detail("Clear", normalKeys);
wait(runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Void> { wait(runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE); tr->setOption(FDBTransactionOptions::LOCK_AWARE);
tr->clear(KeyRangeRef(addPrefix.contents(), strinc(addPrefix))); tr->clear(normalKeys); // Careful when we restore only a sub key range!
return Void(); return Void();
})); }));