jerryshao commented on code in PR #15096: URL: https://github.com/apache/gravitino/pull/15096#discussion_r4689674591
########## api/src/main/java/org/apache/gravitino/kb/KnowledgeBaseArticleOperations.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.kb; + +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.exceptions.KnowledgeBaseArticleAlreadyExistsException; +import org.apache.gravitino.exceptions.KnowledgeBaseArticleVersionConflictException; +import org.apache.gravitino.exceptions.NoSuchKnowledgeBaseArticleException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** + * Metalake-scoped operations on Knowledge Base Articles and their asset bindings. + * + * <p>Page visible results before returning them. Page sizes range from 1 through {@value + * ArticleListFilter#MAX_LIMIT}; offsets are zero-based and nonnegative. + */ +@Evolving +public interface KnowledgeBaseArticleOperations { + + /** + * Lists visible summaries matching the filter. Set {@link ArticlePage#hasMore()} when an + * additional readable match follows the requested page. + * + * @param filter the list filter + * @return one page of matching articles + * @throws NoSuchMetalakeException if the metalake does not exist + */ + ArticlePage listArticles(ArticleListFilter filter) throws NoSuchMetalakeException; + + /** + * Loads an article by name. + * + * @param name the article name + * @return the article + * @throws NoSuchKnowledgeBaseArticleException if the article does not exist or is invisible to + * the caller + */ + default KnowledgeBaseArticle loadArticle(String name) throws NoSuchKnowledgeBaseArticleException { + return loadArticle(name, ArticleListFilter.DEFAULT_LIMIT, 0); + } + + /** + * Loads current content and a visible binding preview from the same revision. + * + * @param name the article name + * @param limit maximum preview size + * @param offset number of visible bindings to skip + * @return the article with the requested preview + */ + KnowledgeBaseArticle loadArticle(String name, int limit, int offset) + throws NoSuchKnowledgeBaseArticleException; + + /** + * Creates an article with current content, Domains and initial bindings. + * + * @param articleCreate the create request + * @return the created article + * @throws KnowledgeBaseArticleAlreadyExistsException if the explicit name is already used, or the + * title is already claimed in the same title-uniqueness scope + */ + KnowledgeBaseArticle createArticle(ArticleCreate articleCreate) + throws KnowledgeBaseArticleAlreadyExistsException; + + /** + * Applies a set of changes to an article atomically. A failure leaves all fields and bindings + * unchanged. + * + * @param name the article name + * @param changes the changes to apply + * @return the altered article + * @throws NoSuchKnowledgeBaseArticleException if the article does not exist + * @throws KnowledgeBaseArticleAlreadyExistsException if the title is already claimed in a + * requested Domain or the default scope + * @throws KnowledgeBaseArticleVersionConflictException if a concurrent update to the same article + * was detected + */ + KnowledgeBaseArticle alterArticle(String name, KnowledgeBaseArticleChange... changes) Review Comment: [P1] When two clients load an article and save sequentially, this signature cannot carry the second client's expected revision, and KnowledgeBaseArticle exposes no token to retain from the read. The merged [design #15067](https://github.com/apache/gravitino/pull/15067) explicitly includes revision tokens and conditional alters in T1. Please expose the token and add an alter overload/request that accepts optional expectedRevision, with contract coverage for passing it through. A conflict exception alone does not provide stale-edit protection. ########## api/src/main/java/org/apache/gravitino/kb/KnowledgeBaseArticle.java: ########## @@ -0,0 +1,136 @@ +/* + * 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.kb; + +import com.google.common.base.Preconditions; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.gravitino.Audit; +import org.apache.gravitino.Auditable; +import org.apache.gravitino.annotation.Evolving; + +/** A metalake-scoped article with current rich-text content, Domain membership and bindings. */ +@Evolving +public interface KnowledgeBaseArticle extends Auditable { + + /** + * Validates an explicit article name and returns its NFC spelling for storage and lookup. + * + * @param name the article name + * @return the normalized article name + */ + static String normalizeName(String name) { + return ArticleValidation.name(Preconditions.checkNotNull(name, "name")); + } + + /** Maximum length of the immutable article name. */ + int NAME_MAX_LENGTH = 128; + + /** Maximum length of the title. */ + int TITLE_MAX_LENGTH = 512; + + /** Maximum length of the short comment. */ + int COMMENT_MAX_LENGTH = 256; + + /** Maximum length of one synonym. */ + int SYNONYM_MAX_LENGTH = 128; + + /** Maximum number of synonyms of one article. */ + int SYNONYMS_MAX_COUNT = 20; + + /** Maximum length of the source reference. */ + int SOURCE_REFERENCE_MAX_LENGTH = 1024; + + /** + * The default maximum body size in UTF-8 bytes (1 MiB). The size is enforced by the server at + * write time; this API does not check the body size. + */ + long DEFAULT_MAX_BODY_BYTES = 1L << 20; + + /** + * The configurable maximum body size, the MySQL {@code MEDIUMTEXT} capacity. The size is enforced + * by the server at write time; this API does not check the body size. + */ + long MAX_BODY_BYTES_LIMIT = 16_777_215L; + + /** + * @return the immutable article name, unique within the metalake + */ + String name(); + + /** + * @return the display title, unique among active articles in each directly assigned Domain, or in Review Comment: [P2] Two differently named articles titled 'Revenue Guide' in the same Domain are allowed by the merged [design #15067](https://github.com/apache/gravitino/pull/15067), but this contract requires rejecting them. Please remove the title-uniqueness requirement here and the corresponding title-conflict documentation in createArticle, alterArticle, and KnowledgeBaseArticleAlreadyExistsException so downstream implementations preserve the agreed behavior. -- 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]
