-
Notifications
You must be signed in to change notification settings - Fork 304
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
[#305][#306] improvement(core): Adjust id name mapping to support true deletion and modification of entities #309
Conversation
Code Coverage Report
Files
|
You'd better add more tests to cover different scenarios. |
api/src/main/java/com/datastrato/graviton/exceptions/SubEntitiesNoEmptyException.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/datastrato/graviton/storage/EntityKeyEncoder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/datastrato/graviton/storage/EntityKeyEncoder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/datastrato/graviton/storage/EntityKeyEncoder.java
Outdated
Show resolved
Hide resolved
* @return | ||
* @throws IOException | ||
*/ | ||
String generateIdNameMappingKey(NameIdentifier nameIdentifier) throws IOException; |
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.
should it be exposed to the outside uers?
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.
generateIdNameMappingKey
was called by KvEntityStore
temporarily. So what you mean outside users?
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 other classes that use this EntityKeyEncoder
.
Basically, I think exposing this method looks a little odd to me, as this seems should not be known by the users.
Besides, the name of this method and below are confused.
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, Let me see
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 was going to move this to NameMappingService
interface, but it's a method that's strongly associated with kv, and it didn't seem right to move it to that interface.
So I also move it to KvEntityStore
, can you give some advice?
* @return | ||
* @throws IOException | ||
*/ | ||
List<T> encodeSubEntityPrefix(NameIdentifier identifier, EntityType type) throws IOException; |
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.
should it be exposed to the outside users?
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.
basically, what's the meaning of this method, the doc written here is confused.
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.
basically, what's the meaning of this method, the doc written here is confused.
I want to get the prefix of all sub-entities of an entities with the name identifier
. E.g., Assuming the id of a metalake is 1
, then prefix of all sub-entities (catalog, schema, table) are:
ca_{metalake_id} is the prefix a catalog entity in metalake 1
sc_{metalake_id} is the prefix a schema entity in metalake 1
ta_{metalake_id} is the prefix a table entity in metalake 1
should it be exposed to the outside users?
KvEntityStore
needs this function to remove all sub-entities
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 we redesign the interface to not expose so many details to the classes who use this.
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.
Method encodeSubEntityPrefix
seems to be closely related with KV Implementation(Get all prefix), So I move this to KvEntityStore
core/src/main/java/com/datastrato/graviton/storage/kv/BinaryEntityKeyEncoder.java
Show resolved
Hide resolved
if (subEntityPrefix.isEmpty()) { | ||
// has no sub-entities | ||
return backend.delete(dataKey); | ||
} |
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 don't you delete name-id mappings also?
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 think we do not need to remove name-id mapping eagerly for the following reasons:
- name-id mappings can be reused later
- name-id mappings can be deleted offline for better performance
catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java
Show resolved
Hide resolved
core/src/main/java/com/datastrato/graviton/proto/TableEntitySerde.java
Outdated
Show resolved
Hide resolved
*/ | ||
private byte[] encodeEntity(NameIdentifier identifier, EntityType entityType) throws IOException { | ||
private byte[] encodeEntity( | ||
NameIdentifier identifier, EntityType entityType, boolean returnNullIfEntityNotFound) |
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.
We'd also change the name "returnNullIfEntityNotFound" to be short
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.
changed
generateIdNameMappingKey(ident), generateIdNameMappingKey(updatedE.nameIdentifier())); | ||
|
||
// Update the entity to store | ||
backend.put(key, serDe.serialize(updatedE), true); |
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 don't we directly call put
?
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 scenario is changing the name of entity
and the key already exists, so we should use overwrite
option. If we use put without overwrite, a AlreadyExistsException
will be thrown.
return StringUtils.isBlank(context) ? name : context + NAMESPACE_SEPARATOR + name; | ||
} | ||
|
||
public String generateIdNameMappingKey(NameIdentifier nameIdentifier) throws IOException { |
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.
generateIdNameMappingKey
and generateKeyForNameMapping
these two names are a bit long and confused, can you simplify the name?
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.
changed
You need to update the rfc-2 markdown file also. |
What changes were proposed in this pull request?
We change the key of name-id mapping pairs.
Why are the changes needed?
Current name-id mapping contains no namespace information and can hardly handle the following scenarios:
Fix: #305 #306
Does this PR introduce any user-facing change?
No
How was this patch tested?
Existing UTs can cover this change.