2017-05-26 04:48:44 +08:00
/*
* WorkerInterface . h
*
* 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 .
*/
# ifndef FDBSERVER_WORKERINTERFACE_H
# define FDBSERVER_WORKERINTERFACE_H
# pragma once
2018-10-20 01:30:13 +08:00
# include "fdbserver/MasterInterface.h"
# include "fdbserver/TLogInterface.h"
# include "fdbserver/ResolverInterface.h"
2017-05-26 04:48:44 +08:00
# include "fdbclient/StorageServerInterface.h"
2018-10-20 01:30:13 +08:00
# include "fdbserver/TesterInterface.h"
2017-05-26 04:48:44 +08:00
# include "fdbclient/FDBTypes.h"
2018-10-20 01:30:13 +08:00
# include "fdbserver/LogSystemConfig.h"
2017-05-26 04:48:44 +08:00
# include "fdbrpc/MultiInterface.h"
# include "fdbclient/ClientWorkerInterface.h"
2017-06-23 08:21:42 +08:00
# define DUMPTOKEN( name ) TraceEvent("DumpToken", recruited.id()).detail("Name", #name).detail("Token", name.getEndpoint().token)
2017-05-26 04:48:44 +08:00
struct WorkerInterface {
ClientWorkerInterface clientInterface ;
LocalityData locality ;
RequestStream < struct InitializeTLogRequest > tLog ;
RequestStream < struct RecruitMasterRequest > master ;
RequestStream < struct InitializeMasterProxyRequest > masterProxy ;
RequestStream < struct InitializeResolverRequest > resolver ;
RequestStream < struct InitializeStorageRequest > storage ;
2017-06-30 06:50:19 +08:00
RequestStream < struct InitializeLogRouterRequest > logRouter ;
2017-05-26 04:48:44 +08:00
RequestStream < struct LoadedPingRequest > debugPing ;
RequestStream < struct CoordinationPingMessage > coordinationPing ;
RequestStream < ReplyPromise < Void > > waitFailure ;
RequestStream < struct SetMetricsLogRateRequest > setMetricsRate ;
RequestStream < struct EventLogRequest > eventLogRequest ;
RequestStream < struct TraceBatchDumpRequest > traceBatchDumpRequest ;
RequestStream < struct DiskStoreRequest > diskStoreRequest ;
TesterInterface testerInterface ;
UID id ( ) const { return tLog . getEndpoint ( ) . token ; }
NetworkAddress address ( ) const { return tLog . getEndpoint ( ) . address ; }
WorkerInterface ( ) { }
WorkerInterface ( LocalityData locality ) : locality ( locality ) { }
template < class Ar >
void serialize ( Ar & ar ) {
2018-09-07 04:44:25 +08:00
ar & clientInterface & locality & tLog & master & masterProxy & resolver & storage & logRouter & debugPing & coordinationPing & waitFailure & setMetricsRate & eventLogRequest & traceBatchDumpRequest & testerInterface & diskStoreRequest ;
2017-05-26 04:48:44 +08:00
}
} ;
struct InitializeTLogRequest {
UID recruitmentID ;
LogSystemConfig recoverFrom ;
Version recoverAt ;
Version knownCommittedVersion ;
LogEpoch epoch ;
std : : vector < Tag > recoverTags ;
2018-04-01 07:47:56 +08:00
std : : vector < Tag > allTags ;
2017-05-26 04:48:44 +08:00
KeyValueStoreType storeType ;
2018-03-30 06:12:38 +08:00
Tag remoteTag ;
int8_t locality ;
bool isPrimary ;
2018-04-09 12:24:05 +08:00
Version startVersion ;
int logRouterTags ;
2018-03-30 06:12:38 +08:00
2017-05-26 04:48:44 +08:00
ReplyPromise < struct TLogInterface > reply ;
InitializeTLogRequest ( ) { }
template < class Ar >
void serialize ( Ar & ar ) {
2018-04-21 04:25:22 +08:00
ar & recruitmentID & recoverFrom & recoverAt & knownCommittedVersion & epoch & recoverTags & allTags & storeType & remoteTag & locality & isPrimary & startVersion & logRouterTags & reply ;
2017-06-30 06:50:19 +08:00
}
} ;
struct InitializeLogRouterRequest {
uint64_t recoveryCount ;
Tag routerTag ;
2018-04-09 12:24:05 +08:00
Version startVersion ;
2018-04-29 09:04:57 +08:00
std : : vector < LocalityData > tLogLocalities ;
IRepPolicyRef tLogPolicy ;
2018-04-30 04:47:32 +08:00
int8_t locality ;
2017-06-30 06:50:19 +08:00
ReplyPromise < struct TLogInterface > reply ;
template < class Ar >
void serialize ( Ar & ar ) {
2018-06-16 03:36:19 +08:00
ar & recoveryCount & routerTag & startVersion & tLogLocalities & tLogPolicy & locality & reply ;
2017-05-26 04:48:44 +08:00
}
} ;
// FIXME: Rename to InitializeMasterRequest, etc
struct RecruitMasterRequest {
Arena arena ;
LifetimeToken lifetime ;
2018-07-01 21:39:04 +08:00
bool forceRecovery ;
2017-05-26 04:48:44 +08:00
ReplyPromise < struct MasterInterface > reply ;
template < class Ar >
void serialize ( Ar & ar ) {
ASSERT ( ar . protocolVersion ( ) > = 0x0FDB00A200040001LL ) ;
2018-07-01 21:39:04 +08:00
ar & lifetime & forceRecovery & reply & arena ;
2017-05-26 04:48:44 +08:00
}
} ;
struct InitializeMasterProxyRequest {
MasterInterface master ;
uint64_t recoveryCount ;
Version recoveryTransactionVersion ;
bool firstProxy ;
ReplyPromise < MasterProxyInterface > reply ;
template < class Ar >
void serialize ( Ar & ar ) {
ar & master & recoveryCount & recoveryTransactionVersion & firstProxy & reply ;
}
} ;
struct InitializeResolverRequest {
uint64_t recoveryCount ;
int proxyCount ;
int resolverCount ;
ReplyPromise < ResolverInterface > reply ;
template < class Ar >
void serialize ( Ar & ar ) {
ar & recoveryCount & proxyCount & resolverCount & reply ;
}
} ;
2018-05-06 09:16:28 +08:00
struct InitializeStorageReply {
StorageServerInterface interf ;
Version addedVersion ;
template < class Ar >
void serialize ( Ar & ar ) {
ar & interf & addedVersion ;
}
} ;
2017-05-26 04:48:44 +08:00
struct InitializeStorageRequest {
Tag seedTag ; //< If this server will be passed to seedShardServers, this will be a tag, otherwise it is invalidTag
UID reqId ;
UID interfaceId ;
KeyValueStoreType storeType ;
2018-05-06 09:16:28 +08:00
ReplyPromise < InitializeStorageReply > reply ;
2017-05-26 04:48:44 +08:00
template < class Ar >
void serialize ( Ar & ar ) {
ar & seedTag & reqId & interfaceId & storeType & reply ;
}
} ;
struct TraceBatchDumpRequest {
ReplyPromise < Void > reply ;
template < class Ar >
void serialize ( Ar & ar ) {
ar & reply ;
}
} ;
struct LoadedReply {
Standalone < StringRef > payload ;
UID id ;
template < class Ar >
void serialize ( Ar & ar ) {
ar & payload & id ;
}
} ;
struct LoadedPingRequest {
UID id ;
bool loadReply ;
Standalone < StringRef > payload ;
ReplyPromise < LoadedReply > reply ;
template < class Ar >
void serialize ( Ar & ar ) {
ar & id & loadReply & payload & reply ;
}
} ;
struct CoordinationPingMessage {
UID clusterControllerId ;
int64_t timeStep ;
CoordinationPingMessage ( ) : timeStep ( 0 ) { }
CoordinationPingMessage ( UID ccId , uint64_t step ) : clusterControllerId ( ccId ) , timeStep ( step ) { }
template < class Ar >
void serialize ( Ar & ar ) {
ar & clusterControllerId & timeStep ;
}
} ;
struct SetMetricsLogRateRequest {
uint32_t metricsLogsPerSecond ;
SetMetricsLogRateRequest ( ) : metricsLogsPerSecond ( 1 ) { }
explicit SetMetricsLogRateRequest ( uint32_t logsPerSecond ) : metricsLogsPerSecond ( logsPerSecond ) { }
template < class Ar >
void serialize ( Ar & ar ) {
ar & metricsLogsPerSecond ;
}
} ;
struct EventLogRequest {
bool getLastError ;
Standalone < StringRef > eventName ;
2018-05-03 01:44:38 +08:00
ReplyPromise < TraceEventFields > reply ;
2017-05-26 04:48:44 +08:00
EventLogRequest ( ) : getLastError ( true ) { }
explicit EventLogRequest ( Standalone < StringRef > eventName ) : eventName ( eventName ) , getLastError ( false ) { }
template < class Ar >
void serialize ( Ar & ar ) {
ar & getLastError & eventName & reply ;
}
} ;
struct DebugEntryRef {
double time ;
NetworkAddress address ;
StringRef context ;
Version version ;
MutationRef mutation ;
DebugEntryRef ( ) { }
DebugEntryRef ( const char * c , Version v , MutationRef const & m ) : context ( ( const uint8_t * ) c , strlen ( c ) ) , version ( v ) , mutation ( m ) , time ( now ( ) ) , address ( g_network - > getLocalAddress ( ) ) { }
DebugEntryRef ( Arena & a , DebugEntryRef const & d ) : time ( d . time ) , address ( d . address ) , context ( d . context ) , version ( d . version ) , mutation ( a , d . mutation ) { }
size_t expectedSize ( ) const {
return context . expectedSize ( ) + mutation . expectedSize ( ) ;
}
template < class Ar >
void serialize ( Ar & ar ) {
ar & time & address & context & version & mutation ;
}
} ;
struct DiskStoreRequest {
bool includePartialStores ;
ReplyPromise < Standalone < VectorRef < UID > > > reply ;
DiskStoreRequest ( bool includePartialStores = false ) : includePartialStores ( includePartialStores ) { }
template < class Ar >
void serialize ( Ar & ar ) {
ar & includePartialStores & reply ;
}
} ;
2018-09-06 06:06:14 +08:00
struct Role {
static const Role WORKER ;
static const Role STORAGE_SERVER ;
static const Role TRANSACTION_LOG ;
static const Role SHARED_TRANSACTION_LOG ;
static const Role MASTER_PROXY ;
static const Role MASTER ;
static const Role RESOLVER ;
static const Role CLUSTER_CONTROLLER ;
static const Role TESTER ;
static const Role LOG_ROUTER ;
std : : string roleName ;
std : : string abbreviation ;
2018-09-06 06:53:12 +08:00
bool includeInTraceRoles ;
2018-09-06 06:06:14 +08:00
2018-09-07 04:47:00 +08:00
bool operator = = ( const Role & r ) const {
return roleName = = r . roleName ;
}
bool operator ! = ( const Role & r ) const {
return ! ( * this = = r ) ;
2018-09-06 06:06:14 +08:00
}
private :
2018-09-06 06:53:12 +08:00
Role ( std : : string roleName , std : : string abbreviation , bool includeInTraceRoles = true ) : roleName ( roleName ) , abbreviation ( abbreviation ) , includeInTraceRoles ( includeInTraceRoles ) {
2018-09-06 06:06:14 +08:00
ASSERT ( abbreviation . size ( ) = = 2 ) ; // Having a fixed size makes log queries more straightforward
}
} ;
void startRole ( const Role & role , UID roleId , UID workerId , std : : map < std : : string , std : : string > details = std : : map < std : : string , std : : string > ( ) , std : : string origination = " Recruited " ) ;
void endRole ( const Role & role , UID id , std : : string reason , bool ok = true , Error e = Error ( ) ) ;
2017-05-26 04:48:44 +08:00
struct ServerDBInfo ;
class Database openDBOnServer ( Reference < AsyncVar < ServerDBInfo > > const & db , int taskID = TaskDefaultEndpoint , bool enableLocalityLoadBalance = true , bool lockAware = false ) ;
Future < Void > extractClusterInterface ( Reference < AsyncVar < Optional < struct ClusterControllerFullInterface > > > const & a , Reference < AsyncVar < Optional < struct ClusterInterface > > > const & b ) ;
Future < Void > fdbd ( Reference < ClusterConnectionFile > const & , LocalityData const & localities , ProcessClass const & processClass , std : : string const & dataFolder , std : : string const & coordFolder , int64_t const & memoryLimit , std : : string const & metricsConnFile , std : : string const & metricsPrefix ) ;
2018-09-29 03:12:06 +08:00
Future < Void > clusterController ( Reference < ClusterConnectionFile > const & , Reference < AsyncVar < Optional < ClusterControllerFullInterface > > > const & currentCC , Reference < AsyncVar < ClusterControllerPriorityInfo > > const & asyncPriorityInfo , Future < Void > const & recoveredDiskFiles , LocalityData const & locality ) ;
2017-05-26 04:48:44 +08:00
// These servers are started by workerServer
Future < Void > storageServer (
class IKeyValueStore * const & persistentData ,
StorageServerInterface const & ssi ,
Tag const & seedTag ,
2018-05-06 09:16:28 +08:00
ReplyPromise < InitializeStorageReply > const & recruitReply ,
2017-05-26 04:48:44 +08:00
Reference < AsyncVar < ServerDBInfo > > const & db ,
std : : string const & folder ) ;
Future < Void > storageServer (
class IKeyValueStore * const & persistentData ,
StorageServerInterface const & ssi ,
Reference < AsyncVar < ServerDBInfo > > const & db ,
2017-09-16 01:57:58 +08:00
std : : string const & folder ,
Promise < Void > const & recovered ) ; // changes pssi->id() to be the recovered ID
2018-07-01 21:39:04 +08:00
Future < Void > masterServer ( MasterInterface const & mi , Reference < AsyncVar < ServerDBInfo > > const & db , class ServerCoordinators const & , LifetimeToken const & lifetime , bool const & forceRecovery ) ;
2017-05-26 04:48:44 +08:00
Future < Void > masterProxyServer ( MasterProxyInterface const & proxy , InitializeMasterProxyRequest const & req , Reference < AsyncVar < ServerDBInfo > > const & db ) ;
2018-01-22 04:21:46 +08:00
Future < Void > tLog ( class IKeyValueStore * const & persistentData , class IDiskQueue * const & persistentQueue , Reference < AsyncVar < ServerDBInfo > > const & db , LocalityData const & locality , PromiseStream < InitializeTLogRequest > const & tlogRequests , UID const & tlogId , bool const & restoreFromDisk , Promise < Void > const & oldLog , Promise < Void > const & recovered ) ; // changes tli->id() to be the recovered ID
2017-05-26 04:48:44 +08:00
Future < Void > monitorServerDBInfo ( Reference < AsyncVar < Optional < ClusterControllerFullInterface > > > const & ccInterface , Reference < ClusterConnectionFile > const & , LocalityData const & , Reference < AsyncVar < ServerDBInfo > > const & dbInfo ) ;
Future < Void > resolver ( ResolverInterface const & proxy , InitializeResolverRequest const & , Reference < AsyncVar < ServerDBInfo > > const & db ) ;
2017-06-30 06:50:19 +08:00
Future < Void > logRouter ( TLogInterface const & interf , InitializeLogRouterRequest const & req , Reference < AsyncVar < ServerDBInfo > > const & db ) ;
2017-05-26 04:48:44 +08:00
void registerThreadForProfiling ( ) ;
void updateCpuProfiler ( ProfilerRequest req ) ;
namespace oldTLog {
2018-01-22 04:21:46 +08:00
Future < Void > tLog ( IKeyValueStore * const & persistentData , IDiskQueue * const & persistentQueue , Reference < AsyncVar < ServerDBInfo > > const & db , LocalityData const & locality , UID const & tlogId ) ;
2017-05-26 04:48:44 +08:00
}
# endif