Drizzled Public API Documentation

queue_producer.h
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 David Shrewsbury
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <client/client_priv.h>
00024 #include <drizzled/error_t.h>
00025 #include <plugin/slave/queue_thread.h>
00026 #include <plugin/slave/sql_executor.h>
00027 #include <string>
00028 #include <vector>
00029 
00030 namespace slave
00031 {
00032   
00033 class QueueProducer : public QueueThread, public SQLExecutor
00034 {
00035 public:
00036   QueueProducer() :
00037     SQLExecutor("slave", "replication"),
00038     _check_interval(5),
00039     _master_port(3306),
00040     _master_id(0),
00041     _drizzle(NULL),
00042     _last_return(DRIZZLE_RETURN_OK),
00043     _is_connected(false),
00044     _saved_max_commit_id(0),
00045     _max_reconnects(10),
00046     _seconds_between_reconnects(30)
00047   {}
00048 
00049   virtual ~QueueProducer();
00050 
00051   bool init();
00052   bool process();
00053   void shutdown();
00054 
00055   void setSleepInterval(uint32_t seconds)
00056   {
00057     _check_interval= seconds;
00058   }
00059 
00060   uint32_t getSleepInterval()
00061   {
00062     return _check_interval;
00063   }
00064 
00065   void setMasterHost(const std::string &host)
00066   {
00067     _master_host= host;
00068   }
00069 
00070   void setMasterPort(uint16_t port)
00071   {
00072     _master_port= port;
00073   }
00074 
00075   void setMasterUser(const std::string &user)
00076   {
00077     _master_user= user;
00078   }
00079 
00080   void setMasterPassword(const std::string &password)
00081   {
00082     _master_pass= password;
00083   }
00084 
00085   void setMaxReconnectAttempts(uint32_t max)
00086   {
00087     _max_reconnects= max;
00088   }
00089 
00090   void setSecondsBetweenReconnects(uint32_t seconds)
00091   {
00092     _seconds_between_reconnects= seconds;
00093   }
00094 
00095   void setCachedMaxCommitId(uint64_t value)
00096   {
00097     _saved_max_commit_id= value;
00098   }
00099 
00100   uint64_t cachedMaxCommitId()
00101   {
00102     return _saved_max_commit_id;
00103   }
00104 
00105   void setMasterId(uint32_t value)
00106   {
00107     _master_id= value;
00108   }
00109 
00110   uint32_t masterId()
00111   {
00112     return _master_id;
00113   }
00114 
00115 private:
00117   uint32_t _check_interval;
00118 
00119   /* Master server connection parameters */
00120   std::string _master_host;
00121   uint16_t    _master_port;
00122   std::string _master_user;
00123   std::string _master_pass;
00124 
00125   uint32_t _master_id;
00126 
00127   drizzle_st *_drizzle;
00128   drizzle_con_st *_connection;
00129   drizzle_return_t _last_return;
00130 
00131   bool _is_connected;
00132   uint64_t _saved_max_commit_id;
00133   uint32_t _max_reconnects;
00134   uint32_t _seconds_between_reconnects;
00135 
00136   std::string _last_error_message;
00137 
00141   bool openConnection();
00142 
00146   bool closeConnection();
00147 
00157   bool reconnect(bool initial_connection);
00158 
00167   bool queryForMaxCommitId(uint64_t *max_commit_id);
00168 
00182   enum drizzled::error_t queryForReplicationEvents(uint64_t max_commit_id);
00183 
00184   bool queryForTrxIdList(uint64_t max_commit_id, std::vector<uint64_t> &list);
00185   bool queueInsert(const char *trx_id,
00186                    const char *seg_id,
00187                    const char *commit_id,
00188                    const char *originating_server_uuid,
00189                    const char *originating_commit_id,
00190                    const char *msg,
00191                    const char *msg_length);
00192 
00199   void setIOState(const std::string &err_msg, bool status);
00200 
00201 };
00202 
00203 } /* namespace slave */
00204