NdbRestarts.hpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #ifndef NDBT_RESTARTS_HPP
  14. #define NDBT_RESTARTS_HPP
  15. #include <NdbRestarter.hpp>
  16. #include <NdbTick.h>
  17. #include <random.h>
  18. /**
  19.  * This class is used to test Ndb's ability to handle 
  20.  * node- and system-restarts.
  21.  * For example:
  22.  *  Node restart:         Restart one node in the cluster.
  23.  *  System restart:       Restart all nodes in the cluster.
  24.  *  Node crash:           Crash one node in the middle of execution and bring it up again.
  25.  *  Multiple node crash:  Crash multiple nodes with a few seconds or milliseconds delay between.
  26.  *  Initial node restart: Restart one node in the cluster without a filesystem on disk.
  27.  *  
  28.  * Each restart type is represented by a NdbRestart class and a collection of these are stored 
  29.  * in the NdbRestarts class.
  30.  *
  31.  * This class may be used from other programs to execute a particular restart.
  32.  *
  33.  */
  34. class NdbRestarts {
  35. public:
  36.   NdbRestarts(const char* _addr = 0): 
  37.     m_restarter(_addr)
  38.   {
  39.     myRandom48Init(NdbTick_CurrentMillisecond());
  40.   }
  41.   enum NdbRestartType{
  42.     NODE_RESTART,
  43.     MULTIPLE_NODE_RESTART,
  44.     SYSTEM_RESTART
  45.   };
  46.   struct NdbRestart {
  47.     typedef int (restartFunc)(NdbRestarter&, const NdbRestart*);
  48.     
  49.     NdbRestart(const char* _name,
  50.        NdbRestartType _type,
  51.        restartFunc* _func,
  52.        int _requiredNodes,
  53.        int _arg1 = -1);
  54.        
  55.     const char * m_name;
  56.     NdbRestartType m_type;
  57.     restartFunc* m_restartFunc;
  58.     int m_numRequiredNodes;
  59.     int m_arg1;
  60.   };
  61.   int getNumRestarts();
  62.   int executeRestart(int _num, unsigned int _timeout = 120);
  63.   int executeRestart(const char* _name, unsigned int _timeout = 120);
  64.   void listRestarts();
  65.   void listRestarts(NdbRestartType _type);
  66. private:
  67.   int executeRestart(const NdbRestart*, unsigned int _timeout);
  68.   struct NdbErrorInsert {
  69.     NdbErrorInsert(const char* _name,
  70.    int _errorNo);
  71.        
  72.     const char * m_name;
  73.     int m_errorNo;
  74.   public:
  75.     const char* getName();
  76.   };
  77.   int getNumErrorInserts();
  78.   const NdbErrorInsert* getError(int _num);
  79.   const NdbErrorInsert* getRandomError();
  80.   static const NdbErrorInsert   m_errors[];
  81.   static const int          m_NoOfErrors;
  82.   const NdbRestart* getRestart(int _num);
  83.   const NdbRestart* getRestart(const char* _name);
  84.   static const NdbRestart   m_restarts[];
  85.   static const int          m_NoOfRestarts;
  86.   NdbRestarter m_restarter;
  87. };
  88. #endif