yuqi1129 commented on code in PR #15070:
URL: https://github.com/apache/gravitino/pull/15070#discussion_r4625578689


##########
core/src/main/java/org/apache/gravitino/glossary/GlossaryManager.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.glossary;
+
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.UUID;
+import javax.annotation.Nullable;
+import org.apache.gravitino.Entity.EntityType;
+import org.apache.gravitino.EntityAlreadyExistsException;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.exceptions.NoSuchTermException;
+import org.apache.gravitino.exceptions.TermAlreadyExistsException;
+import org.apache.gravitino.exceptions.TermVersionConflictException;
+import org.apache.gravitino.meta.GlossaryTermEntity;
+import org.apache.gravitino.storage.IdGenerator;
+import org.apache.gravitino.storage.relational.service.GlossaryTermMetaService;
+import org.apache.gravitino.storage.relational.service.OwnerMetaService;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** Manages live glossary definitions. Callers supply the metalake scope for 
every operation. */
+public final class GlossaryManager {
+  private final GlossaryTermMetaService terms = 
GlossaryTermMetaService.getInstance();
+  private final IdGenerator ids;
+  private final boolean authorizationEnabled;
+  private final TermChangeHandler handler;
+
+  /** Creates a manager that applies effective changes immediately. */
+  public GlossaryManager(IdGenerator ids, boolean authorizationEnabled) {
+    this(ids, authorizationEnabled, (before, after, persist) -> persist.run());
+  }
+
+  GlossaryManager(IdGenerator ids, boolean authorizationEnabled, 
TermChangeHandler handler) {
+    this.ids = ids;
+    this.authorizationEnabled = authorizationEnabled;
+    this.handler = handler;
+  }
+
+  /** Lists term definitions in the given metalake. */
+  public List<GlossaryTermEntity> listTerms(String metalake) {
+    return terms.list(NamespaceUtil.ofGlossaryTerm(metalake));
+  }
+
+  /** Loads a definition by normalized name. */
+  public GlossaryTermEntity getTerm(String metalake, String name) {
+    NameIdentifier ident = 
NameIdentifier.of(NamespaceUtil.ofGlossaryTerm(metalake), name);
+    try {
+      return terms.get(ident);
+    } catch (NoSuchEntityException e) {
+      throw new NoSuchTermException(e, "Term %s does not exist", ident);
+    }
+  }
+
+  /** Creates one live definition and assigns its creator as owner when 
authorization is enabled. */
+  public GlossaryTermEntity createTerm(String metalake, TermSpec spec) {
+    Namespace ns = NamespaceUtil.ofGlossaryTerm(metalake);
+    GlossaryTermEntity term = TermEdits.create(ids.nextId(), ns, spec);
+    return terms.withHierarchyLock(
+        ns,
+        () -> {
+          terms.checkTermNames(term);
+          handler.handle(
+              null,
+              term,
+              () -> {
+                try {
+                  terms.insert(term, false);
+                } catch (EntityAlreadyExistsException e) {
+                  throw new TermAlreadyExistsException(
+                      e, "Term name or source reference already exists");
+                } catch (IOException e) {
+                  throw new UncheckedIOException(e);
+                }
+                if (authorizationEnabled) {
+                  OwnerMetaService.getInstance()

Review Comment:
   Clarified the T6 acceptance criteria in 46e630c218: glossary owner decisions 
read the current identity and owner from storage. Post-commit invalidation 
applies if another shared-authorizer consumer caches those mappings. The 
cross-node drop/recreate check stays in T6. Leaving this thread open for 
agreement on that integration boundary.



-- 
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]

Reply via email to