2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* Locality.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbrpc/Locality.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
const UID LocalityData::UNSET_ID = UID(0x0ccb4e0feddb5583, 0x010f6b77d9d10ece);
|
|
|
|
const StringRef LocalityData::keyProcessId = LiteralStringRef("processid");
|
|
|
|
const StringRef LocalityData::keyZoneId = LiteralStringRef("zoneid");
|
|
|
|
const StringRef LocalityData::keyDcId = LiteralStringRef("dcid");
|
|
|
|
const StringRef LocalityData::keyMachineId = LiteralStringRef("machineid");
|
|
|
|
const StringRef LocalityData::keyDataHallId = LiteralStringRef("data_hall");
|
|
|
|
|
2017-08-29 05:41:04 +08:00
|
|
|
ProcessClass::Fitness ProcessClass::machineClassFitness( ClusterRole role ) const {
|
2017-05-26 04:48:44 +08:00
|
|
|
switch( role ) {
|
|
|
|
case ProcessClass::Storage:
|
|
|
|
switch( _class ) {
|
|
|
|
case ProcessClass::StorageClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
|
|
|
case ProcessClass::TransactionClass:
|
|
|
|
return ProcessClass::WorstFit;
|
|
|
|
case ProcessClass::LogClass:
|
|
|
|
return ProcessClass::WorstFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
}
|
|
|
|
case ProcessClass::TLog:
|
|
|
|
switch( _class ) {
|
|
|
|
case ProcessClass::LogClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::TransactionClass:
|
|
|
|
return ProcessClass::GoodFit;
|
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
|
|
|
case ProcessClass::StorageClass:
|
|
|
|
return ProcessClass::WorstFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
}
|
|
|
|
case ProcessClass::Proxy:
|
|
|
|
switch( _class ) {
|
|
|
|
case ProcessClass::ProxyClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::ResolutionClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::TransactionClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
|
|
|
}
|
|
|
|
case ProcessClass::Master:
|
|
|
|
switch( _class ) {
|
|
|
|
case ProcessClass::MasterClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::ResolutionClass:
|
|
|
|
return ProcessClass::OkayFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
|
|
|
}
|
|
|
|
case ProcessClass::Resolver:
|
|
|
|
switch( _class ) {
|
|
|
|
case ProcessClass::ResolutionClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::TransactionClass:
|
|
|
|
return ProcessClass::OkayFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-05-26 04:48:44 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
|
|
|
}
|
2017-09-08 06:32:08 +08:00
|
|
|
case ProcessClass::LogRouter:
|
|
|
|
switch( _class ) {
|
|
|
|
case ProcessClass::LogRouterClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2017-09-08 06:32:08 +08:00
|
|
|
case ProcessClass::ResolutionClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2017-09-08 06:32:08 +08:00
|
|
|
case ProcessClass::TransactionClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-09-08 06:32:08 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
|
|
|
}
|
2017-08-29 05:41:04 +08:00
|
|
|
case ProcessClass::ClusterController:
|
|
|
|
switch( _class ) {
|
2017-10-17 07:21:25 +08:00
|
|
|
case ProcessClass::ClusterControllerClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::BestFit;
|
2017-08-29 05:41:04 +08:00
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2017-10-17 07:21:25 +08:00
|
|
|
case ProcessClass::MasterClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2017-08-29 05:41:04 +08:00
|
|
|
case ProcessClass::ResolutionClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2018-09-22 07:14:39 +08:00
|
|
|
case ProcessClass::TransactionClass:
|
|
|
|
return ProcessClass::OkayFit;
|
2017-08-29 05:41:04 +08:00
|
|
|
case ProcessClass::ProxyClass:
|
2018-05-09 14:54:28 +08:00
|
|
|
return ProcessClass::OkayFit;
|
2018-06-29 14:20:01 +08:00
|
|
|
case ProcessClass::LogRouterClass:
|
|
|
|
return ProcessClass::OkayFit;
|
2019-01-26 03:03:13 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
2017-08-29 05:41:04 +08:00
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
|
|
|
}
|
2018-12-14 05:31:37 +08:00
|
|
|
case ProcessClass::DataDistributor:
|
|
|
|
switch( _class ) {
|
2019-02-22 07:30:39 +08:00
|
|
|
case ProcessClass::DataDistributorClass:
|
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::MasterClass:
|
|
|
|
return ProcessClass::OkayFit;
|
2019-02-22 07:30:39 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
2019-02-15 08:24:46 +08:00
|
|
|
}
|
2019-03-27 23:24:25 +08:00
|
|
|
case ProcessClass::Ratekeeper:
|
2019-02-15 08:24:46 +08:00
|
|
|
switch( _class ) {
|
2019-03-27 23:24:25 +08:00
|
|
|
case ProcessClass::RatekeeperClass:
|
2019-02-22 07:30:39 +08:00
|
|
|
return ProcessClass::BestFit;
|
|
|
|
case ProcessClass::StatelessClass:
|
|
|
|
return ProcessClass::GoodFit;
|
|
|
|
case ProcessClass::UnsetClass:
|
|
|
|
return ProcessClass::UnsetFit;
|
2019-04-30 10:51:43 +08:00
|
|
|
case ProcessClass::MasterClass:
|
|
|
|
return ProcessClass::OkayFit;
|
2019-02-22 07:30:39 +08:00
|
|
|
case ProcessClass::CoordinatorClass:
|
|
|
|
case ProcessClass::TesterClass:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
default:
|
|
|
|
return ProcessClass::WorstFit;
|
2018-12-14 05:31:37 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
return ProcessClass::NeverAssign;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LBDistance::Type loadBalanceDistance( LocalityData const& loc1, LocalityData const& loc2, NetworkAddress const& addr2 ) {
|
|
|
|
if ( loc1.zoneId().present() && loc1.zoneId() == loc2.zoneId() )
|
|
|
|
return LBDistance::SAME_MACHINE;
|
|
|
|
|
|
|
|
//FIXME: add this back in when load balancing works with local requests
|
|
|
|
//if ( g_network->isAddressOnThisHost( addr2 ) )
|
|
|
|
// return LBDistance::SAME_MACHINE;
|
|
|
|
if ( loc1.dcId().present() && loc1.dcId() == loc2.dcId() )
|
|
|
|
return LBDistance::SAME_DC;
|
|
|
|
return LBDistance::DISTANT;
|
|
|
|
}
|