File: dmtcp_coordinator.h

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (132 lines) | stat: -rw-r--r-- 5,300 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/****************************************************************************
 *   Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, and Gene Cooperman *
 *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu              *
 *                                                                          *
 *  This file is part of DMTCP.                                             *
 *                                                                          *
 *  DMTCP is free software: you can redistribute it and/or                  *
 *  modify it under the terms of the GNU Lesser General Public License as   *
 *  published by the Free Software Foundation, either version 3 of the      *
 *  License, or (at your option) any later version.                         *
 *                                                                          *
 *  DMTCP is distributed in the hope that it will be useful,                *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU Lesser General Public License for more details.                     *
 *                                                                          *
 *  You should have received a copy of the GNU Lesser General Public        *
 *  License along with DMTCP:dmtcp/src.  If not, see                        *
 *  <http://www.gnu.org/licenses/>.                                         *
 ****************************************************************************/

#ifndef DMTCPDMTCPCOORDINATOR_H
#define DMTCPDMTCPCOORDINATOR_H

#include "dmtcpalloc.h"
#include  "../jalib/jsocket.h"
#include "dmtcpmessagetypes.h"

namespace dmtcp
{
  class CoordClient
  {
    public:
      CoordClient(const jalib::JSocket& sock,
                  const struct sockaddr_storage *addr,
                  socklen_t len,
                  DmtcpMessage &hello_remote,
		  int isNSWorker = 0);

      jalib::JSocket &sock() { return _sock; }
      const UniquePid& identity() const { return _identity;}
      void identity(UniquePid upid) { _identity = upid;}
      int clientNumber() const { return _clientNumber; }
      string ip() const { return _ip; }
      WorkerState::eWorkerState state() const { return _state; }
      void setState ( WorkerState::eWorkerState value ) { _state = value; }
      void progname(string pname){ _progname = pname; }
      string progname(void) const { return _progname; }
      void hostname(string hname){ _hostname = hname; }
      string hostname(void) const { return _hostname; }
      pid_t realPid(void) const { return _realPid; }
      void realPid(pid_t pid) { _realPid = pid; }
      pid_t virtualPid(void) const { return _virtualPid; }
      void virtualPid(pid_t pid) { _virtualPid = pid; }
      int isNSWorker() {return _isNSWorker;}

      void readProcessInfo(DmtcpMessage& msg);

    private:
      UniquePid _identity;
      int _clientNumber;
      jalib::JSocket _sock;
      WorkerState::eWorkerState _state;
      string _hostname;
      string _progname;
      string _ip;
      pid_t _realPid;
      pid_t _virtualPid;
      int _isNSWorker;
  };

  class DmtcpCoordinator
  {
    public:
      typedef struct {
        WorkerState::eWorkerState minimumState;
        WorkerState::eWorkerState maximumState;
        bool minimumStateUnanimous;
        int numPeers;
      } ComputationStatus;

      void onData(CoordClient *client);
      void onConnect();
      void onDisconnect(CoordClient *client);
      void eventLoop(bool daemon);

      void addDataSocket(CoordClient *client);
      void updateCheckpointInterval(uint32_t timeout);
      void updateMinimumState(WorkerState::eWorkerState oldState);
      void initializeComputation();
      void broadcastMessage(DmtcpMessageType type, int numPeers = -1);
      bool startCheckpoint();

      void handleUserCommand(char cmd, DmtcpMessage* reply = NULL);
      void printStatus(size_t numPeers, bool isRunning);
      string printList();

      void processDmtUserCmd(DmtcpMessage& hello_remote,
                             jalib::JSocket& remote);
      bool validateNewWorkerProcess(DmtcpMessage& hello_remote,
                                    jalib::JSocket& remote,
                                    CoordClient *client,
                                    const struct sockaddr_storage* addr,
                                    socklen_t len);
      bool validateRestartingWorkerProcess(DmtcpMessage& hello_remote,
                                           jalib::JSocket& remote,
                                           const struct sockaddr_storage* addr,
                                           socklen_t len);

      ComputationStatus getStatus() const;
      WorkerState::eWorkerState minimumState() const {
        return getStatus().minimumState;
      }

      pid_t getNewVirtualPid();

    protected:
      void writeRestartScript();
    private:

      // Store whether rsh/ssh was used
      map< string, vector<string> > _rshCmdFileNames;
      map< string, vector<string> > _sshCmdFileNames;

      //map from hostname to checkpoint files
      map< string, vector<string> > _restartFilenames;
      map< pid_t, CoordClient* > _virtualPidToClientMap;
  };

}

#endif