Drizzled Public API Documentation

queue_consumer.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 <plugin/slave/queue_thread.h>
00024 #include <plugin/slave/sql_executor.h>
00025 #include <drizzled/session.h>
00026 #include <string>
00027 
00028 namespace drizzled
00029 {
00030   namespace message
00031   {
00032     class Transaction;
00033   }
00034 }
00035 
00036 namespace slave
00037 {
00038 
00039 class QueueConsumer : public QueueThread, public SQLExecutor
00040 {
00041 public:
00042   QueueConsumer() :
00043     QueueThread(),
00044     SQLExecutor("slave", "replication"),
00045     _check_interval(5),
00046     _ignore_errors(false)
00047   { }
00048 
00049   bool init();
00050   bool process();
00051   void shutdown();
00052 
00053   void setSleepInterval(uint32_t seconds)
00054   {
00055     _check_interval= seconds;
00056   }
00057 
00058   uint32_t getSleepInterval()
00059   {
00060     return _check_interval;
00061   }
00062   
00066   void setIgnoreErrors(bool value)
00067   {
00068     _ignore_errors= value;
00069   }
00070 
00077   void setApplierState(const std::string &err_msg, bool status);
00078 
00079   void addMasterId(uint32_t id)
00080   {
00081     _master_ids.push_back(id);
00082   }
00083 
00084   bool processSingleMaster(const std::string &master_id);
00085 
00086 private:
00087   typedef std::vector<uint64_t> TrxIdList;
00088 
00090   uint32_t _check_interval;
00091 
00092   std::vector<uint32_t> _master_ids;
00093 
00094   bool _ignore_errors;
00095 
00108   bool getListOfCompletedTransactions(const std::string &master_id,
00109                                       TrxIdList &list);
00110 
00111   bool getMessage(drizzled::message::Transaction &transaction,
00112                   std::string &commit_id,
00113                   const std::string &master_id,
00114                   uint64_t trx_id,
00115                   std::string &originating_server_uuid,
00116                   uint64_t &originating_commit_id,
00117                   uint32_t segment_id);
00118 
00129   bool convertToSQL(const drizzled::message::Transaction &transaction,
00130                     std::vector<std::string> &aggregate_sql,
00131                     std::vector<std::string> &segmented_sql);
00132 
00146   bool executeSQLWithCommitId(std::vector<std::string> &sql,
00147                               const std::string &commit_id,
00148                               const std::string &originating_server_uuid,
00149                               uint64_t originating_commit_id,
00150                               const std::string &master_id);
00151   
00160   bool deleteFromQueue(const std::string &master_id, uint64_t trx_id);
00161 
00168   bool isEndStatement(const drizzled::message::Statement &statement);
00169 };
00170 
00171 } /* namespace slave */
00172