root/dmtcp_coordinator.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, and Gene Cooperman *
   3  *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu              *
   4  *                                                                          *
   5  *  This file is part of DMTCP.                                             *
   6  *                                                                          *
   7  *  DMTCP is free software: you can redistribute it and/or                  *
   8  *  modify it under the terms of the GNU Lesser General Public License as   *
   9  *  published by the Free Software Foundation, either version 3 of the      *
  10  *  License, or (at your option) any later version.                         *
  11  *                                                                          *
  12  *  DMTCP is distributed in the hope that it will be useful,                *
  13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
  15  *  GNU Lesser General Public License for more details.                     *
  16  *                                                                          *
  17  *  You should have received a copy of the GNU Lesser General Public        *
  18  *  License along with DMTCP:dmtcp/src.  If not, see                        *
  19  *  <http://www.gnu.org/licenses/>.                                         *
  20  ****************************************************************************/
  21 
  22 #ifndef DMTCPDMTCPCOORDINATOR_H
  23 #define DMTCPDMTCPCOORDINATOR_H
  24 
  25 #include "dmtcpalloc.h"
  26 #include  "../jalib/jsocket.h"
  27 #include "dmtcpmessagetypes.h"
  28 
  29 namespace dmtcp
  30 {
  31   class CoordClient
  32   {
  33     public:
  34       CoordClient(const jalib::JSocket& sock,
  35                   const struct sockaddr_storage *addr,
  36                   socklen_t len,
  37                   DmtcpMessage &hello_remote,
  38                   int isNSWorker = 0);
  39 
  40       jalib::JSocket &sock() { return _sock; }
  41       const UniquePid& identity() const { return _identity;}
  42       void identity(UniquePid upid) { _identity = upid;}
  43       int clientNumber() const { return _clientNumber; }
  44       string ip() const { return _ip; }
  45       WorkerState state() const { return _state; }
  46       void setState ( WorkerState value ) { _state = value; }
  47       void progname(string pname){ _progname = pname; }
  48       string progname(void) const { return _progname; }
  49       void hostname(string hname){ _hostname = hname; }
  50       string hostname(void) const { return _hostname; }
  51       pid_t realPid(void) const { return _realPid; }
  52       void realPid(pid_t pid) { _realPid = pid; }
  53       pid_t virtualPid(void) const { return _virtualPid; }
  54       void virtualPid(pid_t pid) { _virtualPid = pid; }
  55       int isNSWorker() {return _isNSWorker;}
  56 
  57       void readProcessInfo(DmtcpMessage& msg);
  58 
  59     private:
  60       UniquePid _identity;
  61       int _clientNumber;
  62       jalib::JSocket _sock;
  63       WorkerState _state;
  64       string _hostname;
  65       string _progname;
  66       string _ip;
  67       pid_t _realPid;
  68       pid_t _virtualPid;
  69       int _isNSWorker;
  70   };
  71 
  72   class DmtcpCoordinator
  73   {
  74     public:
  75       typedef struct {
  76         WorkerState minimumState;
  77         WorkerState maximumState;
  78         bool minimumStateUnanimous;
  79         int numPeers;
  80       } ComputationStatus;
  81 
  82       void onData(CoordClient *client);
  83       void onConnect();
  84       void onDisconnect(CoordClient *client);
  85       void eventLoop(bool daemon);
  86 
  87       void addDataSocket(CoordClient *client);
  88       void updateCheckpointInterval(uint32_t timeout);
  89       void updateMinimumState(WorkerState oldState);
  90       void initializeComputation();
  91       void broadcastMessage(DmtcpMessageType type, int numPeers = -1);
  92       bool startCheckpoint();
  93 
  94       void handleUserCommand(char cmd, DmtcpMessage* reply = NULL);
  95       void printStatus(size_t numPeers, bool isRunning);
  96 
  97       void processDmtUserCmd(DmtcpMessage& hello_remote,
  98                              jalib::JSocket& remote);
  99       bool validateNewWorkerProcess(DmtcpMessage& hello_remote,
 100                                     jalib::JSocket& remote,
 101                                     CoordClient *client,
 102                                     const struct sockaddr_storage* addr,
 103                                     socklen_t len);
 104       bool validateRestartingWorkerProcess(DmtcpMessage& hello_remote,
 105                                            jalib::JSocket& remote,
 106                                            const struct sockaddr_storage* addr,
 107                                            socklen_t len);
 108 
 109       ComputationStatus getStatus() const;
 110       WorkerState minimumState() const { return getStatus().minimumState; }
 111 
 112       pid_t getNewVirtualPid();
 113 
 114     protected:
 115       void writeRestartScript();
 116     private:
 117       //map from hostname to checkpoint files
 118       map< string, vector<string> > _restartFilenames;
 119       map< pid_t, CoordClient* > _virtualPidToClientMap;
 120   };
 121 
 122 }
 123 
 124 #endif

/* [<][>][^][v][top][bottom][index][help] */