Drizzled Public API Documentation

replication_dictionary.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
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 #include <config.h>
00022 
00023 #include "replication_dictionary.h"
00024 #include <drizzled/current_session.h>
00025 
00026 #include "univ.i"
00027 #include "btr0sea.h"
00028 #include "os0file.h"
00029 #include "os0thread.h"
00030 #include "srv0start.h"
00031 #include "srv0srv.h"
00032 #include "trx0roll.h"
00033 #include "trx0trx.h"
00034 #include "trx0sys.h"
00035 #include "mtr0mtr.h"
00036 #include "row0ins.h"
00037 #include "row0mysql.h"
00038 #include "row0sel.h"
00039 #include "row0upd.h"
00040 #include "log0log.h"
00041 #include "lock0lock.h"
00042 #include "dict0crea.h"
00043 #include "btr0cur.h"
00044 #include "btr0btr.h"
00045 #include "fsp0fsp.h"
00046 #include "sync0sync.h"
00047 #include "fil0fil.h"
00048 #include "trx0xa.h"
00049 #include "row0merge.h"
00050 #include "thr0loc.h"
00051 #include "dict0boot.h"
00052 #include "ha_prototypes.h"
00053 #include "ut0mem.h"
00054 #include "ibuf0ibuf.h"
00055 #include "create_replication.h"
00056 #include "read_replication.h"
00057 #include "handler0vars.h"
00058 
00059 #include <drizzled/drizzled.h>
00060 
00061 #include <drizzled/replication_services.h>
00062 
00063 #include <google/protobuf/io/zero_copy_stream.h>
00064 #include <google/protobuf/io/zero_copy_stream_impl.h>
00065 #include <google/protobuf/io/coded_stream.h>
00066 #include <google/protobuf/text_format.h>
00067 #include <string>
00068 
00069 using namespace drizzled;
00070 
00071 /*
00072  * Fill the dynamic table data_dictionary.INNODB_CMP and INNODB_CMP_RESET
00073  *
00074  */
00075 InnodbReplicationTable::InnodbReplicationTable() :
00076   plugin::TableFunction("DATA_DICTIONARY", "INNODB_REPLICATION_LOG")
00077 {
00078   add_field("TRANSACTION_ID", plugin::TableFunction::NUMBER, 0, false);
00079   add_field("TRANSACTION_SEGMENT_ID", plugin::TableFunction::NUMBER, 0, false);
00080   add_field("COMMIT_ID", plugin::TableFunction::NUMBER, 0, false);
00081   add_field("END_TIMESTAMP", plugin::TableFunction::NUMBER, 0, false);
00082   add_field("TRANSACTION_MESSAGE_STRING", plugin::TableFunction::STRING, transaction_message_threshold, false);
00083   add_field("TRANSACTION_LENGTH", plugin::TableFunction::NUMBER, 0, false);
00084 }
00085 
00086 InnodbReplicationTable::Generator::Generator(Field **arg) :
00087   plugin::TableFunction::Generator(arg)
00088 {
00089   replication_state =replication_read_init();
00090 }
00091 
00092 InnodbReplicationTable::Generator::~Generator()
00093 {
00094   replication_read_deinit(replication_state);
00095 }
00096 
00097 bool InnodbReplicationTable::Generator::populate()
00098 {
00099   struct read_replication_return_st ret= replication_read_next(replication_state);
00100 
00101   if (ret.message == NULL)
00102     return false;
00103 
00104   /* Transaction ID */
00105   push(static_cast<uint64_t>(ret.id));
00106 
00107   /* Segment ID */
00108   push(static_cast<uint64_t>(ret.seg_id));
00109 
00110   push(static_cast<uint64_t>(ret.commit_id));
00111 
00112   push(static_cast<uint64_t>(ret.end_timestamp));
00113   
00114   /* Message in viewable format */
00115   bool result= message.ParseFromArray(ret.message, ret.message_length);
00116 
00117   if (result == false)
00118   {
00119     fprintf(stderr, _("Unable to parse transaction. Got error: %s.\n"), message.InitializationErrorString().c_str());
00120     push("error");
00121   }
00122   else
00123   {
00124     google::protobuf::TextFormat::PrintToString(message, &transaction_text);
00125     push(transaction_text);
00126   }
00127 
00128   push(static_cast<int64_t>(ret.message_length));
00129 
00130   return true;
00131 }