APIs used

These APIs are defined in the header file mutations.h:

  • hb_put_create(): Creates a structure for the put operation and returns its handle.
  • hb_mutation_set_table(): Sets the table name for the mutation.
  • hb_put_add_cell(): Adds a cell to the put structure. The row key of the cell must be the same as the row key of the put structure.
  • hb_mutation_send(): Queues the put operation for sending to the server. Mutations are not performed atomically and can be batched in a non-deterministic way on either the client side or the server side. Any buffer attached to a mutation object (put or delete) must not be altered until the callback has been received.

Sequence of steps

  1. Create a row object named row_data.
  2. Create a put object.
  3. Specify the name of the table.
  4. Create cell data for the first cell.
  5. Create the first cell.
  6. Add the data to the cell, using a later timestamp than in the previous operation.
  7. Add the first cell to the row.
  8. Queue the put.
  9. Wait 3 seconds, flush the queue, and wait for the RPC calls to complete.

Code

  // now, let's put second version in one column
  outstanding_puts_count++;
  {
    row_data_t *row_data = (row_data_t *) calloc(1, sizeof(row_data_t));
    row_data->key = bytebuffer_printf("row_with_two_cells");
    hb_put_create(row_data->key->buffer, row_data->key->length, &put);
    hb_mutation_set_table(put, table_name, table_name_len);
    hb_mutation_set_durability(put, DURABILITY_SYNC_WAL);
 
    // first cell
    cell_data_t *cell1_data = new_cell_data();
    row_data->first_cell = cell1_data;
    cell1_data->value = bytebuffer_printf("cell1_value_v2");
 
    hb_cell_t *cell1 = (hb_cell_t*) calloc(1, sizeof(hb_cell_t));
    cell1_data->hb_cell = cell1;
 
    cell1->row = row_data->key->buffer;
    cell1->row_len = row_data->key->length;
    cell1->family = FAMILIES[0];
    cell1->family_len = 1;
    cell1->qualifier = column_a->buffer;
    cell1->qualifier_len = column_a->length;
    cell1->value = cell1_data->value->buffer;
    cell1->value_len = cell1_data->value->length;
    cell1->ts = 1392222222222L;
    hb_put_add_cell(put, cell1);
 
    HBASE_LOG_INFO("Sending row with row key : '%.*s'.",
                   cell1->row_len, cell1->row);
    hb_mutation_send(client, put, put_callback, row_data);
    wait_for_puts();
  }