2021-05-29 02:15:52 +08:00
|
|
|
/*
|
|
|
|
* TSSMappingUtil.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2021-05-29 02:15:52 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fdbclient/SystemData.h"
|
|
|
|
#include "fdbclient/KeyBackedTypes.h"
|
2021-06-03 23:31:16 +08:00
|
|
|
#include "fdbserver/TSSMappingUtil.actor.h"
|
2021-05-29 02:15:52 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
ACTOR Future<Void> readTSSMappingRYW(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
std::map<UID, StorageServerInterface>* tssMapping) {
|
|
|
|
KeyBackedMap<UID, UID> tssMapDB = KeyBackedMap<UID, UID>(tssMappingKeys.begin);
|
2022-07-14 06:46:10 +08:00
|
|
|
state KeyBackedMap<UID, UID>::RangeResultType uidMapping =
|
2021-05-29 02:15:52 +08:00
|
|
|
wait(tssMapDB.getRange(tr, UID(), Optional<UID>(), CLIENT_KNOBS->TOO_MANY));
|
2022-07-14 06:46:10 +08:00
|
|
|
ASSERT(uidMapping.results.size() < CLIENT_KNOBS->TOO_MANY);
|
2021-05-29 02:15:52 +08:00
|
|
|
|
|
|
|
state std::map<UID, StorageServerInterface> mapping;
|
2022-07-14 06:46:10 +08:00
|
|
|
state std::vector<std::pair<UID, UID>>::iterator mapItr;
|
|
|
|
for (mapItr = uidMapping.results.begin(); mapItr != uidMapping.results.end(); ++mapItr) {
|
|
|
|
state UID ssId = mapItr->first;
|
|
|
|
Optional<Value> v = wait(tr->get(serverListKeyFor(mapItr->second)));
|
2021-05-29 02:15:52 +08:00
|
|
|
(*tssMapping)[ssId] = decodeServerListValue(v.get());
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> readTSSMapping(Transaction* tr, std::map<UID, StorageServerInterface>* tssMapping) {
|
|
|
|
state RangeResult mappingList = wait(tr->getRange(tssMappingKeys, CLIENT_KNOBS->TOO_MANY));
|
|
|
|
ASSERT(!mappingList.more && mappingList.size() < CLIENT_KNOBS->TOO_MANY);
|
|
|
|
|
|
|
|
for (auto& it : mappingList) {
|
2022-06-29 04:45:10 +08:00
|
|
|
state UID ssId = TupleCodec<UID>::unpack(it.key.removePrefix(tssMappingKeys.begin));
|
|
|
|
UID tssId = TupleCodec<UID>::unpack(it.value);
|
2021-05-29 02:15:52 +08:00
|
|
|
Optional<Value> v = wait(tr->get(serverListKeyFor(tssId)));
|
|
|
|
(*tssMapping)[ssId] = decodeServerListValue(v.get());
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
ACTOR Future<Void> removeTSSPairsFromCluster(Database cx, std::vector<std::pair<UID, UID>> pairsToRemove) {
|
2021-05-29 02:15:52 +08:00
|
|
|
state Reference<ReadYourWritesTransaction> tr = makeReference<ReadYourWritesTransaction>(cx);
|
|
|
|
state KeyBackedMap<UID, UID> tssMapDB = KeyBackedMap<UID, UID>(tssMappingKeys.begin);
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::PRIORITY_SYSTEM_IMMEDIATE);
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
for (auto& tssPair : pairsToRemove) {
|
|
|
|
// DO NOT remove server list key - that'll break a bunch of stuff. DD will eventually call
|
|
|
|
// removeStorageServer
|
|
|
|
tr->clear(serverTagKeyFor(tssPair.second));
|
|
|
|
tssMapDB.erase(tr, tssPair.first);
|
|
|
|
}
|
|
|
|
wait(tr->commit());
|
|
|
|
break;
|
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr->onError(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Void();
|
2021-06-03 23:31:16 +08:00
|
|
|
}
|