Merge lp:~dshrews/drizzle/bug731293_persist_maxcommitid into lp:drizzle/7.0

Proposed by David Shrewsbury
Status: Merged
Approved by: Brian Aker
Approved revision: 2226
Merged at revision: 2229
Proposed branch: lp:~dshrews/drizzle/bug731293_persist_maxcommitid
Merge into: lp:drizzle/7.0
Diff against target: 125 lines (+46/-3)
5 files modified
plugin/slave/queue_producer.h (+1/-1)
plugin/slave/replication_schema.cc (+13/-0)
plugin/slave/replication_schema.h (+15/-0)
plugin/slave/replication_slave.cc (+9/-0)
plugin/slave/replication_slave.h (+8/-2)
To merge this branch: bzr merge lp:~dshrews/drizzle/bug731293_persist_maxcommitid
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+52726@code.launchpad.net

Description of the change

If the supplies a value for --slave.max-commit-id, it is currently possible that this "gets lost" unless another event from the master is received (making the position permanent) before another restart. This branch records the value in the applier_state table immediately at startup.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugin/slave/queue_producer.h'
2--- plugin/slave/queue_producer.h 2011-03-08 06:28:23 +0000
3+++ plugin/slave/queue_producer.h 2011-03-09 18:31:51 +0000
4@@ -91,7 +91,7 @@
5 _seconds_between_reconnects= seconds;
6 }
7
8- void setMaxCommitId(uint64_t value)
9+ void setCachedMaxCommitId(uint64_t value)
10 {
11 _saved_max_commit_id= value;
12 }
13
14=== modified file 'plugin/slave/replication_schema.cc'
15--- plugin/slave/replication_schema.cc 2011-02-23 16:49:25 +0000
16+++ plugin/slave/replication_schema.cc 2011-03-09 18:31:51 +0000
17@@ -24,9 +24,11 @@
18 #include <drizzled/sql/result_set.h>
19 #include <string>
20 #include <vector>
21+#include <boost/lexical_cast.hpp>
22
23 using namespace std;
24 using namespace drizzled;
25+using namespace boost;
26
27 namespace slave
28 {
29@@ -130,4 +132,15 @@
30 return true;
31 }
32
33+bool ReplicationSchema::setInitialMaxCommitId(uint64_t value)
34+{
35+ vector<string> sql;
36+
37+ sql.push_back("UPDATE `sys_replication`.`applier_state`"
38+ " SET `last_applied_commit_id` = "
39+ + lexical_cast<string>(value));
40+
41+ return executeSQL(sql);
42+}
43+
44 } /* namespace slave */
45
46=== modified file 'plugin/slave/replication_schema.h'
47--- plugin/slave/replication_schema.h 2011-02-17 14:20:50 +0000
48+++ plugin/slave/replication_schema.h 2011-03-09 18:31:51 +0000
49@@ -33,6 +33,21 @@
50 { }
51
52 bool create();
53+
54+ /**
55+ * Set initial value of the last applied COMMIT_ID value in applier_state.
56+ *
57+ * This is used when the server is started with --slave.max-commit-id to
58+ * begin reading from the master transaction log at a given point. This
59+ * method will persist the value to the applier_state table. If it wasn't
60+ * permanently stored immediately, we risk the possibility of losing the
61+ * value if the server is again restarted without ever having received
62+ * another event from the master (which causes persistence of the value).
63+ * An edge case, but still possible.
64+ *
65+ * @param[in] value The initial value.
66+ */
67+ bool setInitialMaxCommitId(uint64_t value);
68 };
69
70 } /* namespace slave */
71
72=== modified file 'plugin/slave/replication_slave.cc'
73--- plugin/slave/replication_slave.cc 2011-03-02 16:32:36 +0000
74+++ plugin/slave/replication_slave.cc 2011-03-09 18:31:51 +0000
75@@ -110,6 +110,15 @@
76 return false;
77 }
78
79+ if (_initial_max_commit_id)
80+ {
81+ if (not rs.setInitialMaxCommitId(_initial_max_commit_id))
82+ {
83+ _error= rs.getErrorMessage();
84+ return false;
85+ }
86+ }
87+
88 return true;
89 }
90
91
92=== modified file 'plugin/slave/replication_slave.h'
93--- plugin/slave/replication_slave.h 2011-03-07 21:42:32 +0000
94+++ plugin/slave/replication_slave.h 2011-03-09 18:31:51 +0000
95@@ -41,7 +41,8 @@
96
97 ReplicationSlave(const std::string &config)
98 : drizzled::plugin::Daemon("Replication Slave"),
99- _config_file(config)
100+ _config_file(config),
101+ _initial_max_commit_id(0)
102 {}
103
104 ~ReplicationSlave()
105@@ -73,7 +74,10 @@
106 */
107 void setMaxCommitId(uint64_t value)
108 {
109- _producer.setMaxCommitId(value);
110+ /* must tell producer to set its cached value */
111+ _producer.setCachedMaxCommitId(value);
112+ /* setting this indicates that we should store it permanently */
113+ _initial_max_commit_id= value;
114 }
115
116 private:
117@@ -89,6 +93,8 @@
118 /** I/O thread that will populate the work queue */
119 boost::thread _producer_thread;
120
121+ uint64_t _initial_max_commit_id;
122+
123 /**
124 * Initialize slave services with the given configuration file.
125 *

Subscribers

People subscribed via source and target branches