Date: Friday, August 25, 2006 @ 15:20:32
  Author: gilles
    Path: /cvsroot/carob/carob/src

 Removed: ControllerConnectPolicy.cpp (1.12)

Removed unused file, forgotten when refactoring controller pool


-----------------------------+
 ControllerConnectPolicy.cpp |  283 ------------------------------------------
 1 files changed, 283 deletions(-)


Index: carob/src/ControllerConnectPolicy.cpp
diff -u carob/src/ControllerConnectPolicy.cpp:1.12 
carob/src/ControllerConnectPolicy.cpp:removed
--- carob/src/ControllerConnectPolicy.cpp:1.12  Wed Jun 28 17:54:48 2006
+++ carob/src/ControllerConnectPolicy.cpp       Fri Aug 25 15:20:32 2006
@@ -1,283 +0,0 @@
-/*
- * Sequoia: Database clustering technology.
- * Copyright (C) 2005-2006 Continuent, Inc.
- * Contact: [EMAIL PROTECTED]
- * 
- * 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.
- *
- * Initial developer(s): Gilles Rayrat
- * Contributor(s): 
- */
-
-#include "ControllerConnectPolicy.hpp"
-
-#include "JavaSocket.hpp"
-#include "Connection.hpp"
-
-#include "ConnectionParameters.hpp"
-#include "Common.hpp"
-
-#include <map>
-#include <sstream>
-
-using std::wstring;
-
-using namespace CarobNS;
-
-CriticalSection AbstractControllerConnectPolicy::suspected_controllers_CS;
-
-typedef struct
-{
-  ControllerInfo  controllerInfo;
-  JavaSocket*     pingSocketPtr;
-} SuspectController;
-
-/** Utility typedef to have a short name for suspect_list content type */
-typedef std::vector<SuspectController> SuspectList;
-/** The list of suspected controllers (static => per process) */
-namespace
-{
-  /** list of controllers suspected of failure */
-  SuspectList suspected_controllers;
-  /** # of controllers that have fail since this process has been created */
-  int controller_failure_number = 0;
-};
-
-AbstractControllerConnectPolicy::AbstractControllerConnectPolicy(
-    const std::vector<ControllerInfo>& controllerList, long retryIntervalInMs)
-        throw (DriverException, UnexpectedException)
-{
-  if (controllerList.size() == 0)
-    throw DriverException(
-        L"Invalid empty controller list in connect policy constructor");
-  controller_list = controllerList;
-}
-
-AbstractControllerConnectPolicy::~AbstractControllerConnectPolicy()
-{
-  controller_list.clear();
-}
-
-/*static*/
-void AbstractControllerConnectPolicy::updateSuspectList(int select_timeout /* 
= 20 */)
-{
-  wstring fctName(L"AbstractControllerConnectPolicy::updateSuspectList");
-  if (suspected_controllers.size() < 1)
-    return;
-
-  LockScope scLs(&suspected_controllers_CS);
-  //create set of fds for select function
-  fd_set writableControllers;
-  FD_ZERO(&writableControllers);
-  struct timeval tv;
-  tv.tv_sec = 0;
-  tv.tv_usec = select_timeout;
-  int fdMax = -1, retVal = 0;
-  for (SuspectList::iterator iter = suspected_controllers.begin();
-      iter != suspected_controllers.end(); iter++)
-  {
-    try
-    {
-      //connect socket and add it to the list of fds
-      if 
((*iter).pingSocketPtr->connectTo((*iter).controllerInfo.getHostName(),
-                                           
(*iter).controllerInfo.getHostPort()))
-      {
-        int sock = (*iter).pingSocketPtr->getFd();
-        if (sock > fdMax)
-          fdMax = sock;
-        FD_SET(sock, &writableControllers);
-      }
-    }
-    catch (...){}
-  }
-  retVal = select(fdMax+1, NULL, &writableControllers, NULL, &tv);
-  if (retVal == -1)
-  {
-    if (isErrorEnabled())
-    {
-      logError(fctName, L"Select returned error #"+toWString(errno));
-    }
-    return;
-  }
-  // if (retVal == 0) => timeout, no controller up again, do nothing
-  // If controllers are found up again, let's remove them from the list of
-  // suspects
-  if (retVal > 0)
-  {
-    // Anti-perfomant-but-very-sure way to remove up-again controllers from the
-    // list of suspects
-    bool mayHaveControllerLeftToRemove = true;
-    while (mayHaveControllerLeftToRemove)
-    {
-      mayHaveControllerLeftToRemove = false;
-      for (SuspectList::iterator iter = suspected_controllers.begin();
-          iter != suspected_controllers.end(); iter++)
-      {
-        if (FD_ISSET((*iter).pingSocketPtr->getFd(), &writableControllers))
-        {
-          if (isDebugEnabled())
-          {
-            logDebug(fctName, L"Controller "
-                + static_cast<wstring>((*iter).controllerInfo)
-                + L" is up again. Removing it from the list of suspects (list 
size="
-                + toWString(suspected_controllers.size())+L")");
-          }
-          //send ping and close socket
-          (*iter).pingSocketPtr->writeJavaInt(Ping);
-          // For performance, we could:
-          //1.delete (*iter).pingSocketPtr;
-          //2.suspected_controllers.erase(iter);
-          // But we don't need perf in this part of code, so let's factorize
-          // and use our dedicated function
-          removeControllerFromSuspectList((*iter).controllerInfo);
-          mayHaveControllerLeftToRemove = true;
-          break;
-        }
-      }
-    }
-  }
-}
-
-/*static*/
-bool AbstractControllerConnectPolicy::isSuspectedOfFailure(
-    const ControllerInfo& controllerInfo)
-{
-  // This is a good place to do the ping on suspected controllers, we are
-  // called by most of the functions in this class
-  updateSuspectList();
-  // Just compare controller info with each item in the whole list
-  for (SuspectList::const_iterator iter = suspected_controllers.begin();
-      iter != suspected_controllers.end(); iter++)
-  {
-    if ((*iter).controllerInfo == controllerInfo)
-      return true;
-  }
-  return false;
-}
-
-void AbstractControllerConnectPolicy::suspectControllerOfFailure(
-    ControllerInfo& controllerInfo)
-{
-  wstring 
fctName(L"AbstractControllerConnectPolicy::suspectControllerOfFailure");
-
-  // First check that the controller is not already in the list of suspects
-  if (isSuspectedOfFailure(controllerInfo))
-    return;
-
-  // Add it to the list
-  for (size_t i = 0; i < controller_list.size(); i++)
-  {
-    if (controllerInfo == controller_list[i])
-    {
-      LockScope scLs(&suspected_controllers_CS);
-      //just for reporting (in the future ?)
-      controller_failure_number++;
-      SuspectController newSuspect;
-      newSuspect.controllerInfo = controllerInfo;
-      if (isDebugEnabled())
-        logDebug(fctName, L"Creating ping socket to suspected controller...");
-      // creates and prepares a new socket for pinging the controller
-      newSuspect.pingSocketPtr = new JavaSocket();
-      newSuspect.pingSocketPtr->create(false); //create non blocking
-      //add the controller and its socket to the list
-      suspected_controllers.push_back(newSuspect);
-      if (isDebugEnabled())
-        logDebug(fctName, L"Controller " + static_cast<wstring>(controllerInfo)
-            + L" is now suspected of failure (list size="
-            + toWString(suspected_controllers.size())+L")");
-      return;
-    }
-  }
-}
-
-/*static*/
-void AbstractControllerConnectPolicy::removeControllerFromSuspectList(
-    const ControllerInfo& controllerInfo)
-{
-  wstring 
fctName(L"AbstractControllerConnectPolicy::removeControllerFromSuspectList");
-  LockScope scLs(&suspected_controllers_CS);
-
-  for (SuspectList::iterator iter = suspected_controllers.begin();
-      iter != suspected_controllers.end(); iter++)
-  {
-    if ((*iter).controllerInfo == controllerInfo)
-    {
-      // found it
-      delete (*iter).pingSocketPtr; //free the ping socket
-      suspected_controllers.erase(iter);
-      if (isDebugEnabled())
-      {
-        logDebug(fctName, L"Controller " + static_cast<wstring>(controllerInfo)
-            + L" has been removed from suspect list (list size="
-            + toWString(suspected_controllers.size())+L")");
-      }
-      return;
-    }
-  }
-  if (isWarnEnabled())
-  {
-    logWarn(fctName, L"Controller " + static_cast<wstring>(controllerInfo)
-        + L" is not (anymore?) in the suspect list");
-  }
-}
-
-/*static*/
-int AbstractControllerConnectPolicy::getNumberOfFailures()
-{
-  return controller_failure_number;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ROUND ROBIN POLICY
-////////////////////////////////////////////////////////////////////////////////
-
-RoundRobinConnectPolicy::RoundRobinConnectPolicy(
-    const std::vector<ControllerInfo>& controllerList, long retryIntervalInMs)
-        throw (DriverException, UnexpectedException) :
-AbstractControllerConnectPolicy(controllerList, retryIntervalInMs),
-index(-1)
-{
-}
-
-ControllerInfo RoundRobinConnectPolicy::getController()
-    throw (NoMoreControllerException, UnexpectedException)
-{
-  wstring fctName(L"RoundRobinConnectPolicy::getController");
-
-  LockScope ls(&policy_CS);
-  {
-    LockScope scLs(&suspected_controllers_CS);
-    unsigned int testedControllers = 0; //unsigned because we compare it to 
vector.size()
-    bool lastTestedControllerWasSuspect = false;
-    do
-    {
-      index = (index + 1) % controller_list.size();
-      lastTestedControllerWasSuspect = 
isSuspectedOfFailure(controller_list[index]);
-      testedControllers++;
-    }
-    while (lastTestedControllerWasSuspect
-        && testedControllers <= controller_list.size());
-    // if there are no more controllers up => exception
-    if (lastTestedControllerWasSuspect)
-    {
-      throw NoMoreControllerException(L"All "
-                                      + toWString(suspected_controllers.size())
-                                      + L" controllers down");
-    }
-  }
-  if (isDebugEnabled())
-    logDebug(fctName, L"Selected controller[" + toWString(index) + L"]:"
-        + static_cast<wstring>(controller_list[index]));
-  return controller_list[index];
-}
-

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to