@@ -357,7 +357,7 @@ void Tablet::StartTransaction(WriteTransactionState* tx_state) {
357357}
358358
359359Status Tablet::InsertUnlocked (WriteTransactionState *tx_state,
360- RowOp* insert) {
360+ RowOp* insert, int offset ) {
361361 const TabletComponents* comps = DCHECK_NOTNULL (tx_state->tablet_components ());
362362
363363 CHECK (state_ == kOpen || state_ == kBootstrapping );
@@ -367,6 +367,26 @@ Status Tablet::InsertUnlocked(WriteTransactionState *tx_state,
367367 DCHECK_EQ (tx_state->schema_at_decode_time (), schema ()) << " Raced against schema change" ;
368368 DCHECK (tx_state->op_id ().IsInitialized ()) << " TransactionState OpId needed for anchoring" ;
369369
370+ int key_col_size = schema ()->num_key_columns ();
371+ if (key_col_size >= 3
372+ && schema ()->column (key_col_size - 1 ).name () == " op_id_offset"
373+ && schema ()->column (key_col_size - 2 ).name () == " op_id_index"
374+ && schema ()->column (key_col_size - 3 ).name () == " op_id_term" ) {
375+ // LOG(INFO) << "Replacing term/index cols with val: " << tx_state->op_id().ShortDebugString() << ":" << offset;
376+ ContiguousRow row_to_modify (schema (), (uint8_t *)(insert->decoded_op .row_data ));
377+
378+ // Substitute in op_id info
379+ *reinterpret_cast <int64_t *>(row_to_modify.mutable_cell_ptr (key_col_size - 3 )) = tx_state->op_id ().term ();
380+ *reinterpret_cast <int64_t *>(row_to_modify.mutable_cell_ptr (key_col_size - 2 )) = tx_state->op_id ().index ();
381+ *reinterpret_cast <int32_t *>(row_to_modify.mutable_cell_ptr (key_col_size - 1 )) = offset;
382+
383+ // Reset key_probe with new values
384+ ConstContiguousRow row_key (&key_schema_, insert->decoded_op .row_data );
385+ insert->key_probe .reset (new tablet::RowSetKeyProbe (row_key));
386+ } else {
387+ // LOG(INFO) << "No col to replace with val: " << tx_state->op_id().ShortDebugString() << ":" << offset;
388+ }
389+
370390 ProbeStats stats;
371391
372392 // Submit the stats before returning from this function
@@ -495,16 +515,17 @@ void Tablet::StartApplying(WriteTransactionState* tx_state) {
495515
496516void Tablet::ApplyRowOperations (WriteTransactionState* tx_state) {
497517 StartApplying (tx_state);
498- for (RowOp* row_op : tx_state->row_ops ()) {
499- ApplyRowOperation (tx_state, row_op);
518+ for (int offset = 0 ; offset < tx_state->row_ops ().size (); offset++) {
519+ RowOp* row_op = tx_state->row_ops ()[offset];
520+ ApplyRowOperation (tx_state, row_op, offset);
500521 }
501522}
502523
503524void Tablet::ApplyRowOperation (WriteTransactionState* tx_state,
504- RowOp* row_op) {
525+ RowOp* row_op, int offset ) {
505526 switch (row_op->decoded_op .type ) {
506527 case RowOperationsPB::INSERT:
507- ignore_result (InsertUnlocked (tx_state, row_op));
528+ ignore_result (InsertUnlocked (tx_state, row_op, offset ));
508529 return ;
509530
510531 case RowOperationsPB::UPDATE:
0 commit comments