-
Notifications
You must be signed in to change notification settings - Fork 809
feat(cache): add updated_at columns and auth mapper operations for version-validated caching #10793
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
Open
yuqi1129
wants to merge
7
commits into
apache:branch-cache-improvement
Choose a base branch
from
yuqi1129:feat/cache-db-schema-mapper
base: branch-cache-improvement
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dd6c855
feat(cache): add updated_at columns, entity_change_log, and auth mapp…
yuqi1129 290512e
feat(cache): wire touchUpdatedAt and entity_change_log into all MetaS…
yuqi1129 c7bb7c8
fix
yuqi1129 e94d747
fix
yuqi1129 d9e3898
fix(cache): use subquery for PostgreSQL DELETE with LIMIT in entity_c…
yuqi1129 7cd47c9
Fix
yuqi1129 4ef8393
Merge branch 'branch-cache-improvement' into feat/cache-db-schema-mapper
yuqi1129 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/main/java/org/apache/gravitino/storage/relational/mapper/EntityChangeLogMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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.storage.relational.mapper; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.gravitino.storage.relational.po.auth.EntityChangeRecord; | ||
| import org.apache.ibatis.annotations.DeleteProvider; | ||
| import org.apache.ibatis.annotations.InsertProvider; | ||
| import org.apache.ibatis.annotations.Param; | ||
| import org.apache.ibatis.annotations.SelectProvider; | ||
|
|
||
| /** | ||
| * A MyBatis Mapper for entity_change_log table operations. | ||
| * | ||
| * <p>This append-only log tracks structural changes to entities (create, alter, drop) and is used | ||
| * by the entity change poller to drive targeted invalidation of the metadataIdCache on HA peer | ||
| * nodes. | ||
| */ | ||
| public interface EntityChangeLogMapper { | ||
|
|
||
| String ENTITY_CHANGE_LOG_TABLE_NAME = "entity_change_log"; | ||
|
|
||
| @SelectProvider(type = EntityChangeLogSQLProviderFactory.class, method = "selectEntityChanges") | ||
| List<EntityChangeRecord> selectChanges( | ||
| @Param("createdAtAfter") long createdAtAfter, @Param("maxRows") int maxRows); | ||
|
|
||
| @InsertProvider(type = EntityChangeLogSQLProviderFactory.class, method = "insertEntityChange") | ||
| void insertChange( | ||
| @Param("metalakeName") String metalakeName, | ||
| @Param("entityType") String entityType, | ||
| @Param("fullName") String fullName, | ||
| @Param("operateType") String operateType, | ||
| @Param("createdAt") long createdAt); | ||
|
|
||
| @DeleteProvider(type = EntityChangeLogSQLProviderFactory.class, method = "pruneOldEntityChanges") | ||
| void pruneOldEntries(@Param("before") long before); | ||
| } |
82 changes: 82 additions & 0 deletions
82
...ava/org/apache/gravitino/storage/relational/mapper/EntityChangeLogSQLProviderFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * 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.storage.relational.mapper; | ||
|
|
||
| import static org.apache.gravitino.storage.relational.mapper.EntityChangeLogMapper.ENTITY_CHANGE_LOG_TABLE_NAME; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import java.util.Map; | ||
| import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; | ||
| import org.apache.gravitino.storage.relational.mapper.provider.base.EntityChangeLogBaseSQLProvider; | ||
| import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; | ||
| import org.apache.ibatis.annotations.Param; | ||
|
|
||
| public class EntityChangeLogSQLProviderFactory { | ||
|
|
||
| private static final Map<JDBCBackendType, EntityChangeLogBaseSQLProvider> | ||
| ENTITY_CHANGE_LOG_SQL_PROVIDER_MAP = | ||
| ImmutableMap.of( | ||
| JDBCBackendType.MYSQL, new EntityChangeLogMySQLProvider(), | ||
| JDBCBackendType.H2, new EntityChangeLogH2Provider(), | ||
| JDBCBackendType.POSTGRESQL, new EntityChangeLogPostgreSQLProvider()); | ||
|
|
||
| public static EntityChangeLogBaseSQLProvider getProvider() { | ||
| String databaseId = | ||
| SqlSessionFactoryHelper.getInstance() | ||
| .getSqlSessionFactory() | ||
| .getConfiguration() | ||
| .getDatabaseId(); | ||
| JDBCBackendType jdbcBackendType = JDBCBackendType.fromString(databaseId); | ||
| return ENTITY_CHANGE_LOG_SQL_PROVIDER_MAP.get(jdbcBackendType); | ||
| } | ||
|
|
||
| static class EntityChangeLogMySQLProvider extends EntityChangeLogBaseSQLProvider {} | ||
|
|
||
| static class EntityChangeLogH2Provider extends EntityChangeLogBaseSQLProvider {} | ||
|
|
||
| static class EntityChangeLogPostgreSQLProvider extends EntityChangeLogBaseSQLProvider { | ||
| @Override | ||
| public String pruneOldEntityChanges(@Param("before") long before) { | ||
| return "DELETE FROM " | ||
| + ENTITY_CHANGE_LOG_TABLE_NAME | ||
| + " WHERE id IN (SELECT id FROM " | ||
| + ENTITY_CHANGE_LOG_TABLE_NAME | ||
| + " WHERE created_at < #{before} LIMIT 1000)"; | ||
| } | ||
| } | ||
|
|
||
| public static String selectEntityChanges( | ||
| @Param("createdAtAfter") long createdAtAfter, @Param("maxRows") int maxRows) { | ||
| return getProvider().selectEntityChanges(createdAtAfter, maxRows); | ||
| } | ||
|
|
||
| public static String insertEntityChange( | ||
| @Param("metalakeName") String metalakeName, | ||
| @Param("entityType") String entityType, | ||
| @Param("fullName") String fullName, | ||
| @Param("operateType") String operateType, | ||
| @Param("createdAt") long createdAt) { | ||
| return getProvider() | ||
| .insertEntityChange(metalakeName, entityType, fullName, operateType, createdAt); | ||
| } | ||
|
|
||
| public static String pruneOldEntityChanges(@Param("before") long before) { | ||
| return getProvider().pruneOldEntityChanges(before); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...che/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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.storage.relational.mapper.provider.base; | ||
|
|
||
| import static org.apache.gravitino.storage.relational.mapper.EntityChangeLogMapper.ENTITY_CHANGE_LOG_TABLE_NAME; | ||
|
|
||
| import org.apache.ibatis.annotations.Param; | ||
|
|
||
| public class EntityChangeLogBaseSQLProvider { | ||
|
|
||
| public String selectEntityChanges( | ||
| @Param("createdAtAfter") long createdAtAfter, @Param("maxRows") int maxRows) { | ||
| return "SELECT metalake_name as metalakeName, entity_type as entityType," | ||
| + " full_name as fullName, operate_type as operateType, created_at as createdAt" | ||
| + " FROM " | ||
| + ENTITY_CHANGE_LOG_TABLE_NAME | ||
| + " WHERE created_at > #{createdAtAfter} ORDER BY created_at LIMIT #{maxRows}"; | ||
|
yuqi1129 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public String insertEntityChange( | ||
| @Param("metalakeName") String metalakeName, | ||
| @Param("entityType") String entityType, | ||
| @Param("fullName") String fullName, | ||
| @Param("operateType") String operateType, | ||
| @Param("createdAt") long createdAt) { | ||
| return "INSERT INTO " | ||
| + ENTITY_CHANGE_LOG_TABLE_NAME | ||
| + " (metalake_name, entity_type, full_name, operate_type, created_at)" | ||
| + " VALUES (#{metalakeName}, #{entityType}, #{fullName}, #{operateType}, #{createdAt})"; | ||
| } | ||
|
|
||
| public String pruneOldEntityChanges(@Param("before") long before) { | ||
| return "DELETE FROM " | ||
| + ENTITY_CHANGE_LOG_TABLE_NAME | ||
| + " WHERE created_at < #{before} LIMIT 1000"; | ||
|
yuqi1129 marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.