question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CheckAndMutate uses timestamps inconsistently

See original GitHub issue

Steps to reproduce

  @Test
  void testCantReadMyOwnWrites() throws IOException {
    Table table = // TODO
    byte[] row = Bytes.toBytes(System.currentTimeMillis());
    byte[] q = Bytes.toBytes("q");
    byte[] f = Bytes.toBytes("f");
    byte[] A = Bytes.toBytes("aaa");
    byte[] B = Bytes.toBytes("bbb");

    boolean success = table
        .checkAndMutate(row, f).qualifier(q).ifNotExists()
        .thenPut(new Put(row).addColumn(f, q, A));
    assertThat(success).isTrue();
    table.put(new Put(row).addColumn(f, q, B));
    byte[] value = table.get(new Get(row)).getValue(f, q);
    assertThat(value).isEqualTo(B); // 👈  this fails
  }

This (generally) works when setting a breakpoint on table.put(new Put(row).addColumn(f, q, B)); - i.e. slowing down the operation with the breakpoint seems to “fix” it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
aditanasecommented, Mar 25, 2021

@kolea2 excellent feedback, thank you for the additional testing!

1reaction
kolea2commented, Mar 22, 2021

Hi @aditanase - the Put call in HBase without a timestamp passed in will use the existing timestamp, see https://github.com/apache/hbase/blob/master/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java#L179, so I do not believe that will not work as is, as the existing timestamp will end up being the server side timestamp. I believe calling setTimestamp first will work. Here’s what I tried:

Example using setTimestamp last with custom timestamp:

Timestamp timestamp = new Timestamp(11111111);
            Put put = new Put(row)
                    .addColumn(f, q, A)
                    .addColumn(f, q2, B)
                    .setTimestamp(timestamp.getTime());
            boolean success = table
                    .checkAndMutate(row, f).qualifier(q).ifNotExists()
                    .thenPut(put);
            Assert.assertTrue(success);

Output (via cbt tool). Custom timestamp ignored:

xZ?6
  cf:q                                     @ 2021/03/22-13:07:13.094000
    "aaa"
  cf:q2                                    @ 2021/03/22-13:07:13.094000
    "bbb"

Example using custom timestamp first:

Timestamp timestamp = new Timestamp(11111111);
            Put put = new Put(row)
                    .setTimestamp(timestamp.getTime())
                    .addColumn(f, q, A)
                    .addColumn(f, q2, B);
            boolean success = table
                    .checkAndMutate(row, f).qualifier(q).ifNotExists()
                    .thenPut(put);
            Assert.assertTrue(success);

Output:

xZ?2
  cf:q                                     @ 1969/12/31-22:05:11.111000
    "aaa"
  cf:q2                                    @ 1969/12/31-22:05:11.111000
    "bbb"

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CheckAndMutate methods should not set client-side timestamps
If a user doesn't set timestamps, Put operations get client-side timestamps. ... CheckAndMutate uses timestamps inconsistently #2898.
Read more >
Issues Fixed in CDH 5.3.x | 5.x - Cloudera Documentation
If the connection with ZooKeeper is inconsistent, the ReplicationCleaner may abort, and the following event is logged by the HMaster:
Read more >
The HBase CheckAndMutate is atomic is it also consistent?
Let's say I have: a cell with value 5. 2 workers simultaneously want to change the value of the cell (using checkAndMutate )...
Read more >
Ensuring transactional consistency with DDD
We use Entity Framework and EF6 uses read_commited_snapshot by default, so two consecutive reads from repository can give us inconsistent ...
Read more >
The Definitive Guide, 2nd Edition HBase Guide Second Early ...
The architecture used underneath is well researched and has not changed ... the time where the cache and the database views are inconsistent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found