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


##########
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:
   i18n



##########
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:
   i18n



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