Esempio n. 1
0
  @Test(timeout = 100000)
  public void testBatchWithSameRow() throws Exception {
    String tableName = TABLE_NAME_PREFIX + "-testBatchWithSameRow";
    table = createTable(tableName, basicSchema, new CreateTableOptions());

    KuduSession session = syncClient.newSession();
    session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);

    // Insert 25 rows, one per batch, along with 50 updates for each, and a delete at the end,
    // while also clearing the cache between each batch half the time. The delete is added here
    // so that a misplaced update would fail if it happens later than its delete.
    for (int i = 0; i < 25; i++) {
      session.apply(createInsert(i));
      for (int j = 0; j < 50; j++) {
        Update update = table.newUpdate();
        PartialRow row = update.getRow();
        row.addInt(basicSchema.getColumnByIndex(0).getName(), i);
        row.addInt(basicSchema.getColumnByIndex(1).getName(), 1000);
        session.apply(update);
      }
      Delete del = table.newDelete();
      PartialRow row = del.getRow();
      row.addInt(basicSchema.getColumnByIndex(0).getName(), i);
      session.apply(del);
      session.flush();
      if (i % 2 == 0) {
        client.emptyTabletsCacheForTable(table.getTableId());
      }
    }
    assertEquals(0, countRowsInScan(client.newScannerBuilder(table).build()));
  }
Esempio n. 2
0
  /**
   * 执行插入更新操作
   *
   * @param tablename
   * @param mid
   * @param fieldsValue
   */
  private void insertUpdate(String tablename, String mid, String[] fieldsValue) {

    checkSession();

    KuduTable table;
    if (Constants.UPUSERS_ATTR_TABLE.equals(tablename)) {
      table = table_attr;
    } else {
      table = table_days;
    }
    try {
      Insert insert = table.newInsert();
      PartialRow row = insert.getRow();
      setInsertValue(mid, Constants.ATTR_INSERT_FIELDS, fieldsValue, row);
      OperationResponse rsInsert = session.apply(insert);
      if (rsInsert.hasRowError()) {
        if ("key already present".equals(rsInsert.getRowError().getMessage())) {
          Update update = table.newUpdate();
          PartialRow urow = update.getRow();
          setUpdateValue(mid, Constants.ATTR_UPDATE_FIELDS, fieldsValue, urow);
          OperationResponse rsUpdate = session.apply(update);
          if (rsUpdate.hasRowError()) {
            System.out.println(
                "=======================================ERROR UPDATE :" + rsUpdate.getRowError());
          } else {
            System.out.println(
                "=======================================UPDATE DATA:"
                    + mid
                    + ":"
                    + Arrays.toString(fieldsValue));
          }
        } else {
          System.out.println(
              "=======================================ERROR INSERT :" + rsInsert.getRowError());
        }
      } else {
        System.out.println(
            "=======================================INSERT DATA:"
                + mid
                + ":"
                + Arrays.toString(fieldsValue));
      }
    } catch (Exception e) {
      collector.reportError(e);
    }
  }