static void RegisterAffinityCallback( ComputeAffinityCallback pfComputeAffinity );
Name | Description | |
---|---|---|
in | pfComputeAffinity | Pointer to the ComputeAffinityCallback callback, which reports the station's affinity level to PromotionReferee . |
Registers a callback for reporting the station's level of affinity.
This method is called by the PromotionReferee
for the given station. The example below is an implementation of the ComputeAffinityCallback
that assigns (practically, always) the duplication master of the orphaned objects to a server process. In this example, objects are assigned randomly to the given server processes to avoid the risk of the system freezing, which could happen if a certain server received all of the objects and the entire processing load. Of course, you could also distribute the processing load by implementing load balancing in a server cluster. A non-server process will only receive control over the orphaned objects when no server process exists.
void ServerTakeOverAllObjects(DOHandle hObject, qByte *pbyAffinity, TimeInterval* ptiWaitTime) {
// No matter what hObject is, we do the following. In a real life
// application, the actual affinity would probably depend on the
// type of hObject.
Station::Ref refLocal(Station::GetLocalStation());
// This must be valid: this is my own station!!
SYSTEMCHECK(refLocal.IsValid());
if (refLocal->GetProcessType()==Station::ServerProcess) {
// If I'm a server, then I select a random value between 1 and
// 101. This is my affinity. Using a random value will cause
// a uniform distribution of the objects on the failed station
// over the servers.
*pbyAffinity = 1 + static_cast < qByte > (Platform::GetRandomNumber(100));
// Since this is a server process we use a low wait time as it doesn't
// really matter which server we choose.
*ptiWaitTime = 200;
} else {
// The station is not a server. We do not want this station to
// take control of the object so we set the lowest affinity.
*pbyAffinity = 0;
// And we set a long wait time as we want to wait for a
// server to see the fault as well.
*ptiWaitTime = 2000;
}
}
CONFIDENTIAL