Skip to content
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

BugFix: Fixed an issue where JDBC OceanBaseSink might cause data loss in non-primary key tables #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yuanoOo
Copy link
Member

@yuanoOo yuanoOo commented Dec 12, 2024

Summary

fix #109

Solution Description

@yuanoOo yuanoOo changed the title BugFix: Fixed the issue that JDBC OceanBaseSink non-primary key table may cause data loss BugFix: Fixed an issue where JDBC OceanBaseSink might cause data loss in non-primary key tables Dec 12, 2024
@yuanoOo yuanoOo requested a review from whhe December 12, 2024 03:36
keys -> {
Object[] array =
keys.stream().map(record::getFieldValue).toArray();
if (array.length == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's it for? The process should directly go to orElse if the record is from a non-pk table,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object key = keyExtractor.extract(dataChangeRecord);
if (key == null) {
synchronized (buffer) {
buffer.computeIfAbsent(record.getTableId().identifier(), k -> new ArrayList<>())
.add(dataChangeRecord);
}
} else {
synchronized (reducedBuffer) {
reducedBuffer
.computeIfAbsent(record.getTableId().identifier(), k -> new HashMap<>())
.put(key, dataChangeRecord);
}
}

  • If record.getTable().getKey() is an empty but not null primary key List, this KeyExtractor.simple() will return an empty DataChangeRecord object but not NULL
  • Then line 133 of the code block above will return false, causing the non-primary key table to be mistakenly treated as the primary key table.
        static KeyExtractor simple() {
            return record ->
                    // when record.getTable().getKey() is empty List
                    Optional.ofNullable(record.getTable().getKey())
                            .map(
                                    keys ->
                                            new DataChangeRecordData(
                                                    keys.stream()
                                                            .map(record::getFieldValue)
                                                            .toArray()))
                            .orElse(null);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: JDBC OceanBaseSink may cause data loss for non-primary key tables.
2 participants