-
Notifications
You must be signed in to change notification settings - Fork 380
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
[#3607] feat(core): Support to import the entities when loading entities #3623
Conversation
9587cea
to
30b5053
Compare
From my point, I think:
|
|
I'm considering a point: is it necessary to expose the concept of when enterprises integrating Gravitino , there will be two phases
During the transitional state of migration, users request cannot yet converge on Gravitino, so we need to periodically import newly added When the migration is complete, all request will go through Gravitino, and at this point, "import" is no longer necessary. another thing, why don't we automatically check and insert metadata during the |
I ever had concern about the issue of the lock. |
ebf6696
to
20f57e5
Compare
219641e
to
d0910a7
Compare
@lw-yang @jerryshao Could you help me review this pull request? |
All comments are addressed. @jerryshao @yuqi1129 Could you take an another look? |
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.
Can you please carefully polish your code, I feel like that you didn't carefully check the behavior of each return value and the corner case. This makes me think that you don't have UTs to cover your different cases.
@@ -23,6 +24,9 @@ public final class EntityCombinedSchema implements Schema { | |||
|
|||
// Sets of properties that should be hidden from the user. | |||
private Set<String> hiddenProperties; | |||
// If imported is true, it means that storage backend have stored the correct entity. |
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.
Add a blank line above.
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.
@@ -272,6 +273,15 @@ boolean isManagedEntity(NameIdentifier catalogIdent, Capability.Scope scope) { | |||
IllegalArgumentException.class); | |||
} | |||
|
|||
boolean isEntityExist(NameIdentifier ident, Entity.EntityType type) { |
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.
Do you need thing method to be package private, or protected is enough?
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.
Package private is enough. It should keep consistent with other methods.
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.
I mean should protected
be enough?
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.
I changed to protected
. But other methods in this class are package public. I think this method should have the same visibility with other methods with the same class.
catalogIdentifier, | ||
HasPropertyMetadata::schemaPropertiesMetadata, | ||
schema.properties())); | ||
if (schema == null || schema.imported()) { |
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 method definition here will throw a NoSuchSchemaException
instead of returning null, you should follow this, the method definition doesn't return null, instead it throws an exception.
catalogIdentifier, | ||
HasPropertyMetadata::schemaPropertiesMetadata, | ||
schema.properties())); | ||
if (schema == null || schema.imported()) { |
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.
Again, do you really check that the code above will return null or throw an exception?
catalogIdentifier, | ||
HasPropertyMetadata::schemaPropertiesMetadata, | ||
schema.properties())); | ||
return schema; |
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.
Why do you return a schema
you got previously here, IIUC, should we return a schema after it is imported?
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.
If schema is imported, we don't need to import it again, so we can return it directly.
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.
No, what I mean is that you will have a new entity combined schema in importSchema()
, you should return the new one, not the old one. If you don't understand what I'm talking about, just ping me offline.
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.
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.
Has this comment been resolved? I have the same question, I think here should return EntityCombinedSchema
after import
.
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.
After digging into the code, the difference of schema
before and after import
is only about AuditInfo
, and since the imported entity
doesn't have the new AuditInfo
, so schema
is the same before and after import
, no need to create a new one. It is also the same for table and topic. @mchades .
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.
Got it. If there is no change in the auditInfo
then it is acceptable not to use imported EntityCombinedSchema
here.
@@ -330,4 +303,102 @@ public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmpty | |||
? droppedFromStore | |||
: droppedFromCatalog; | |||
} | |||
|
|||
private boolean importSchema(NameIdentifier identifier) { |
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.
You didn't leverage the return value of this method, so why do you need to define a return value?
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.
OK, Maybe I should add some logs.
} | ||
|
||
StringIdentifier stringId = getStringIdFromProperties(schema.properties()); | ||
// Case 1: The schema is not created by Gravitino. |
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.
You didn't update as what @yuqi1129 mentioned here.
ident, | ||
identifier -> store.get(identifier, SCHEMA, SchemaEntity.class), | ||
"GET", | ||
stringId.id()); |
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.
For entity store, it throws a NoSuchEntityException
instead of returning null. So the code below is not valid.
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.
operateOnEntity
will catch NoSuchEntityException
and return null.
core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/datastrato/gravitino/catalog/TableOperationDispatcher.java
Outdated
Show resolved
Hide resolved
@@ -24,6 +25,10 @@ public final class EntityCombinedSchema implements Schema { | |||
// Sets of properties that should be hidden from the user. | |||
private Set<String> hiddenProperties; |
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.
Perhaps we can handle this not in this PR, we may need a class named 'combinedEntity' to unify the handling of entities from different sources.
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.
@mchades what is the meaning here, can you explain more?
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.
I mean do we need to provide an abstract class CombinedEntity<T>
for EntityCombinedSchema
, EntityCombinedTable
, and EntityCombinedTopic
?
// Load the schema to make sure the schema is imported. | ||
SchemaDispatcher schemaDispatcher = GravitinoEnv.getInstance().schemaDispatcher(); | ||
NameIdentifier schemaIdent = NameIdentifier.of(ident.namespace().levels()); | ||
schemaDispatcher.loadSchema(schemaIdent); |
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.
It will produce an extra event of loadSchema
if we use the loadSchema instead of SchemaExists
. Is it expected?
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.
But using SchemaExists
seems a bit weird...
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.
OK.
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.
core/src/main/java/com/datastrato/gravitino/catalog/TableOperationDispatcher.java
Outdated
Show resolved
Hide resolved
Please review again. |
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
Overall LGTM |
… entities (apache#3623) ### What changes were proposed in this pull request? Support to import the entities when loading entities ### Why are the changes needed? Fix: apache#3607 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Add ut. --------- Co-authored-by: Heng Qin <[email protected]> Co-authored-by: Rory <[email protected]> Co-authored-by: Jerry Shao <[email protected]>
What changes were proposed in this pull request?
Support to import the entities when loading entities
Why are the changes needed?
Fix: #3607
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Add ut.