Revision 87b5e5cb include/FedReplicaManager.h

View differences:

include/FedReplicaManager.h
26 26

  
27 27
extern "C" void * frm_loop(void *arg);
28 28

  
29
class SqlDB;
29
class LogDB;
30
class LogDBRecord;
30 31

  
31 32
class FedReplicaManager : public ReplicaManager, ActionListener
32 33
{
33 34
public:
34 35

  
35 36
    /**
36
     *  @param _t timer for periofic actions (sec)
37
     *  @param _p purge timeout for log
38 37
     *  @param d pointer to underlying DB (LogDB)
39
     *  @param l log_retention length (num records)
40 38
     */
41
    FedReplicaManager(time_t _t, time_t _p, SqlDB * d, unsigned int l);
39
    FedReplicaManager(LogDB * d);
42 40

  
43 41
    virtual ~FedReplicaManager();
44 42

  
45 43
    /**
46
     *  Creates a new record in the federation log and sends the replication
47
     *  event to the replica threads. [MASTER]
48
     *    @param sql db command to replicate
49
     *    @return 0 on success -1 otherwise
44
     *  Sends the replication event to the replica threads. [MASTER]
50 45
     */
51
    int replicate(const std::string& sql);
46
    void replicate(const std::string& sql)
47
    {
48
        ReplicaManager::replicate();
49
    }
52 50

  
53 51
    /**
54 52
     *  Updates the current index in the server and applies the command to the
55 53
     *  server. It also stores the record in the zone log [SLAVE]
56 54
     *    @param index of the record
55
     *    @param prev of index preceding this one
57 56
     *    @param sql command to apply to DB
58 57
     *    @return 0 on success, last_index if missing records, -1 on DB error
59 58
     */
60
    int apply_log_record(int index, const std::string& sql);
59
    int apply_log_record(int index, int prev, const std::string& sql);
61 60

  
62 61
    /**
63 62
     *  Record was successfully replicated on zone, increase next index and
......
106 105

  
107 106
        update_zones(zids);
108 107

  
109
        get_last_index(last_index);
110

  
111 108
        ReplicaManager::start_replica_threads(zids);
112 109
    }
113 110

  
......
134 131
    void delete_zone(int zone_id);
135 132

  
136 133
    /**
137
     *  Bootstrap federated log
138
     */
139
    static int bootstrap(SqlDB *_db);
140

  
141
    /**
142 134
     *  @return the id of fed. replica thread
143 135
     */
144 136
    pthread_t get_thread_id() const
......
146 138
        return frm_thread;
147 139
    };
148 140

  
149
    /**
150
     *  @return the last index of the fed log (from DB to use this method in
151
     *  HA followers)
152
     */
153
    unsigned int get_last_index() const
154
    {
155
        unsigned int li;
156

  
157
        get_last_index(li);
158

  
159
        return li;
160
    }
161

  
162 141
private:
163 142
    friend void * frm_loop(void *arg);
164 143

  
......
177 156
     */
178 157
    pthread_mutex_t mutex;
179 158

  
180
    //--------------------------------------------------------------------------
181
    //  Timers
182
    //    - timer_period. Base timer to wake up the manager
183
    //    - purge_period. How often the replicated log is purged (600s)
184
    //    - xmlrpc_timeout. To timeout xml-rpc api calls to replicate log
185
    //--------------------------------------------------------------------------
186
    time_t timer_period;
187

  
188
    time_t purge_period;
189

  
190
    static const time_t xmlrpc_timeout_ms;
191

  
192 159
    // -------------------------------------------------------------------------
193 160
    // Synchronization variables
194
    //   - last_index in the replication log
161
    //   - xmlrpc_timeout. To timeout xml-rpc api calls to replicate log
195 162
    //   - zones list of zones in the federation with:
196 163
    //     - list of servers <id, xmlrpc endpoint>
197 164
    //     - next index to send to this zone
198 165
    // -------------------------------------------------------------------------
166
    static const time_t xmlrpc_timeout_ms;
167

  
199 168
    struct ZoneServers
200 169
    {
201 170
        ZoneServers(int z, unsigned int l, const std::string& s):
202
            zone_id(z), endpoint(s), next(l){};
171
            zone_id(z), endpoint(s), next(l), last(-1){};
203 172

  
204 173
        ~ZoneServers(){};
205 174

  
......
207 176

  
208 177
        std::string  endpoint;
209 178

  
210
        unsigned int next;
179
        int next;
180

  
181
        int last;
211 182
    };
212 183

  
213 184
    std::map<int, ZoneServers *> zones;
214 185

  
215
    unsigned int last_index;
216

  
217
    SqlDB * logdb;
218

  
219
    unsigned int log_retention;
186
    LogDB * logdb;
220 187

  
221 188
    // -------------------------------------------------------------------------
222 189
    // Action Listener interface
......
229 196
    void finalize_action(const ActionRequest& ar);
230 197

  
231 198
    /**
232
     *  This function is executed periodically to purge the state log
233
     */
234
    void timer_action(const ActionRequest& ar);
235

  
236
    // -------------------------------------------------------------------------
237
    // Database Implementation
238
    // Store log records to replicate on federation slaves
239
    // -------------------------------------------------------------------------
240
    static const char * table;
241

  
242
    static const char * db_names;
243

  
244
    static const char * db_bootstrap;
245

  
246
    /**
247
     *  Gets a record from the log
248
     *    @param index of the record
249
     *    @param sql command of the record
250
     *    @return 0 in case of success -1 otherwise
251
     */
252
    int get_log_record(int index, std::string& sql);
253

  
254
    /**
255
     *  Inserts a new record in the log ans updates the last_index variable
256
     *  (memory and db)
257
     *    @param index of new record
258
     *    @param sql of DB command to execute
259
     *    @return 0 on success
260
     */
261
    int insert_log_record(int index, const std::string& sql);
262

  
263
    /**
264
     *  Reads the last index from DB for initialization
265
     *    @param index
266
     *    @return 0 on success
267
     */
268
    int get_last_index(unsigned int& index) const;
269

  
270
    /**
271 199
     *  Get the nest record to replicate in a zone
272 200
     *    @param zone_id of the zone
273 201
     *    @param index of the next record to send
274 202
     *    @param sql command to replicate
275 203
     *    @return 0 on success, -1 otherwise
276 204
     */
277
    int get_next_record(int zone_id, int& index, std::string& sql,
278
        std::string& zservers);
205
    int get_next_record(int zone_id, std::string& zedp, LogDBRecord& lr);
206

  
279 207
};
280 208

  
281 209
#endif /*FED_REPLICA_MANAGER_H_*/

Also available in: Unified diff