This is an automated email from the ASF dual-hosted git repository.

yongzao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 877c1c0d857 Fix compatibility issues for userid (#16473)
877c1c0d857 is described below

commit 877c1c0d8574e4fbc0bd2b821b95dca36576b7ea
Author: wenyanshi-123 <[email protected]>
AuthorDate: Wed Sep 24 16:57:53 2025 +0800

    Fix compatibility issues for userid (#16473)
---
 .../apache/iotdb/commons/auth/user/BasicUserManager.java | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
index 96d5ad7cc42..cb46f5643a0 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
@@ -154,13 +154,6 @@ public abstract class BasicUserManager extends 
BasicRoleManager {
     try {
       long maxUserId = this.accessor.loadUserId();
       nextUserId = Math.max(maxUserId, INTERNAL_USER_END_ID);
-
-      for (Map.Entry<String, Role> userEntry : entityMap.entrySet()) {
-        User user = (User) userEntry.getValue();
-        if (user.getUserId() == -1) {
-          user.setUserId(++nextUserId);
-        }
-      }
     } catch (IOException e) {
       LOGGER.warn("meet error in load max userId.", e);
       throw new RuntimeException(e);
@@ -284,16 +277,23 @@ public abstract class BasicUserManager extends 
BasicRoleManager {
   public void reset() throws AuthException {
     accessor.reset();
     entityMap.clear();
+    initUserId();
     for (String userId : accessor.listAllEntities()) {
       try {
         User user = (User) accessor.loadEntity(userId);
+        if (user.getUserId() == -1) {
+          if 
(user.getName().equals(CommonDescriptor.getInstance().getConfig().getAdminName()))
 {
+            user.setUserId(0);
+          } else {
+            user.setUserId(++nextUserId);
+          }
+        }
         entityMap.put(user.getName(), user);
       } catch (IOException e) {
         LOGGER.warn("Get exception when load user {}", userId);
         throw new AuthException(TSStatusCode.AUTH_IO_EXCEPTION, e);
       }
     }
-    initUserId();
     initAdmin();
     initInternalAuditorWhenNecessary();
   }

Reply via email to