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("ORIGINATING_SERVER_UUID", plugin::TableFunction::STRING, 36, false);
00083   add_field("ORIGINATING_COMMIT_ID", plugin::TableFunction::NUMBER, 0, false);
00084   add_field("TRANSACTION_MESSAGE_STRING", plugin::TableFunction::STRING, transaction_message_threshold, false);
00085   add_field("TRANSACTION_LENGTH", plugin::TableFunction::NUMBER, 0, false);
00086 }
00087 
00088 InnodbReplicationTable::Generator::Generator(Field **arg) :
00089   plugin::TableFunction::Generator(arg)
00090 {
00091   replication_state =replication_read_init();
00092 }
00093 
00094 InnodbReplicationTable::Generator::~Generator()
00095 {
00096   replication_read_deinit(replication_state);
00097 }
00098 
00099 bool InnodbReplicationTable::Generator::populate()
00100 {
00101   struct read_replication_return_st ret= replication_read_next(replication_state);
00102 
00103   if (ret.message == NULL)
00104     return false;
00105 
00106   /* Transaction ID */
00107   push(static_cast<uint64_t>(ret.id));
00108 
00109   /* Segment ID */
00110   push(static_cast<uint64_t>(ret.seg_id));
00111 
00112   push(static_cast<uint64_t>(ret.commit_id));
00113 
00114   push(static_cast<uint64_t>(ret.end_timestamp));
00115 
00116   push(ret.originating_server_uuid);
00117 
00118   push(static_cast<uint64_t>(ret.originating_commit_id));
00119   
00120   /* Message in viewable format */
00121   bool result= message.ParseFromArray(ret.message, ret.message_length);
00122 
00123   if (result == false)
00124   {
00125     fprintf(stderr, _("Unable to parse transaction. Got error: %s.\n"), message.InitializationErrorString().c_str());
00126     push("error");
00127   }
00128   else
00129   {
00130     google::protobuf::TextFormat::PrintToString(message, &transaction_text);
00131     push(transaction_text);
00132   }
00133 
00134   push(static_cast<int64_t>(ret.message_length));
00135 
00136   return true;
00137 }