-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-32139][connector/hbase] Using strongly increasing nanosecond timestamp and DeleteColumn type to fix data accidental deletion and non deletion issues when sink hbase. #22612
Conversation
...-hbase-base/src/main/java/org/apache/flink/connector/hbase/util/HBaseTimestampGenerator.java
Outdated
Show resolved
Hide resolved
for (int i = 0; i < 100_000_000; i++) { | ||
long now = timestampGenerator.get(); | ||
if (lastTimestamp > 0) { | ||
assertTrue(lastTimestamp < now); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use 'now > lastTimestamp' as assertion condition to explicitly show that timestamp is increasing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good advice
} | ||
final long realNow = timestampGenerator.getCurrentSystemTimeNano(); | ||
final long diff = lastTimestamp - realNow; | ||
assertTrue("Should no timestamp diff in 100 billion tests", diff <= 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
billion → million
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
final long diff = lastTimestamp - realNow; | ||
assertTrue("Should no timestamp diff in 100 billion tests", diff <= 0); | ||
LOG.info( | ||
"timestamp diff of 100 billion tests in nanosecond: {} (use {}, real {})", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
billion → million
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lastTimestamp = now; | ||
} | ||
final long realNow = timestampGenerator.getCurrentSystemTimeNano(); | ||
final long diff = lastTimestamp - realNow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use 'realNow - lastTimestamp' to explicitly show that the timestamp is increasing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea
…DeleteColumn type to fix data accidental deletion and non deletion issues when sink hbase.
a234181
to
fe2ef22
Compare
Also, it is recommended that you add test cases to verify this HBase data loss issue is completely fixed with this solution. |
public void testStronglyIncreasingTimestampGenerator() { | ||
HBaseTimestampGenerator timestampGenerator = HBaseTimestampGenerator.stronglyIncreasing(); | ||
long lastTimestamp = 0; | ||
for (int i = 0; i < 100_000_000; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing - Having a test run 100 million times isn't an effective test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing - Having a test run 100 million times isn't an effective test
@MartijnVisser
Thank you for your review and valuable feedback. I think I may need to use Junit5 to write test cases, and change 100 million times tests to one times。Can you give more suggestions on how to write this test?
Actually, I have another question. How to write test cases for the probability of errors occurring in this data loss situation, as we cannot assert a definite state ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution logic itself LGTM. Agree what other reviewers mentions about the tests. Added 1 more comment.
package org.apache.flink.connector.hbase.util; | ||
|
||
/** Generate timestamp for HBase mutation. */ | ||
public abstract class HBaseTimestampGenerator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance we will have another implementation for this class in the future? Even if yes, I think we can introduce the extra abstraction layer when it will be necessary. For now, a simple class, e.g. StronglyIncreasingTsGenerator
with 1 public method that returns the ts would be enough, resulting a simpler and cleaner solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance we will have another implementation for this class in the future? Even if yes, I think we can introduce the extra abstraction layer when it will be necessary. For now, a simple class, e.g.
StronglyIncreasingTsGenerator
with 1 public method that returns the ts would be enough, resulting a simpler and cleaner solution.
Thank you for your feedback. I will make some modifications according to your suggestion.
@flinkbot run azure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for incorporating the requested changes!
Hi @MartijnVisser , thanks for the reviewing and merging. A friendly reminder: Please note the squish commit before merging and the commit message should start with [FLINK-JIRA_ID], thanks~ |
Hi @1996fanrui - Yeah I made a mistake, there's unfortunately nothing I can do to repair that situation :( |
What is the purpose of the change
Using strongly increasing nanosecond timestamp and DeleteColumn type to fix data accidental deletion and non deletion issues when sink upsert data to hbase.
https://issues.apache.org/jira/browse/FLINK-32139
Brief change log
Verifying this change
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: noDocumentation