Skip to content

Commit c300973

Browse files
committed
WIP Kudu queue hack
1 parent 5489476 commit c300973

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/kudu/tablet/tablet.cc

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void Tablet::StartTransaction(WriteTransactionState* tx_state) {
357357
}
358358

359359
Status 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

496516
void 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

503524
void 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:

src/kudu/tablet/tablet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Tablet {
182182
// Apply a single row operation, which must already be prepared.
183183
// The result is set back into row_op->result
184184
void ApplyRowOperation(WriteTransactionState* tx_state,
185-
RowOp* row_op);
185+
RowOp* row_op, int offset);
186186

187187
// Create a new row iterator which yields the rows as of the current MVCC
188188
// state of this tablet.
@@ -382,7 +382,7 @@ class Tablet {
382382
// they were already acquired. Requires that handles for the relevant locks
383383
// and MVCC transaction are present in the transaction state.
384384
Status InsertUnlocked(WriteTransactionState *tx_state,
385-
RowOp* insert);
385+
RowOp* insert, int offset);
386386

387387
// A version of MutateRow that does not acquire locks and instead assumes
388388
// they were already acquired. Requires that handles for the relevant locks

src/kudu/tablet/tablet_bootstrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ Status TabletBootstrap::FilterAndApplyOperations(WriteTransactionState* tx_state
13241324
}
13251325

13261326
// Actually apply it.
1327-
tablet_->ApplyRowOperation(tx_state, op);
1327+
tablet_->ApplyRowOperation(tx_state, op, op_idx - 1);
13281328
DCHECK(op->result != NULL);
13291329

13301330
// We expect that the above Apply() will always succeed, because we're

0 commit comments

Comments
 (0)