0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RequestHandlerRenewSession.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include "Common/Compat.h"
23 #include "Common/Error.h"
24 #include "Common/Logger.h"
25 #include "Common/InetAddr.h"
26 
27 #include "AsyncComm/CommBuf.h"
28 
29 #include "Hyperspace/Protocol.h"
30 #include "Hyperspace/Master.h"
32 #include "Hyperspace/SessionData.h"
33 
34 using namespace Hyperspace;
35 using namespace Hypertable;
36 
37 /*
38  *
39  */
41 
42  int error;
43 
44  try {
45  SessionDataPtr session_ptr;
46 
47  if (m_destroy_session) {
49  return;
50  }
51 
52  // if this is not the current replication master then try to return
53  // addr of current master
54 
55  if (!m_master->is_master()) {
56  String location = m_master->get_current_master();
57 
58  HT_DEBUG_OUT << "Redirecting request to current master " << location << HT_END;
59 
60  CommBufPtr cbp(Protocol::create_server_redirect_request(location));
61  error = m_comm->send_datagram(m_event->addr, *m_send_addr, cbp);
62  if (error != Error::OK) {
63  HT_ERRORF("Comm::send_datagram returned %s", Error::get_text(error));
64  }
65  HT_DEBUG_OUT << "Redirected request to current master " << location << HT_END;
66  return;
67  }
68 
69  HT_DEBUG_OUT << "Handling renew session request at local (master) site" << HT_END;
70 
71  if (m_session_id == 0) {
72  HT_DEBUG_OUT << "Do create session request at local (master) site" << HT_END;
74  HT_INFOF("Session handle %llu created", (Llu)m_session_id);
75  error = Error::OK;
76  }
77  else
79 
80  if (error == Error::HYPERSPACE_EXPIRED_SESSION) {
81  HT_INFOF("Session handle %llu expired", (Llu)m_session_id);
82  CommBufPtr cbp(Protocol::create_server_keepalive_request(m_session_id,
84  error = m_comm->send_datagram(m_event->addr, *m_send_addr, cbp);
85  if (error != Error::OK) {
86  HT_ERRORF("Comm::send_datagram returned %s",
87  Error::get_text(error));
88  }
89  return;
90  }
91 
92  if (!m_master->get_session(m_session_id, session_ptr)) {
93  HT_ERRORF("Unable to find data for session %llu", (Llu)m_session_id);
94  return;
95  }
96 
97  session_ptr->purge_notifications(m_delivered_events);
98 
99  /*
100  HT_INFOF("Sending Keepalive request to %s (m_last_known_event=%lld)",
101  InetAddr::format(m_event->addr), m_last_known_event);
102  **/
103 
104  CommBufPtr cbp(Protocol::create_server_keepalive_request(
105  session_ptr));
106  error = m_comm->send_datagram(m_event->addr, *m_send_addr, cbp);
107  if (error != Error::OK) {
108  HT_ERRORF("Comm::send_datagram returned %s",
109  Error::get_text(error));
110  }
111 
112  }
113  catch (Exception &e) {
114  HT_ERROR_OUT << e << HT_END;
115  }
116 }
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
virtual void run()
Carries out the request.
Declarations for Protocol.
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
bool get_session(uint64_t session_id, SessionDataPtr &session_data)
Definition: Master.cc:291
std::shared_ptr< SessionData > SessionDataPtr
Definition: SessionData.h:156
int send_datagram(const CommAddress &addr, const CommAddress &send_addr, CommBufPtr &cbuf)
Sends a datagram to a remote address.
Definition: Comm.cc:437
Hyperspace definitions
void destroy_session(uint64_t session_id)
Definition: Master.cc:305
bool is_master()
Definition: Master.h:78
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
Logging routines and macros.
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
Hypertable definitions
Declarations for CommBuf.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
uint64_t create_session(struct sockaddr_in &addr)
Definition: Master.cc:263
int renew_session_lease(uint64_t session_id)
Definition: Master.cc:354
Internet address wrapper classes and utility functions.
This is a generic exception class for Hypertable.
Definition: Error.h:314
String get_current_master()
Definition: Master.h:84
#define HT_ERRORF(msg,...)
Definition: Logger.h:300
Error codes, Exception handling, error logging.
#define HT_DEBUG_OUT
Definition: Logger.h:261