VGalaxies commented on code in PR #17780:
URL: https://github.com/apache/iotdb/pull/17780#discussion_r3395911858


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/subscription/meta/topic/TopicMeta.java:
##########
@@ -168,14 +187,29 @@ public void transferOwner(
                   + " current owner-epoch: %s, current 
owner-lease-expire-time-ms: %s",
               topicName, this.ownerId, this.ownerEpoch, 
this.ownerLeaseExpireTimeMs));
     }
+    if (Objects.nonNull(ownerLeaseDurationMs) && ownerLeaseDurationMs <= 0) {
+      throw new IllegalArgumentException(
+          String.format(
+              "Subscription topic owner lease duration should be positive, 
topic: %s,"
+                  + " owner-lease-duration-ms: %s",
+              topicName, ownerLeaseDurationMs));

Review Comment:
   Addressed in 6787927100. Moved the TopicMeta owner-fencing exception 
messages (owner id/epoch validation, monotonic/never-reused epoch, stale-clear, 
rollback, and lease-duration checks) into `SubscriptionMessages` with both en 
and zh locale sources. node-commons already depends on the subscription client 
module, so it reuses that i18n class.



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/subscription/SubscriptionCoordinator.java:
##########
@@ -163,11 +169,81 @@ public TSStatus alterTopic(TAlterTopicReq req) {
     return status;
   }
 
+  public boolean blockOwnerLeaseRenewalIfOwnerTransfer(TAlterTopicReq req) {
+    final TopicMeta currentTopicMeta = 
subscriptionInfo.deepCopyTopicMeta(req.getTopicName());
+    final TopicMeta updatedTopicMeta = buildAlteredTopicMeta(req);
+    if (Objects.isNull(currentTopicMeta)
+        || Objects.isNull(updatedTopicMeta)
+        || Objects.equals(currentTopicMeta.getOwnerId(), 
updatedTopicMeta.getOwnerId())) {
+      return false;
+    }
+
+    blockedOwnerLeaseRenewalTopics.add(req.getTopicName());
+    return true;
+  }
+
+  public void unblockOwnerLeaseRenewal(String topicName) {
+    blockedOwnerLeaseRenewalTopics.remove(topicName);
+  }
+
+  public TopicMeta buildAlteredTopicMetaAfterOwnerLeaseExpired(TAlterTopicReq 
req)
+      throws InterruptedException {
+    while (true) {
+      final TopicMeta currentTopicMeta = 
subscriptionInfo.deepCopyTopicMeta(req.getTopicName());
+      final TopicMeta updatedTopicMeta = buildAlteredTopicMeta(req);
+      if (Objects.isNull(currentTopicMeta)
+          || Objects.isNull(updatedTopicMeta)
+          || Objects.equals(currentTopicMeta.getOwnerId(), 
updatedTopicMeta.getOwnerId())) {
+        return updatedTopicMeta;
+      }
+
+      final long ownerLeaseRemainingTimeMs = 
currentTopicMeta.getOwnerLeaseRemainingTimeMs();
+      if (Objects.isNull(currentTopicMeta.getOwnerLeaseExpireTimeMs())
+          || ownerLeaseRemainingTimeMs <= 0) {
+        return updatedTopicMeta;
+      }
+
+      Thread.sleep(Math.min(ownerLeaseRemainingTimeMs + 1, 1000L));
+    }
+  }
+
   public TopicMeta buildAlteredTopicMeta(TAlterTopicReq req) {
     return subscriptionInfo.deepCopyTopicMetaWithUpdatedAttributes(
         req.getTopicName(), req.getTopicAttributes());
   }
 
+  public TSStatus renewTopicOwnerLease(TRenewTopicOwnerLeaseReq req) {
+    if (blockedOwnerLeaseRenewalTopics.contains(req.getTopicName())) {
+      return RpcUtils.getStatus(
+          TSStatusCode.SUBSCRIPTION_OWNER_FENCED,
+          String.format(
+              "Subscription: topic %s owner lease renewal is blocked by a 
pending owner transfer.",
+              req.getTopicName()));
+    }

Review Comment:
   Addressed in 6787927100. The originally flagged `renewTopicOwnerLease` 
message was removed during the owner-lease rework (CN-side renewal was replaced 
by a DataNode-local lease heartbeat). The remaining PR-introduced hard-coded 
message in this file, the alter-topic warn, now uses 
`ManagerMessages.FAILED_TO_ALTER_TOPIC_WITH_ATTRIBUTES_RESULT_STATUS` (en/zh).



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