roryqi commented on code in PR #14326:
URL: https://github.com/apache/gravitino/pull/14326#discussion_r4467222092
##########
core/src/main/java/org/apache/gravitino/tag/TagManager.java:
##########
@@ -120,6 +124,7 @@ public Tag createTag(
Map<String, String> properties,
TagValueConstraint valueConstraint)
throws TagAlreadyExistsException {
+ HiddenPolicyTag.checkVisible(name);
Review Comment:
Updated in 1e6f63536e: prefix validation now applies only to create and
rename targets. Existing tags are protected by their stored `hidden` flag, so
pre-upgrade tags in either casing remain accessible and can be renamed away.
Hidden-tag collisions now report the tag name as `TagAlreadyExistsException`
(HTTP 409). Added regression coverage for both casings.
##########
core/src/main/java/org/apache/gravitino/policy/PolicyManager.java:
##########
@@ -73,6 +78,100 @@ public PolicyManager(IdGenerator idGenerator, EntityStore
entityStore) {
this.objectPolicyResolver = new ObjectPolicyResolver(entityStore);
}
+ /**
+ * Applies a policy to an object through its hidden tag using the entity
store.
+ *
+ * <p>This internal operation is idempotent. Migration callers can group it
with legacy cleanup in
+ * their storage transaction. It is not exposed through the policy
dispatcher or client APIs.
+ *
+ * @param metalake The policy and object's metalake.
+ * @param policyName The policy name.
+ * @param object The metadata object to associate.
+ * @param auditInfo The audit information to preserve on newly created
relations.
+ * @return The policy's hidden tag ID.
+ * @throws IOException If an entity or relation cannot be persisted.
+ */
+ public long addPolicyToObject(
Review Comment:
Updated in 1e6f63536e. When another writer creates the expected
selector-free policy link, `addPolicyToObject` now reloads and validates it,
then continues the object assignment. Ordinary duplicate policy-tag additions
still conflict. Added a deterministic two-caller regression on
H2/MySQL/PostgreSQL.
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/PolicyMetaService.java:
##########
@@ -499,6 +535,26 @@ private void updatePolicyRootWithVersion(
() -> policyWriteFailure(identifier, oldPolicyPO));
}
+ private void deleteHiddenTagWithoutCommit(PolicyPO policy) {
+ TagPO tag =
+ SessionUtils.getWithoutCommit(
+ TagMetaMapper.class,
+ mapper ->
+ mapper.selectTagMetaByMetalakeIdAndNameForUpdate(
+ policy.getMetalakeId(),
HiddenPolicyTag.name(policy.getPolicyId())));
+ if (tag == null
+ || !tag.isHidden()
+ ||
!HiddenPolicyTag.properties(policy.getPolicyId()).equals(tag.getProperties())) {
Review Comment:
Updated in 1e6f63536e. Cleanup now identifies the tag by `hidden=true` and
its canonical name, checks that soft deletion affects exactly one row, and
removes the object assignments in the same transaction. The deleted policy
snapshot is used to invalidate the local tag cache, and a tag DROP record
invalidates peer caches. Added JSON-formatting, rollback, and local/peer cache
tests on H2/MySQL/PostgreSQL.
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/PolicyMetaService.java:
##########
@@ -434,6 +446,30 @@ private void insertPolicyVersionIfAllocated(PolicyPO
oldPolicyPO, PolicyPO newPo
mapper ->
mapper.insertPolicyVersion(newPolicyPO.getPolicyVersionPO()));
}
+ private void createHiddenTagWithoutCommit(PolicyEntity policy, PolicyPO
policyPO) {
+ TagEntity tag = HiddenPolicyTag.create(policy,
RandomIdGenerator.INSTANCE.nextId());
Review Comment:
Updated in 94f584f66b. Hidden-tag creation now uses
`GravitinoEnv.getInstance().idGenerator()`, the same server generator used for
policy IDs, following the existing schema/metric storage pattern. Tests cover
ordinary create, create via overwrite, tag reuse on overwrite, and rollback
when the generator is uninitialized; all pass on H2/MySQL/PostgreSQL.
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TagMetaBaseSQLProvider.java:
##########
@@ -33,7 +33,7 @@ public String listTagPOsByMetalake(@Param("metalakeName")
String metalakeName) {
+ " tm.metalake_id as metalakeId,"
+ " tm.tag_comment as comment,"
+ " tm.properties as properties,"
- + " tm.allowed_values as allowedValues,"
+ + " tm.allowed_values as allowedValues, tm.hidden as hidden,"
Review Comment:
Documented in `docs/policies.md` in 1e6f63536e: stop all old servers before
the schema upgrade, complete any required offline policy binding migration
while servers are stopped, and start only upgraded servers. The guide
explicitly rules out mixed versions after hidden tags have been created by
policy creation or migration.
--
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]