small cosmetic changes in spacing.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@24214 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Dave Wetzel 2006-12-19 12:16:57 +00:00
parent 2f2a13fc47
commit 126006dd58

View file

@ -71,80 +71,81 @@ GSWLoadBalancing_FindApp(GSWAppRequest *p_pAppRequest,
GSWAppInstance *pAppInstance=NULL; GSWAppInstance *pAppInstance=NULL;
time_t curTime = (time_t)0; time_t curTime = (time_t)0;
while (!fFound && iTries-->0) while (!fFound && ((iTries--) > 0))
{ {
pApp->iLastInstanceIndex = (pApp->iLastInstanceIndex+1) % uInstancesCount; pApp->iLastInstanceIndex = (pApp->iLastInstanceIndex+1) % uInstancesCount;
GSWDebugLog(p_pLogServerData,"LoadBalancing: Will try instance %d (instances count=%d).", GSWDebugLog(p_pLogServerData,"LoadBalancing: Will try instance %d (instances count=%d).",
pApp->iLastInstanceIndex,uInstancesCount); pApp->iLastInstanceIndex,uInstancesCount);
pAppInstance = pAppInstance =
(GSWAppInstance *)GSWDict_ValueForKey(&pApp->stInstancesDict, (GSWAppInstance *)GSWDict_ValueForKey(&pApp->stInstancesDict,
GSWList_ElementAtIndex(pInstancesList, GSWList_ElementAtIndex(pInstancesList,
pApp->iLastInstanceIndex)); pApp->iLastInstanceIndex));
if (pAppInstance) if (pAppInstance)
{ {
if (!pAppInstance->pApp) if (!pAppInstance->pApp)
{ {
GSWLog(GSW_CRITICAL,p_pLogServerData, GSWLog(GSW_CRITICAL,p_pLogServerData,
"AppInstance pApp is null pAppInstance=%p", "AppInstance pApp is null pAppInstance=%p",
pAppInstance); pAppInstance);
}; };
if (pAppInstance->timeNextRetryTime!=0) if (pAppInstance->timeNextRetryTime!=0)
{ {
if (!curTime) if (!curTime)
time(&curTime); time(&curTime);
if (pAppInstance->timeNextRetryTime<curTime) if (pAppInstance->timeNextRetryTime<curTime)
{ {
GSWLog(GSW_WARNING, GSWLog(GSW_WARNING,
p_pLogServerData, p_pLogServerData,
"LoadBalance: Instance %s:%d was marked dead for %d secs. Now resurecting !", "LoadBalance: Instance %s:%d was marked dead for %d secs. Now resurecting !",
p_pAppRequest->pszName, p_pAppRequest->pszName,
pAppInstance->iInstance, pAppInstance->iInstance,
APP_CONNECT_RETRY_DELAY); APP_CONNECT_RETRY_DELAY);
pAppInstance->timeNextRetryTime=0; pAppInstance->timeNextRetryTime=0;
}; };
}; };
if (pAppInstance->timeNextRetryTime==0 && pAppInstance->fValid)
{ if (pAppInstance->timeNextRetryTime==0 && pAppInstance->fValid)
BOOL okay = TRUE; {
// check if refused, time to try again ? BOOL okay = TRUE;
if (p_pURLComponents->stRequestHandlerKey.iLength==0 || // check if refused, time to try again ?
p_pURLComponents->stRequestHandlerKey.pszStart==NULL) if (p_pURLComponents->stRequestHandlerKey.iLength==0 ||
{ p_pURLComponents->stRequestHandlerKey.pszStart==NULL)
GSWAppInfo *thisAppInfo = {
GSWAppInfo_Find(p_pAppRequest->pszName, GSWAppInfo *thisAppInfo =
pAppInstance->iInstance); GSWAppInfo_Find(p_pAppRequest->pszName,
if (thisAppInfo && thisAppInfo->isRefused) pAppInstance->iInstance);
{ if (thisAppInfo && thisAppInfo->isRefused)
time_t actTime = (time_t)0; {
// this instance refuses new sessions time_t actTime = (time_t)0;
time(&actTime); // this instance refuses new sessions
if (actTime > thisAppInfo->timeNextRetryTime) time(&actTime);
{ if (actTime > thisAppInfo->timeNextRetryTime)
thisAppInfo->isRefused = FALSE; // try it again {
} thisAppInfo->isRefused = FALSE; // try it again
else }
{ else
okay = FALSE; // try an other instance {
} okay = FALSE; // try an other instance
} }
} }
}
if (okay == TRUE)
{ if (okay == TRUE)
fFound = TRUE; {
strcpy(p_pAppRequest->pszName,pApp->pszName); fFound = TRUE;
p_pAppRequest->iInstance = pAppInstance->iInstance; strcpy(p_pAppRequest->pszName,pApp->pszName);
p_pAppRequest->pszHost = pAppInstance->pszHostName; p_pAppRequest->iInstance = pAppInstance->iInstance;
p_pAppRequest->iPort = pAppInstance->iPort; p_pAppRequest->pszHost = pAppInstance->pszHostName;
p_pAppRequest->eType = EAppType_LoadBalanced; p_pAppRequest->iPort = pAppInstance->iPort;
p_pAppRequest->pAppInstance = pAppInstance; p_pAppRequest->eType = EAppType_LoadBalanced;
pAppInstance->uOpenedRequestsNb++; p_pAppRequest->pAppInstance = pAppInstance;
} pAppInstance->uOpenedRequestsNb++;
}; }
}; }
}; }
}
GSWList_Free(pInstancesList,FALSE); GSWList_Free(pInstancesList,FALSE);
}; }
GSWLock_Unlock(g_lockAppList); GSWLock_Unlock(g_lockAppList);
if (fFound) if (fFound)
@ -181,77 +182,76 @@ GSWLoadBalancing_FindInstance(GSWAppRequest *p_pAppRequest,
pApp = (GSWApp *)GSWConfig_GetApp(p_pAppRequest->pszName); pApp = (GSWApp *)GSWConfig_GetApp(p_pAppRequest->pszName);
if (pApp) if (pApp)
{ {
GSWAppInstance *pAppInstance=NULL; GSWAppInstance *pAppInstance = NULL;
char szInstanceNum[50]=""; char szInstanceNum[50] = "";
sprintf(szInstanceNum,"%d",p_pAppRequest->iInstance);
pAppInstance =
(GSWAppInstance *)GSWDict_ValueForKey(&pApp->stInstancesDict,
szInstanceNum);
// Not a known instance sprintf(szInstanceNum,"%d",p_pAppRequest->iInstance);
if (!pAppInstance)
{ pAppInstance = (GSWAppInstance *)GSWDict_ValueForKey(&pApp->stInstancesDict,
// but we can switch to a known one ? szInstanceNum);
if (pApp->fSwitchToKnownInstance)
fFound=GSWLoadBalancing_FindApp(p_pAppRequest, // Not a known instance
p_pLogServerData, if (!pAppInstance)
p_pURLComponents); {
} // but we can switch to a known one ?
else if (pApp->fSwitchToKnownInstance)
{ fFound=GSWLoadBalancing_FindApp(p_pAppRequest,
GSWDebugLog(p_pLogServerData,"Instance Found"); p_pLogServerData,
if (pAppInstance->fValid) p_pURLComponents);
{ } else {
BOOL okay = TRUE;
// check if refused, time to try again ? GSWDebugLog(p_pLogServerData,"Instance Found");
if (p_pURLComponents->stRequestHandlerKey.iLength==0 || if (pAppInstance->fValid)
p_pURLComponents->stRequestHandlerKey.pszStart==NULL) {
{ BOOL okay = TRUE;
GSWAppInfo *thisAppInfo = // check if refused, time to try again ?
GSWAppInfo_Find(p_pAppRequest->pszName, if (p_pURLComponents->stRequestHandlerKey.iLength==0 || p_pURLComponents->stRequestHandlerKey.pszStart==NULL)
pAppInstance->iInstance); {
if (thisAppInfo && thisAppInfo->isRefused) GSWAppInfo *thisAppInfo =
{ GSWAppInfo_Find(p_pAppRequest->pszName,
time_t actTime = (time_t)0; pAppInstance->iInstance);
// this instance refuses new sessions
time(&actTime); if (thisAppInfo && thisAppInfo->isRefused)
if (actTime > thisAppInfo->timeNextRetryTime) {
{ time_t actTime = (time_t)0;
thisAppInfo->isRefused = FALSE; // try it again // this instance refuses new sessions
} time(&actTime);
else
{ if (actTime > thisAppInfo->timeNextRetryTime)
okay = FALSE; // try an other instance {
} thisAppInfo->isRefused = FALSE; // try it again
} }
} else
{
if (okay == TRUE) okay = FALSE; // try an other instance
{ }
fFound=TRUE; }
p_pAppRequest->iInstance = pAppInstance->iInstance; }
p_pAppRequest->pszHost = pAppInstance->pszHostName;
p_pAppRequest->iPort = pAppInstance->iPort; if (okay == TRUE)
p_pAppRequest->eType = EAppType_LoadBalanced; {
p_pAppRequest->pAppInstance = pAppInstance; fFound=TRUE;
pAppInstance->uOpenedRequestsNb++; p_pAppRequest->iInstance = pAppInstance->iInstance;
GSWDebugLog(p_pLogServerData,"Instance is valid"); p_pAppRequest->pszHost = pAppInstance->pszHostName;
} p_pAppRequest->iPort = pAppInstance->iPort;
} p_pAppRequest->eType = EAppType_LoadBalanced;
else p_pAppRequest->pAppInstance = pAppInstance;
{ pAppInstance->uOpenedRequestsNb++;
GSWDebugLog(p_pLogServerData,"Instance is not valid"); GSWDebugLog(p_pLogServerData,"Instance is valid");
}; }
}; } else {
}; GSWDebugLog(p_pLogServerData,"Instance is not valid");
}
}
}
GSWLock_Unlock(g_lockAppList); GSWLock_Unlock(g_lockAppList);
GSWDebugLog(p_pLogServerData,"Stop GSWLoadBalancing_FindInstance"); GSWDebugLog(p_pLogServerData,"Stop GSWLoadBalancing_FindInstance");
return fFound; return fFound;
}; }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void void