-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Improve](Tablet Schema) Use deterministic way to serialize protobuf … #30906
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,9 @@ class TabletSchema { | |
| // void create_from_pb(const TabletSchemaPB& schema, TabletSchema* tablet_schema). | ||
| TabletSchema() = default; | ||
| void init_from_pb(const TabletSchemaPB& schema, bool ignore_extracted_columns = false); | ||
| // Notice: Use deterministic way to serialize protobuf, | ||
| // since serialize Map in protobuf may could lead to un-deterministic by default | ||
| static std::string deterministic_string_serialize(const TabletSchemaPB& schema_pb); | ||
| void to_schema_pb(TabletSchemaPB* tablet_meta_pb) const; | ||
| void append_column(TabletColumn column, ColumnType col_type = ColumnType::NORMAL); | ||
| void append_index(TabletIndex index); | ||
|
|
@@ -363,17 +366,17 @@ class TabletSchema { | |
| // Dump [(name, type, is_nullable), ...] | ||
| string dump_structure() const { | ||
| string str = "["; | ||
| for (auto p : _field_name_to_index) { | ||
| for (auto p : _cols) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why change this code?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (str.size() > 1) { | ||
| str += ", "; | ||
| } | ||
| str += "("; | ||
| str += p.first; | ||
| str += p.name(); | ||
| str += ", "; | ||
| str += TabletColumn::get_string_by_field_type(_cols[p.second].type()); | ||
| str += TabletColumn::get_string_by_field_type(p.type()); | ||
| str += ", "; | ||
| str += "is_nullable:"; | ||
| str += (_cols[p.second].is_nullable() ? "true" : "false"); | ||
| str += (p.is_nullable() ? "true" : "false"); | ||
| str += ")"; | ||
| } | ||
| str += "]"; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are you sure the deterministic serialize will take affect on map value?
void CodedOutputStream::SetSerializationDeterministic(
bool value)
Indicate to the serializer whether the user wants derministic serialization.
The default when this is not called comes from the global default, controlled by SetDefaultSerializationDeterministic.
What deterministic serialization means is entirely up to the driver of the serialization process (i.e. the caller of methods like WriteVarint32). In the case of serializing a proto buffer message using one of the methods of MessageLite, this means that for a given binary equal messages will always be serialized to the same bytes. This implies:
Repeated serialization of a message will return the same bytes.
Different processes running the same binary (including on different
machines) will serialize equal messages to the same bytes.
Note that this is not canonical across languages. It is also unstable across different builds with intervening message definition changes, due to unknown fields. Users who need canonical serialization (e.g. persistent storage in a canonical form, fingerprinting) should define their own canonicalization specification and implement the serializer using reflection APIs rather than relying on this API.
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.
Yes , map serialization is none deterministic by default, and
SetSerializationDeterministicto true will make it deterministic.From the document aboveThis means that for a given binary equal messages will always be serialized to the same bytes.I've also tested and it's deterministic as expected