Caideyipi commented on code in PR #17985:
URL: https://github.com/apache/iotdb/pull/17985#discussion_r3434573847


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java:
##########
@@ -998,6 +1009,45 @@ public void processLoadSnapshot(final File snapshotDir) 
throws IOException {
     }
   }
 
+  public void enrichPipeMetasWithRootUserForCompatibility() {
+    acquireWriteLock();
+    try {
+      pipeMetaKeeper
+          .getPipeMetaList()
+          .forEach(
+              pipeMeta -> 
enrichPipeMetaWithRootUserForCompatibility(pipeMeta.getStaticMeta()));
+    } finally {
+      releaseWriteLock();
+    }
+  }
+
+  private void enrichPipeMetaWithRootUserForCompatibility(final PipeStaticMeta 
pipeStaticMeta) {
+    if (pipeUserPasswordProvider == null) {
+      return;
+    }
+    final boolean shouldEnrichSource = 
pipeStaticMeta.mayNeedCompatibleRootUserForIoTDBSource();
+    final boolean shouldEnrichSink = 
pipeStaticMeta.mayNeedCompatibleRootUserForWriteBackSink();
+    if (!shouldEnrichSource && !shouldEnrichSink) {
+      return;
+    }
+
+    final String rootUserName = 
CommonDescriptor.getInstance().getConfig().getDefaultAdminName();
+    final String password = pipeUserPasswordProvider.apply(rootUserName, null);

Review Comment:
   Addressed in 3801d49e817: removed the second parameter from the pipe 
metadata layer. ConfigManager now adapts PermissionManager.login4Pipe with 
userName -> login4Pipe(userName, null), because this compatibility path only 
needs to fetch the current stored root password.



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java:
##########
@@ -998,6 +1009,45 @@ public void processLoadSnapshot(final File snapshotDir) 
throws IOException {
     }
   }
 
+  public void enrichPipeMetasWithRootUserForCompatibility() {
+    acquireWriteLock();
+    try {
+      pipeMetaKeeper
+          .getPipeMetaList()
+          .forEach(
+              pipeMeta -> 
enrichPipeMetaWithRootUserForCompatibility(pipeMeta.getStaticMeta()));
+    } finally {
+      releaseWriteLock();
+    }
+  }
+
+  private void enrichPipeMetaWithRootUserForCompatibility(final PipeStaticMeta 
pipeStaticMeta) {
+    if (pipeUserPasswordProvider == null) {
+      return;
+    }
+    final boolean shouldEnrichSource = 
pipeStaticMeta.mayNeedCompatibleRootUserForIoTDBSource();
+    final boolean shouldEnrichSink = 
pipeStaticMeta.mayNeedCompatibleRootUserForWriteBackSink();
+    if (!shouldEnrichSource && !shouldEnrichSink) {
+      return;
+    }
+
+    final String rootUserName = 
CommonDescriptor.getInstance().getConfig().getDefaultAdminName();
+    final String password = pipeUserPasswordProvider.apply(rootUserName, null);
+    if (Objects.isNull(password)) {
+      throw new PipeException(
+          String.format(
+              "Failed to enrich pipe %s with root user for compatibility 
because root user %s does not exist.",
+              pipeStaticMeta.getPipeName(), rootUserName));

Review Comment:
   Addressed in 3801d49e817: moved this error message into ConfigNodeMessages 
and added the constant to both en and zh i18n source sets.



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java:
##########
@@ -95,10 +97,16 @@ public class PipeTaskInfo implements SnapshotProcessor {
 
   // Pure in-memory object, not involved in snapshot serialization and 
deserialization.
   private final PipeTaskInfoVersion pipeTaskInfoVersion;
+  private final BiFunction<String, String, String> pipeUserPasswordProvider;

Review Comment:
   Addressed in 3801d49e817: changed this from BiFunction<String, String, 
String> to Function<String, String> and renamed it to 
pipeUserCurrentPasswordProvider. The single parameter now clearly means 
username, and the return value is the current stored password for pipe 
authentication.



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