~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/transaction_reader.cc

  • Committer: David Shrewsbury
  • Date: 2010-08-27 13:01:51 UTC
  • mto: (1734.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1735.
  • Revision ID: shrewsbury.dave@gmail.com-20100827130151-vxlwsbryusweara6
Fix to capture INSERTs from a LOAD DATA command in the replication stream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
  }
95
95
}
96
96
 
 
97
static bool isEndStatement(const message::Statement &statement)
 
98
{
 
99
  switch (statement.type())
 
100
  {
 
101
    case (message::Statement::INSERT):
 
102
    {
 
103
      const message::InsertData &data= statement.insert_data();
 
104
      if (not data.end_segment())
 
105
        return false;
 
106
      break;
 
107
    }
 
108
    case (message::Statement::UPDATE):
 
109
    {
 
110
      const message::UpdateData &data= statement.update_data();
 
111
      if (not data.end_segment())
 
112
        return false;
 
113
      break;
 
114
    }
 
115
    case (message::Statement::DELETE):
 
116
    {
 
117
      const message::DeleteData &data= statement.delete_data();
 
118
      if (not data.end_segment())
 
119
        return false;
 
120
      break;
 
121
    }
 
122
    default:
 
123
      return true;
 
124
  }
 
125
  return true;
 
126
}
 
127
 
97
128
static void printTransaction(const message::Transaction &transaction)
98
129
{
 
130
  static uint64_t last_trx_id= 0;
 
131
  bool should_commit= true;
99
132
  const message::TransactionContext trx= transaction.transaction_context();
100
133
 
101
134
  size_t num_statements= transaction.statement_size();
102
135
  size_t x;
103
136
 
104
 
  cout << "START TRANSACTION;" << endl;
 
137
  /*
 
138
   * One way to determine when a new transaction begins is when the
 
139
   * transaction id changes. We check that here.
 
140
   */
 
141
  if (trx.transaction_id() != last_trx_id)
 
142
    cout << "START TRANSACTION;" << endl;
 
143
 
 
144
  last_trx_id= trx.transaction_id();
 
145
 
105
146
  for (x= 0; x < num_statements; ++x)
106
147
  {
107
148
    const message::Statement &statement= transaction.statement(x);
 
149
 
 
150
    if (should_commit)
 
151
      should_commit= isEndStatement(statement);
 
152
 
108
153
    printStatement(statement);
109
154
  }
110
 
  cout << "COMMIT;" << endl;
 
155
 
 
156
  /*
 
157
   * If ALL Statements are end segments, we can commit this Transaction.
 
158
   * We can also check to see if the transaction_id changed, but this
 
159
   * wouldn't work for the last Transaction in the transaction log since
 
160
   * we don't have another Transaction to compare to. Checking for all
 
161
   * end segments (like we do above) covers this case.
 
162
   */
 
163
  if (should_commit)
 
164
    cout << "COMMIT;" << endl;
111
165
}
112
166
 
113
167
int main(int argc, char* argv[])