yuqi1129 commented on code in PR #4019:
URL: https://github.com/apache/gravitino/pull/4019#discussion_r1668479867
##########
core/src/main/java/com/datastrato/gravitino/tag/TagManager.java:
##########
@@ -36,32 +48,144 @@ public class TagManager {
private static final Logger LOG = LoggerFactory.getLogger(TagManager.class);
- public TagManager(IdGenerator idGenerator, EntityStore entityStore) {}
+ private final IdGenerator idGenerator;
+
+ private final EntityStore entityStore;
+
+ public TagManager(IdGenerator idGenerator, EntityStore entityStore) {
+ if (entityStore instanceof KvEntityStore) {
+ String errorMsg =
+ "TagManager cannot run with kv entity store, please configure the
entity "
+ + "store to use relational entity store and restart the
Gravitino server";
+ LOG.error(errorMsg);
+ throw new RuntimeException(errorMsg);
+ }
+
+ this.idGenerator = idGenerator;
+ this.entityStore = entityStore;
+ }
public String[] listTags(String metalake) {
- throw new UnsupportedOperationException("Not implemented yet");
+ return TreeLockUtils.doWithTreeLock(
+ NameIdentifier.of(ofTagNamespace(metalake).levels()),
+ LockType.READ,
+ () -> {
+ checkMetalakeExists(metalake, entityStore);
+
+ try {
+ return entityStore
+ .list(ofTagNamespace(metalake), TagEntity.class,
Entity.EntityType.TAG).stream()
+ .map(TagEntity::name)
+ .toArray(String[]::new);
+ } catch (IOException ioe) {
+ LOG.error("Failed to list tags", ioe);
+ throw new RuntimeException(ioe);
+ }
+ });
}
- public Tag[] listTagsInfo(String metalake, boolean extended) {
+ public MetadataObject[] listAssociatedMetadataObjectsForTag(String metalake,
String name) {
throw new UnsupportedOperationException("Not implemented yet");
}
public Tag createTag(String metalake, String name, String comment,
Map<String, String> properties)
throws TagAlreadyExistsException {
- throw new UnsupportedOperationException("Not implemented yet");
+ Map<String, String> tagProperties = properties == null ?
Collections.emptyMap() : properties;
+
+ return TreeLockUtils.doWithTreeLock(
+ NameIdentifier.of(ofTagNamespace(metalake).levels()),
+ LockType.WRITE,
+ () -> {
+ checkMetalakeExists(metalake, entityStore);
+
+ TagEntity tagEntity =
+ TagEntity.builder()
+ .withId(idGenerator.nextId())
+ .withName(name)
+ .withNamespace(ofTagNamespace(metalake))
+ .withComment(comment)
+ .withProperties(tagProperties)
+ .withAuditInfo(
+ AuditInfo.builder()
+
.withCreator(PrincipalUtils.getCurrentPrincipal().getName())
+ .withCreateTime(Instant.now())
+ .build())
+ .build();
+
+ try {
+ entityStore.put(tagEntity, false /* overwritten */);
+ return tagEntity;
+ } catch (EntityAlreadyExistsException e) {
+ throw new TagAlreadyExistsException(
+ "Tag with name %s under metalake %s already exists", name,
metalake);
+ } catch (IOException ioe) {
+ LOG.error("Failed to create tag", ioe);
Review Comment:
It's best to include name identification information in the log.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]