Commit dcf21e94 authored by unknown's avatar unknown
Browse files

BUG#21154 The management server consumes too much CPU

BUG#13987 Cluster: Loss of data nodes can cause high CPU usage from ndb_mgmd

fix the actual problem (getting incomplete line of data), introduced with previous
improvement.

also add list sessions, get session and get session id to mgmapi to allow
the implementation of a test case for this exact problem.


ndb/include/mgmapi/mgmapi.h:
  Add internal ndb_mgm_get_fd for use in test case
ndb/include/mgmapi/mgmapi_debug.h:
  Add internal get_session_id and get_session
ndb/include/util/InputStream.hpp:
  - fix warning when building with gcc 4
  - add mutex to be UNLOCKED when blocking (e.g. select(2))
    - this means we can list sessions in a threadsafe way
  - add this weird startover member to SocketInputStream
  	- this helps work out if we've read a newline yet and should start inserting
  	  into buffer from the start
ndb/include/util/Parser.hpp:
  add mutex to context to pass down to SocketInputStream
ndb/include/util/socket_io.h:
  readln_socket accepts mutex to UNLOCK around select(2)
ndb/src/common/util/InputStream.cpp:
  remove evil, add more.
  
  As
ndb/src/common/util/Parser.cpp:
  set mutex for passing down to InputStream to unlock on select(2).
  
  change way detecting of NoLine
ndb/src/common/util/socket_io.cpp:
  unlock a mutex around select so that we can nicely do thread safe
  listing of sessions.
  
  Always retrieve data from the OS so that we instantly get EOF on disconnect
  and don't end up spinning looking for a newline.
ndb/src/mgmapi/mgmapi.cpp:
  add internal ndb_mgm_get_fd() for internal testing
  
  internal/debug:
  ndb_mgm_get_session_id
  
  ndb_mgm_get_session
ndb/src/mgmsrv/Services.cpp:
  Add list sessions, get session id and get session.
  
  introduce a session mutex
ndb/src/mgmsrv/Services.hpp:
  Add list and get session.
  
  Add session_id to MgmApiSession.
ndb/test/ndbapi/testMgm.cpp:
  Add test for MgmApiSession disconnection (mgmd at 100%)
parent 81526834
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,19 @@ extern "C" {
   */
  int ndb_mgm_end_session(NdbMgmHandle handle);

  /**
   * ndb_mgm_get_fd
   *
   * get the file descriptor of the handle.
   * INTERNAL ONLY.
   * USE FOR TESTING. OTHER USES ARE NOT A GOOD IDEA.
   *
   * @param  handle NDB management handle
   * @return handle->socket
   *
   */
  int ndb_mgm_get_fd(NdbMgmHandle handle);

  /**
   * Get the node id of the mgm server we're connected to
   */
+14 −0
Original line number Diff line number Diff line
@@ -132,6 +132,20 @@ extern "C" {
				   const char * value,
				   struct ndb_mgm_reply* reply);

  Uint64 ndb_mgm_get_session_id(NdbMgmHandle handle);

  struct NdbMgmSession {
    Uint64 id;
    Uint32 m_stopSelf;
    Uint32 m_stop;
    Uint32 nodeid;
    Uint32 parser_buffer_len;
    Uint32 parser_status;
  };

  int ndb_mgm_get_session(NdbMgmHandle handle, Uint64 id,
                          struct NdbMgmSession *s, int *len);

#ifdef __cplusplus
}
#endif
+10 −0
Original line number Diff line number Diff line
@@ -19,13 +19,22 @@

#include <ndb_global.h>
#include <NdbTCP.h>
#include <NdbMutex.h>

/**
 * Input stream
 */
class InputStream {
public:
  InputStream() { m_mutex= NULL; };
  virtual ~InputStream() {};
  virtual char* gets(char * buf, int bufLen) = 0;
  /**
   * Set the mutex to be UNLOCKED when blocking (e.g. select(2))
   */
  void set_mutex(NdbMutex *m) { m_mutex= m; };
protected:
  NdbMutex *m_mutex;
};

class FileInputStream : public InputStream {
@@ -40,6 +49,7 @@ extern FileInputStream Stdin;
class SocketInputStream : public InputStream {
  NDB_SOCKET_TYPE m_socket;
  unsigned m_timeout;
  bool m_startover;
public:
  SocketInputStream(NDB_SOCKET_TYPE socket, unsigned readTimeout = 1000);
  char* gets(char * buf, int bufLen);
+4 −1
Original line number Diff line number Diff line
@@ -61,12 +61,15 @@ public:
  /**
   * Context for parse
   */
  struct Context {
  class Context {
  public:
    Context() { m_mutex= NULL; };
    ParserStatus m_status;
    const ParserRow<T> * m_currentCmd;
    const ParserRow<T> * m_currentArg;
    char * m_currentToken;
    char m_tokenBuffer[512];
    NdbMutex *m_mutex;

    Vector<const ParserRow<T> *> m_aliasUsed;
  };
+6 −1
Original line number Diff line number Diff line
@@ -21,12 +21,17 @@

#include <NdbTCP.h>

#include <NdbMutex.h>

#ifdef  __cplusplus
extern "C" {
#endif

  int read_socket(NDB_SOCKET_TYPE, int timeout_ms, char *, int len);
  int readln_socket(NDB_SOCKET_TYPE, int timeout_ms, char *, int len);

  int readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis,
                    char * buf, int buflen, NdbMutex *mutex);

  int write_socket(NDB_SOCKET_TYPE, int timeout_ms, const char[], int len);

  int print_socket(NDB_SOCKET_TYPE, int timeout_ms, const char *, ...); 
Loading