summaryrefslogtreecommitdiff
path: root/sql/rpl_injector.h
diff options
context:
space:
mode:
authorunknown <tomas@poseidon.ndb.mysql.com>2006-01-12 19:51:02 +0100
committerunknown <tomas@poseidon.ndb.mysql.com>2006-01-12 19:51:02 +0100
commit4c798b42d37d0df05c49bb6be3e105fae891dd23 (patch)
tree5f26130f48df39314474782dafb7b845ebffb2ff /sql/rpl_injector.h
parent5872e5aeb9424ae9c0472885bfd22fad53febd84 (diff)
downloadmariadb-git-4c798b42d37d0df05c49bb6be3e105fae891dd23.tar.gz
wl2325 wl2324
mysql-test/include/have_ndb_extra.inc: New BitKeeper file ``mysql-test/include/have_ndb_extra.inc'' mysql-test/include/not_ndb.inc: New BitKeeper file ``mysql-test/include/not_ndb.inc'' mysql-test/r/have_ndb_extra.require: New BitKeeper file ``mysql-test/r/have_ndb_extra.require'' mysql-test/r/ndb_alter_table_row.result: New BitKeeper file ``mysql-test/r/ndb_alter_table_row.result'' mysql-test/r/ndb_alter_table_stm.result: New BitKeeper file ``mysql-test/r/ndb_alter_table_stm.result'' mysql-test/r/ndb_binlog_basic.result: New BitKeeper file ``mysql-test/r/ndb_binlog_basic.result'' mysql-test/r/ndb_binlog_multi.result: New BitKeeper file ``mysql-test/r/ndb_binlog_multi.result'' mysql-test/r/ndb_multi_row.result: New BitKeeper file ``mysql-test/r/ndb_multi_row.result'' mysql-test/r/not_ndb.require: New BitKeeper file ``mysql-test/r/not_ndb.require'' mysql-test/r/rpl_ndb_bank.result: New BitKeeper file ``mysql-test/r/rpl_ndb_bank.result'' mysql-test/r/rpl_ndb_basic.result: New BitKeeper file ``mysql-test/r/rpl_ndb_basic.result'' mysql-test/r/rpl_ndb_disk.result: New BitKeeper file ``mysql-test/r/rpl_ndb_disk.result'' mysql-test/r/rpl_ndb_idempotent.result: New BitKeeper file ``mysql-test/r/rpl_ndb_idempotent.result'' mysql-test/r/rpl_ndb_load.result: New BitKeeper file ``mysql-test/r/rpl_ndb_load.result'' mysql-test/r/rpl_ndb_multi.result: New BitKeeper file ``mysql-test/r/rpl_ndb_multi.result'' mysql-test/r/rpl_ndb_sync.result: New BitKeeper file ``mysql-test/r/rpl_ndb_sync.result'' mysql-test/r/rpl_row_basic_7ndb.result: New BitKeeper file ``mysql-test/r/rpl_row_basic_7ndb.result'' mysql-test/t/ndb_alter_table_row.test: New BitKeeper file ``mysql-test/t/ndb_alter_table_row.test'' mysql-test/t/ndb_alter_table_stm.test: New BitKeeper file ``mysql-test/t/ndb_alter_table_stm.test'' mysql-test/t/ndb_binlog_basic.test: New BitKeeper file ``mysql-test/t/ndb_binlog_basic.test'' mysql-test/t/ndb_binlog_multi.test: New BitKeeper file ``mysql-test/t/ndb_binlog_multi.test'' mysql-test/t/ndb_multi_row.test: New BitKeeper file ``mysql-test/t/ndb_multi_row.test'' mysql-test/t/rpl_ndb_bank.test: New BitKeeper file ``mysql-test/t/rpl_ndb_bank.test'' mysql-test/t/rpl_ndb_basic.test: New BitKeeper file ``mysql-test/t/rpl_ndb_basic.test'' mysql-test/t/rpl_ndb_disk.test: New BitKeeper file ``mysql-test/t/rpl_ndb_disk.test'' mysql-test/t/rpl_ndb_idempotent.test: New BitKeeper file ``mysql-test/t/rpl_ndb_idempotent.test'' mysql-test/t/rpl_ndb_load.test: New BitKeeper file ``mysql-test/t/rpl_ndb_load.test'' mysql-test/t/rpl_ndb_multi.test: New BitKeeper file ``mysql-test/t/rpl_ndb_multi.test'' mysql-test/t/rpl_ndb_sync.test: New BitKeeper file ``mysql-test/t/rpl_ndb_sync.test'' mysql-test/t/rpl_row_basic_7ndb.test: New BitKeeper file ``mysql-test/t/rpl_row_basic_7ndb.test'' sql/ha_ndbcluster_binlog.cc: New BitKeeper file ``sql/ha_ndbcluster_binlog.cc'' sql/ha_ndbcluster_binlog.h: New BitKeeper file ``sql/ha_ndbcluster_binlog.h'' sql/ha_ndbcluster_tables.h: New BitKeeper file ``sql/ha_ndbcluster_tables.h'' sql/rpl_injector.cc: New BitKeeper file ``sql/rpl_injector.cc'' sql/rpl_injector.h: New BitKeeper file ``sql/rpl_injector.h'' storage/ndb/include/kernel/signaldata/DihFragCount.hpp: New BitKeeper file ``storage/ndb/include/kernel/signaldata/DihFragCount.hpp''
Diffstat (limited to 'sql/rpl_injector.h')
-rw-r--r--sql/rpl_injector.h251
1 files changed, 251 insertions, 0 deletions
diff --git a/sql/rpl_injector.h b/sql/rpl_injector.h
new file mode 100644
index 00000000000..32d3fdd1a78
--- /dev/null
+++ b/sql/rpl_injector.h
@@ -0,0 +1,251 @@
+/*
+ Copyright (C) 2005 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef INJECTOR_H
+#define INJECTOR_H
+
+/* Pull in 'byte', 'my_off_t', and 'uint32' */
+#include <my_global.h>
+
+#ifdef HAVE_ROW_BASED_REPLICATION
+#include <my_bitmap.h>
+
+/* Forward declarations */
+class handler;
+class MYSQL_LOG;
+class st_table;
+
+typedef st_table TABLE;
+
+/*
+ Injector to inject rows into the MySQL server.
+
+ The injector class is used to notify the MySQL server of new rows that have
+ appeared outside of MySQL control.
+
+ The original purpose of this is to allow clusters---which handle replication
+ inside the cluster through other means---to insert new rows into binary log.
+ Note, however, that the injector should be used whenever rows are altered in
+ any manner that is outside of MySQL server visibility and which therefore
+ are not seen by the MySQL server.
+ */
+class injector
+{
+public:
+
+ /*
+ Get an instance of the injector.
+
+ DESCRIPTION
+ The injector is a Singleton, so this static function return the
+ available instance of the injector.
+
+ RETURN VALUE
+ A pointer to the available injector object.
+ */
+ static injector *instance();
+
+ /*
+ A transaction where rows can be added.
+
+ DESCRIPTION
+ The transaction class satisfy the **CopyConstructible** and
+ **Assignable** requirements. Note that the transaction is *not*
+ default constructible.
+ */
+ class transaction {
+ friend class injector;
+ public:
+ /* Convenience definitions */
+ typedef byte* record_type;
+ typedef uint32 server_id_type;
+
+ /*
+ Table reference.
+
+ RESPONSIBILITY
+
+ The class contains constructors to handle several forms of
+ references to tables. The constructors can implicitly be used to
+ construct references from, e.g., strings containing table names.
+
+ EXAMPLE
+
+ The class is intended to be used *by value*. Please, do not try to
+ construct objects of this type using 'new'; instead construct an
+ object, possibly a temporary object. For example:
+
+ injector::transaction::table tbl(share->table, true);
+ MY_BITMAP cols;
+ bitmap_init(&cols, NULL, (i + 7) / 8, false);
+ inj->write_row(::server_id, tbl, &cols, row_data);
+
+ or
+
+ MY_BITMAP cols;
+ bitmap_init(&cols, NULL, (i + 7) / 8, false);
+ inj->write_row(::server_id,
+ injector::transaction::table(share->table, true),
+ &cols, row_data);
+
+ This will work, be more efficient, and have greater chance of
+ inlining, not run the risk of losing pointers.
+
+ COLLABORATION
+
+ injector::transaction
+ Provide a flexible interface to the representation of tables.
+
+ */
+ class table
+ {
+ public:
+ table(TABLE *table, bool is_transactional)
+ : m_table(table), m_is_transactional(is_transactional)
+ {
+ }
+
+ char const *db_name() const { return m_table->s->db.str; }
+ char const *table_name() const { return m_table->s->table_name.str; }
+ TABLE *get_table() const { return m_table; }
+ bool is_transactional() const { return m_is_transactional; }
+
+ private:
+ TABLE *m_table;
+ bool m_is_transactional;
+ };
+
+ /*
+ Binlog position as a structure.
+ */
+ class binlog_pos {
+ friend class transaction;
+ public:
+ char const *file_name() const { return m_file_name; }
+ my_off_t file_pos() const { return m_file_pos; }
+
+ private:
+ char const *m_file_name;
+ my_off_t m_file_pos;
+ };
+
+ transaction() : m_thd(NULL) { }
+ transaction(transaction const&);
+ ~transaction();
+
+ /* Clear transaction, i.e., make calls to 'good()' return false. */
+ void clear() { m_thd= NULL; }
+
+ /* Is the transaction in a good state? */
+ bool good() const { return m_thd != NULL; }
+
+ /* Default assignment operator: standard implementation */
+ transaction& operator=(transaction t) {
+ swap(t);
+ return *this;
+ }
+
+ /*
+ Add a 'write row' entry to the transaction.
+ */
+ int write_row (server_id_type sid, table tbl,
+ MY_BITMAP const *cols, size_t colcnt,
+ record_type record);
+
+ /*
+ Add a 'delete row' entry to the transaction.
+ */
+ int delete_row(server_id_type sid, table tbl,
+ MY_BITMAP const *cols, size_t colcnt,
+ record_type record);
+
+ /*
+ Add an 'update row' entry to the transaction.
+ */
+ int update_row(server_id_type sid, table tbl,
+ MY_BITMAP const *cols, size_t colcnt,
+ record_type before, record_type after);
+
+ /*
+ Commit a transaction.
+
+ This member function will clean up after a sequence of *_row calls by,
+ for example, releasing resource and unlocking files.
+ */
+ int commit();
+
+ /*
+ Get the position for the start of the transaction.
+
+ Returns the position in the binary log of the first event in this
+ transaction. If no event is yet written, the position where the event
+ *will* be written is returned. This position is known, since a
+ new_transaction() will lock the binary log and prevent any other
+ writes to the binary log.
+ */
+ binlog_pos start_pos() const;
+
+ private:
+ /* Only the injector may construct these object */
+ transaction(MYSQL_LOG *, THD *);
+
+ void swap(transaction& o) {
+ /* std::swap(m_start_pos, o.m_start_pos); */
+ {
+ binlog_pos const tmp= m_start_pos;
+ m_start_pos= o.m_start_pos;
+ o.m_start_pos= tmp;
+ }
+
+ /* std::swap(m_thd, o.m_thd); */
+ {
+ THD* const tmp= m_thd;
+ m_thd= o.m_thd;
+ o.m_thd= tmp;
+ }
+ }
+
+ binlog_pos m_start_pos;
+ THD *m_thd;
+ };
+
+ /*
+ Create a new transaction. This member function will prepare for a
+ sequence of *_row calls by, for example, reserving resources and
+ locking files. There are two overloaded alternatives: one returning a
+ transaction by value and one using placement semantics. The following
+ two calls are equivalent, with the exception that the latter will
+ overwrite the transaction.
+
+ injector::transaction trans1= inj->new_trans(thd);
+
+ injector::transaction trans2;
+ inj->new_trans(thd, &trans);
+ */
+ transaction new_trans(THD *);
+ void new_trans(THD *, transaction *);
+
+private:
+ explicit injector();
+ ~injector() { } /* Nothing needs to be done */
+ injector(injector const&); /* You're not allowed to copy injector
+ instances.
+ */
+};
+
+#endif /* HAVE_ROW_BASED_REPLICATION */
+#endif /* INJECTOR_H */