summaryrefslogtreecommitdiff
path: root/ndb/src/old_files/rep/adapters/AppNDB.hpp
blob: 9563a1e41ab5a3ec86e0e1c6ad5965854eb8834f (plain)
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
133
134
135
136
137
138
139
140
141
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program 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 General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef APPNDB_HPP
#define APPNDB_HPP
#include "NdbApi.hpp"

#include <NdbMain.h>
#include <NdbOut.hpp>
#include <NdbSleep.h>
#include <NdbTick.h>

#include <NdbThread.h>
#include <Vector.hpp>

#include "TableInfoPs.hpp"
#include <rep/storage/GCIContainer.hpp>
#include <rep/storage/GCIBuffer.hpp>

#include <rep/state/RepState.hpp>

extern "C" {
  void * runAppNDB_C(void *);
}

/**
 * @class AppNDB
 * @brief Connects to NDB and appliers log records into standby system
 */
class AppNDB {
public:
  /***************************************************************************
   * Constructor / Destructor / Init
   ***************************************************************************/
  AppNDB(class GCIContainer * gciContainer, class RepState * repState);
  ~AppNDB();

  void init(const char * connectString);

  GrepError::Code 
  applyBuffer(Uint32 nodeGrp, Uint32 first, Uint32 force);
  
  /**
   * Takes a table id and drops it.
   * @param tableId   Name of table to be dropped
   * @return Returns 1 = ok, -1 failed
   * 
   * @todo Fix: 0 usually means ok...
   */
  int dropTable(Uint32 tableId);
  void startApplier();
  void stopApplier(GrepError::Code err);  
private:
  /***************************************************************************
   * Methods
   ***************************************************************************/
  friend void* runAppNDB_C(void*);

  void threadMainAppNDB(void);

  /**
   * Takes a log records and does the operation specified in the log record
   * on NDB.
   * @param - lr (LogRecord)
   * @param - force true if GREP:SSCoord is in phase STARTING. 
   *	      Ignore "Execute" errors if true.
   */
  int applyLogRecord(LogRecord *  lr, bool force, Uint32 gci);

  /**
   * Applies a table based on a meta record and creates the table 
   * in NDB.
   * @param - meta record
   * @return - 0 on success, -1 if something went wrong
   */
  int applyMetaRecord(MetaRecord *  mr, Uint32 gci);

  /**
   * Takes a meta record and uses NdbDictionaryXXX::parseInfoTable 
   * and returns a table
   * @param mr - MetaRecord
   * @return - a table based on the meta record
   */
  NdbDictionary::Table* prepareMetaRecord(MetaRecord *  mr);

  /**
   * Prints out an NDB error message if a ndb operation went wrong.
   * @param msg - text explaining the error
   * @param err - NDB error type
   */
  void reportNdbError(const char * msg, const NdbError & err);
  
  /**
   * Prints out a warning message. Used if support for something
   * is not implemented.
   * @param tableName - the name of the table this warning occured on
   * @param message - warning message
   */
  void reportWarning(const char * tableName, const char * message);

  /**
   * Prints out a warning message. Used if support for something
   * is not implemented.
   * @param tableName - the name of the table this warning occured on
   * @param columnName - the name of the column this warning occured on
   * @param message - warning message
   */
  void reportWarning(const char * tableName, const char * columnName,
		     const char * message);


  /***************************************************************************
   * Variables
   ***************************************************************************/
  GCIContainer *               m_gciContainer;
  RepState *	               m_repState;

  Ndb*                         m_ndb;
  NdbDictionary::Dictionary *  m_dict;
  NodeId                       m_ownNodeId;
  bool                         m_started;
  TableInfoPs *                m_tableInfoPs;
  NdbThread*                   m_applierThread; 
  NdbCondition *	       m_cond;
  MutexVector<GCIBuffer*>      m_gciBufferList;
};

#endif