@Override
 public DatasetSpecification configure(String instanceName, DatasetProperties properties) {
   return DatasetSpecification.builder(instanceName, getName())
       .properties(properties.getProperties())
       .datasets(tableDef.configure("key-value-table", properties))
       .build();
 }
Ejemplo n.º 2
0
 /**
  * Creates properties for {@link Table} or {@link Table} data set instance.
  *
  * @param level level on which to detect conflicts in changes made by different transactions
  * @param ttl time to live for data written into a table, in ms. {@link #NO_TTL} means unlimited
  * @return {@link DatasetProperties} for the data set
  */
 public static DatasetProperties tableProperties(
     ConflictDetection level, int ttl, DatasetProperties props) {
   return DatasetProperties.builder()
       .add(Table.PROPERTY_CONFLICT_LEVEL, level.name())
       .add(Table.PROPERTY_TTL, ttl)
       .addAll(props.getProperties())
       .build();
 }
Ejemplo n.º 3
0
  @Test
  public void testTTL() throws Exception {
    // for the purpose of this test it is fine not to configure ttl when creating table: we want to
    // see if it
    // applies on reading
    int ttl = 1000;
    String ttlTable = "ttl";
    String noTtlTable = "nottl";
    DatasetProperties props =
        DatasetProperties.builder().add(Table.PROPERTY_TTL, String.valueOf(ttl)).build();
    getTableAdmin(CONTEXT1, ttlTable, props).create();
    DatasetSpecification ttlTableSpec =
        DatasetSpecification.builder(ttlTable, HBaseTable.class.getName())
            .properties(props.getProperties())
            .build();
    HBaseTable table =
        new HBaseTable(CONTEXT1, ttlTableSpec, cConf, testHBase.getConfiguration(), hBaseTableUtil);

    DetachedTxSystemClient txSystemClient = new DetachedTxSystemClient();
    Transaction tx = txSystemClient.startShort();
    table.startTx(tx);
    table.put(b("row1"), b("col1"), b("val1"));
    table.commitTx();

    TimeUnit.SECONDS.sleep(2);

    tx = txSystemClient.startShort();
    table.startTx(tx);
    table.put(b("row2"), b("col2"), b("val2"));
    table.commitTx();

    // now, we should not see first as it should have expired, but see the last one
    tx = txSystemClient.startShort();
    table.startTx(tx);
    byte[] val = table.get(b("row1"), b("col1"));
    if (val != null) {
      LOG.info("Unexpected value " + Bytes.toStringBinary(val));
    }
    Assert.assertNull(val);
    Assert.assertArrayEquals(b("val2"), table.get(b("row2"), b("col2")));

    // test a table with no TTL
    DatasetProperties props2 =
        DatasetProperties.builder().add(Table.PROPERTY_TTL, String.valueOf(Tables.NO_TTL)).build();
    getTableAdmin(CONTEXT1, noTtlTable, props2).create();
    DatasetSpecification noTtlTableSpec =
        DatasetSpecification.builder(noTtlTable, HBaseTable.class.getName())
            .properties(props2.getProperties())
            .build();
    HBaseTable table2 =
        new HBaseTable(
            CONTEXT1, noTtlTableSpec, cConf, testHBase.getConfiguration(), hBaseTableUtil);

    tx = txSystemClient.startShort();
    table2.startTx(tx);
    table2.put(b("row1"), b("col1"), b("val1"));
    table2.commitTx();

    TimeUnit.SECONDS.sleep(2);

    tx = txSystemClient.startShort();
    table2.startTx(tx);
    table2.put(b("row2"), b("col2"), b("val2"));
    table2.commitTx();

    // if ttl is -1 (unlimited), it should see both
    tx = txSystemClient.startShort();
    table2.startTx(tx);
    Assert.assertArrayEquals(b("val1"), table2.get(b("row1"), b("col1")));
    Assert.assertArrayEquals(b("val2"), table2.get(b("row2"), b("col2")));
  }