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

rong 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 58ade690a9c fix cn parser and code style. (#12231)
58ade690a9c is described below

commit 58ade690a9c8b72aee16d5e81c4c25cb6834996e
Author: Colin Li <[email protected]>
AuthorDate: Mon Mar 25 16:09:50 2024 +0800

    fix cn parser and code style. (#12231)
---
 .../consensus/request/auth/AuthorPlan.java         | 18 +++++++++
 .../confignode/manager/PermissionManager.java      |  1 +
 .../schema/CNPhysicalPlanGenerator.java            | 43 ++++++++++------------
 .../persistence/schema/CNSnapshotFileType.java     |  2 +-
 .../schema/ConfignodeSnapshotParser.java           |  9 ++---
 .../impl/sync/AuthOperationProcedure.java          | 21 +++++++++--
 .../persistence/CNPhysicalPlanGeneratorTest.java   | 28 +++++++-------
 .../iotdb/commons/auth/entity/PrivilegeType.java   | 11 ++++++
 .../commons/auth/role/LocalFileRoleAccessor.java   |  2 +
 .../iotdb/commons/auth/user/BasicUserManager.java  |  8 +---
 .../commons/auth/user/LocalFileUserAccessor.java   |  8 +++-
 11 files changed, 96 insertions(+), 55 deletions(-)

diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/auth/AuthorPlan.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/auth/AuthorPlan.java
index 61c76320007..2f8db35dc13 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/auth/AuthorPlan.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/auth/AuthorPlan.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.confignode.consensus.request.auth;
 
 import org.apache.iotdb.commons.auth.AuthException;
+import org.apache.iotdb.commons.auth.entity.PrivilegeType;
 import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.utils.BasicStructureSerDeUtil;
@@ -292,4 +293,21 @@ public class AuthorPlan extends ConfigPhysicalPlan {
     return Objects.hash(
         authorType, userName, roleName, password, newPassword, permissions, 
nodeNameList, grantOpt);
   }
+
+  @Override
+  public String toString() {
+    return "[type:"
+        + authorType
+        + ", username:"
+        + userName
+        + ", rolename:"
+        + roleName
+        + ", permissions:"
+        + PrivilegeType.toPriType(permissions)
+        + ", grant option:"
+        + grantOpt
+        + ", paths:"
+        + nodeNameList
+        + "]";
+  }
 }
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
index 7e7c6f9c437..7e74c7dce03 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
@@ -61,6 +61,7 @@ public class PermissionManager {
   public TSStatus operatePermission(AuthorPlan authorPlan, boolean 
isGeneratedByPipe) {
     TSStatus tsStatus;
     // If the permissions change, clear the cache content affected by the 
operation
+    LOGGER.info("Auth: run auth plan: {}", authorPlan.toString());
     try {
       if (authorPlan.getAuthorType() == ConfigPhysicalPlanType.CreateUser
           || authorPlan.getAuthorType() == ConfigPhysicalPlanType.CreateRole) {
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNPhysicalPlanGenerator.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNPhysicalPlanGenerator.java
index 742ad457ed4..213cf51daef 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNPhysicalPlanGenerator.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNPhysicalPlanGenerator.java
@@ -93,7 +93,7 @@ public class CNPhysicalPlanGenerator
 
   public CNPhysicalPlanGenerator(Path snapshotFilePath, CNSnapshotFileType 
fileType)
       throws IOException {
-    if (fileType == CNSnapshotFileType.SCHEMA_TEMPLATE) {
+    if (fileType == CNSnapshotFileType.SCHEMA) {
       logger.warn("schema_template need two files");
       return;
     }
@@ -107,7 +107,7 @@ public class CNPhysicalPlanGenerator
   public CNPhysicalPlanGenerator(Path schemaInfoFile, Path templateFile) 
throws IOException {
     inputStream = Files.newInputStream(schemaInfoFile);
     templateInputStream = Files.newInputStream(templateFile);
-    snapshotFileType = CNSnapshotFileType.SCHEMA_TEMPLATE;
+    snapshotFileType = CNSnapshotFileType.SCHEMA;
   }
 
   @Override
@@ -127,7 +127,7 @@ public class CNPhysicalPlanGenerator
       generateUserRolePhysicalPlan(false);
     } else if (snapshotFileType == CNSnapshotFileType.USER_ROLE) {
       generateGrantRolePhysicalPlan();
-    } else if (snapshotFileType == CNSnapshotFileType.SCHEMA_TEMPLATE) {
+    } else if (snapshotFileType == CNSnapshotFileType.SCHEMA) {
       generateTemplatePlan();
       if (latestException != null) {
         return false;
@@ -178,7 +178,6 @@ public class CNPhysicalPlanGenerator
       }
       String user = versionAndName.left;
       if (isUser) {
-        // skip password
         readString(dataInputStream, STRING_ENCODING, strBufferLocal);
         AuthorPlan createUser = new 
AuthorPlan(ConfigPhysicalPlanType.CreateUser);
         createUser.setUserName(user);
@@ -191,9 +190,7 @@ public class CNPhysicalPlanGenerator
       }
 
       int privilegeMask = dataInputStream.readInt();
-      // translate sys privileges
       generateGrantSysPlan(user, isUser, privilegeMask);
-      // translate path privileges
       while (dataInputStream.available() != 0) {
         String path = readString(dataInputStream, STRING_ENCODING, 
strBufferLocal);
         PartialPath priPath;
@@ -208,7 +205,7 @@ public class CNPhysicalPlanGenerator
       }
     } catch (IOException ioException) {
       logger.error(
-          "Got IOException when deserialize userole file, type:{}", 
snapshotFileType, ioException);
+          "Got IOException when deserialize use&role file, type:{}", 
snapshotFileType, ioException);
       latestException = ioException;
     } finally {
       strBufferLocal.remove();
@@ -279,8 +276,8 @@ public class CNPhysicalPlanGenerator
   private void generateDatabasePhysicalPlan() {
     try (BufferedInputStream bufferedInputStream = new 
BufferedInputStream(inputStream)) {
       byte type = ReadWriteIOUtils.readByte(bufferedInputStream);
-      String name = null;
-      int childNum = 0;
+      String name;
+      int childNum;
       Stack<Pair<IConfigMNode, Boolean>> stack = new Stack<>();
       IConfigMNode databaseMNode;
       IConfigMNode internalMNode;
@@ -358,12 +355,9 @@ public class CNPhysicalPlanGenerator
     databaseMNode
         .getAsMNode()
         
.setDatabaseSchema(ThriftConfigNodeSerDeUtils.deserializeTDatabaseSchema(inputStream));
+    Long databaseTTL = -1L;
     if (databaseMNode.getAsMNode().getDatabaseSchema().isSetTTL()) {
-      SetTTLPlan plan =
-          new SetTTLPlan(
-              
Collections.singletonList(databaseMNode.getAsMNode().getDatabaseSchema().getName()),
-              databaseMNode.getAsMNode().getDatabaseSchema().getTTL());
-      planDeque.add(plan);
+      databaseTTL = databaseMNode.getAsMNode().getDatabaseSchema().getTTL();
       databaseMNode.getAsMNode().getDatabaseSchema().unsetTTL();
     }
 
@@ -371,7 +365,13 @@ public class CNPhysicalPlanGenerator
         new DatabaseSchemaPlan(
             ConfigPhysicalPlanType.CreateDatabase, 
databaseMNode.getAsMNode().getDatabaseSchema());
     planDeque.add(createDBPlan);
-
+    if (databaseTTL != -1L) {
+      SetTTLPlan setTTLPlan =
+          new SetTTLPlan(
+              
Collections.singletonList(databaseMNode.getAsMNode().getDatabaseSchema().getName()),
+              databaseTTL);
+      planDeque.add(setTTLPlan);
+    }
     return databaseMNode.getAsMNode();
   }
 
@@ -379,14 +379,11 @@ public class CNPhysicalPlanGenerator
     IConfigMNode basicMNode =
         nodeFactory.createInternalMNode(null, 
ReadWriteIOUtils.readString(inputStream));
     basicMNode.setSchemaTemplateId(ReadWriteIOUtils.readInt(inputStream));
-    if (basicMNode.getSchemaTemplateId() >= 0) {
-      if (!templateTable.isEmpty()) {
-        String templateName = 
templateTable.get(basicMNode.getSchemaTemplateId());
-        // ignore preset plan.
-        CommitSetSchemaTemplatePlan plan =
-            new CommitSetSchemaTemplatePlan(templateName, 
basicMNode.getFullPath());
-        planDeque.add(plan);
-      }
+    if (basicMNode.getSchemaTemplateId() >= 0 && !templateTable.isEmpty()) {
+      String templateName = 
templateTable.get(basicMNode.getSchemaTemplateId());
+      CommitSetSchemaTemplatePlan plan =
+          new CommitSetSchemaTemplatePlan(templateName, 
basicMNode.getFullPath());
+      planDeque.add(plan);
     }
     return basicMNode;
   }
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNSnapshotFileType.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNSnapshotFileType.java
index ee8f6f9bb79..0c64a18da48 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNSnapshotFileType.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/CNSnapshotFileType.java
@@ -24,5 +24,5 @@ public enum CNSnapshotFileType {
   USER,
   ROLE,
   USER_ROLE,
-  SCHEMA_TEMPLATE
+  SCHEMA
 }
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfignodeSnapshotParser.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfignodeSnapshotParser.java
index 1f6aea04cfe..cbec961cf47 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfignodeSnapshotParser.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfignodeSnapshotParser.java
@@ -74,7 +74,6 @@ public class ConfignodeSnapshotParser {
       for (Path path : stream) {
         try (DirectoryStream<Path> filestream =
             Files.newDirectoryStream(Paths.get(path.toString() + 
File.separator + "sm"))) {
-          // find the latest snapshots
           ArrayList<Path> snapshotList = new ArrayList<>();
           for (Path snapshotFolder : filestream) {
             if (snapshotFolder.toFile().isDirectory()) {
@@ -135,7 +134,7 @@ public class ConfignodeSnapshotParser {
               snapshotPairList.add(
                   new Pair<>(
                       new Pair<>(schemaInfoFile.toPath(), 
templateInfoFile.toPath()),
-                      CNSnapshotFileType.SCHEMA_TEMPLATE));
+                      CNSnapshotFileType.SCHEMA));
             }
           }
         }
@@ -146,8 +145,8 @@ public class ConfignodeSnapshotParser {
 
   public static CNPhysicalPlanGenerator translate2PhysicalPlan(
       Path path1, Path path2, CNSnapshotFileType type) throws IOException {
-    if (type == CNSnapshotFileType.SCHEMA_TEMPLATE && (path1 == null || path2 
== null)) {
-      LOGGER.warn("schema_template require schemainfo file and template file");
+    if (type == CNSnapshotFileType.SCHEMA && (path1 == null || path2 == null)) 
{
+      LOGGER.warn("schema_template require schema info file and template 
file");
       return null;
     } else if (path1 == null) {
       LOGGER.warn("path1 should not be null");
@@ -159,7 +158,7 @@ public class ConfignodeSnapshotParser {
       return null;
     }
 
-    if (type == CNSnapshotFileType.SCHEMA_TEMPLATE) {
+    if (type == CNSnapshotFileType.SCHEMA) {
       return new CNPhysicalPlanGenerator(path1, path2);
     } else {
       return new CNPhysicalPlanGenerator(path1, type);
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/sync/AuthOperationProcedure.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/sync/AuthOperationProcedure.java
index 4a165235221..14bb0a68322 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/sync/AuthOperationProcedure.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/sync/AuthOperationProcedure.java
@@ -69,7 +69,7 @@ public class AuthOperationProcedure extends 
AbstractNodeProcedure<AuthOperationP
   private static final int RETRY_THRESHOLD = 2;
   private static final CommonConfig commonConfig = 
CommonDescriptor.getInstance().getConfig();
 
-  private List<Pair<TDataNodeConfiguration, Long>> dataNodesToInvalid;
+  private final List<Pair<TDataNodeConfiguration, Long>> dataNodesToInvalid = 
new ArrayList<>();
 
   private List<TDataNodeConfiguration> datanodes;
 
@@ -117,6 +117,7 @@ public class AuthOperationProcedure extends 
AbstractNodeProcedure<AuthOperationP
             }
           }
           if (dataNodesToInvalid.isEmpty()) {
+            LOGGER.info("Auth procedure: clean datanode cache successfully");
             return Flow.NO_MORE_STATE;
           } else {
             
setNextState(AuthOperationProcedureState.DATANODE_AUTHCACHE_INVALIDING);
@@ -152,12 +153,12 @@ public class AuthOperationProcedure extends 
AbstractNodeProcedure<AuthOperationP
       res.setMessage(e.getMessage());
     }
     if (res.code == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
-      LOGGER.debug("Execute auth plan {} success.", plan);
       setNextState(DATANODE_AUTHCACHE_INVALIDING);
-      dataNodesToInvalid = new ArrayList<>();
       for (TDataNodeConfiguration item : datanodes) {
         this.dataNodesToInvalid.add(new Pair<>(item, 
System.currentTimeMillis()));
       }
+      LOGGER.info(
+          "Execute auth plan {} success. To invalidate datanodes: {}", plan, 
dataNodesToInvalid);
     } else {
       LOGGER.info("Failed to execute plan {} because {}", plan, res.message);
       setFailure(new ProcedureException(new IoTDBException(res.message, 
res.code)));
@@ -200,6 +201,11 @@ public class AuthOperationProcedure extends 
AbstractNodeProcedure<AuthOperationP
     }
     ReadWriteIOUtils.write(timeoutMS, stream);
     ReadWriteIOUtils.write(plan.serializeToByteBuffer(), stream);
+    ReadWriteIOUtils.write(dataNodesToInvalid.size(), stream);
+    for (Pair<TDataNodeConfiguration, Long> item : dataNodesToInvalid) {
+      ThriftCommonsSerDeUtils.serializeTDataNodeConfiguration(item.left, 
stream);
+      ReadWriteIOUtils.write(item.right, stream);
+    }
   }
 
   @Override
@@ -219,6 +225,15 @@ public class AuthOperationProcedure extends 
AbstractNodeProcedure<AuthOperationP
     } catch (IOException e) {
       LOGGER.error("IO error when deserialize authplan.", e);
     }
+    if (byteBuffer.hasRemaining()) {
+      size = ReadWriteIOUtils.readInt(byteBuffer);
+      for (int i = 0; i < size; i++) {
+        TDataNodeConfiguration datanode =
+            
ThriftCommonsSerDeUtils.deserializeTDataNodeConfiguration(byteBuffer);
+        Long timeStamp = ReadWriteIOUtils.readLong(byteBuffer);
+        this.dataNodesToInvalid.add(new Pair<>(datanode, timeStamp));
+      }
+    }
   }
 
   @Override
diff --git 
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/CNPhysicalPlanGeneratorTest.java
 
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/CNPhysicalPlanGeneratorTest.java
index f7b7700c244..476966a385f 100644
--- 
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/CNPhysicalPlanGeneratorTest.java
+++ 
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/CNPhysicalPlanGeneratorTest.java
@@ -101,10 +101,10 @@ public class CNPhysicalPlanGeneratorTest {
     AuthorPlan plan = new AuthorPlan(ConfigPhysicalPlanType.CreateRole);
     plan.setRoleName(roleName);
     answerSet.add(plan.hashCode());
-    // step 1: create role - plan1
+    // Step 1: create role - plan1
     authorInfo.authorNonQuery(plan);
 
-    // step 2: grant role path privileges - plan2
+    // Step 2: grant role path privileges - plan2
     plan = new AuthorPlan(ConfigPhysicalPlanType.GrantRole);
     plan.setRoleName(roleName);
     plan.setNodeNameList(Collections.singletonList(new 
PartialPath("root.db.t1")));
@@ -114,7 +114,7 @@ public class CNPhysicalPlanGeneratorTest {
     plan.setPermissions(pathPris);
     authorInfo.authorNonQuery(plan);
 
-    // answer set
+    // Answer set
     plan.getPermissions().clear();
     plan.getPermissions().add(PrivilegeType.WRITE_DATA.ordinal());
     answerSet.add(plan.hashCode());
@@ -122,7 +122,7 @@ public class CNPhysicalPlanGeneratorTest {
     plan.getPermissions().add(PrivilegeType.WRITE_SCHEMA.ordinal());
     answerSet.add(plan.hashCode());
 
-    // step 3: grant role sys privileges - plan3
+    // Step 3: grant role sys privileges - plan3
     plan = new AuthorPlan(ConfigPhysicalPlanType.GrantRole);
     plan.setRoleName(roleName);
     plan.setNodeNameList(Collections.emptyList());
@@ -133,7 +133,7 @@ public class CNPhysicalPlanGeneratorTest {
     plan.setGrantOpt(true);
     authorInfo.authorNonQuery(plan);
 
-    // answer set
+    // Answer set
     plan.getPermissions().clear();
     plan.getPermissions().add(PrivilegeType.MANAGE_ROLE.ordinal());
     answerSet.add(plan.hashCode());
@@ -141,11 +141,11 @@ public class CNPhysicalPlanGeneratorTest {
     plan.getPermissions().add(PrivilegeType.MANAGE_DATABASE.ordinal());
     answerSet.add(plan.hashCode());
 
-    // PhysicalPlan gnerator will return five plans:
+    // PhysicalPlan generator will return five plans:
     // 1. create role plan
     // 2. grant path privileges plan * 2
     // 3. grant system privileges plan * 2
-    boolean success = authorInfo.processTakeSnapshot(snapshotDir);
+    Assert.assertTrue(authorInfo.processTakeSnapshot(snapshotDir));
 
     File roleProfile =
         SystemFileFactory.INSTANCE.getFile(
@@ -174,7 +174,7 @@ public class CNPhysicalPlanGeneratorTest {
     AuthorPlan plan = new AuthorPlan(ConfigPhysicalPlanType.CreateUser);
     plan.setPassword("password");
     plan.setUserName(userName);
-    // create user plan 1
+    // Create user plan 1
     authorInfo.authorNonQuery(plan);
     answerSet.add(plan.hashCode());
 
@@ -182,7 +182,7 @@ public class CNPhysicalPlanGeneratorTest {
     plan.setRoleName("role1");
     authorInfo.authorNonQuery(plan);
 
-    // grant path privileges, plan 2 , plan 3
+    // Grant path privileges, plan 2 , plan 3
     plan = new AuthorPlan(ConfigPhysicalPlanType.GrantUser);
     plan.setUserName(userName);
     plan.setNodeNameList(Collections.singletonList(new 
PartialPath("root.db1.t2")));
@@ -201,7 +201,7 @@ public class CNPhysicalPlanGeneratorTest {
     plan.getPermissions().add(PrivilegeType.READ_DATA.ordinal());
     answerSet.add(plan.hashCode());
 
-    // grant system privileges, plan 4
+    // Grant system privileges, plan 4
     plan = new AuthorPlan(ConfigPhysicalPlanType.GrantUser);
     plan.setUserName(userName);
     plan.setNodeNameList(Collections.emptyList());
@@ -210,14 +210,14 @@ public class CNPhysicalPlanGeneratorTest {
     authorInfo.authorNonQuery(plan);
     answerSet.add(plan.hashCode());
 
-    // grant role to user, plan 5
+    // Grant role to user, plan 5
     plan = new AuthorPlan(ConfigPhysicalPlanType.GrantRoleToUser);
     plan.setRoleName("role1");
     plan.setUserName(userName);
     authorInfo.authorNonQuery(plan);
     answerSet.add(plan.hashCode());
 
-    boolean success = authorInfo.processTakeSnapshot(snapshotDir);
+    Assert.assertTrue(authorInfo.processTakeSnapshot(snapshotDir));
 
     File userProfile =
         SystemFileFactory.INSTANCE.getFile(
@@ -309,7 +309,7 @@ public class CNPhysicalPlanGeneratorTest {
   }
 
   @Test
-  public void templateGneratorTest() throws Exception {
+  public void templateGeneratorTest() throws Exception {
     setupClusterSchemaInfo();
     Template t1 =
         new Template(
@@ -353,7 +353,7 @@ public class CNPhysicalPlanGeneratorTest {
   }
 
   @Test
-  public void templateAndDatabaseComplatedTest() throws Exception {
+  public void templateAndDatabaseCompletedTest() throws Exception {
     setupClusterSchemaInfo();
     Set<Integer> answerSet = new HashSet<>();
     Set<String> storageGroupPathList = new TreeSet<>();
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
index 3c385679ba3..18c6c9b64c6 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
@@ -19,6 +19,9 @@
 
 package org.apache.iotdb.commons.auth.entity;
 
+import java.util.HashSet;
+import java.util.Set;
+
 /** This enum class contains all available privileges in IoTDB. */
 public enum PrivilegeType {
   READ_DATA(true),
@@ -78,4 +81,12 @@ public enum PrivilegeType {
     }
     return size;
   }
+
+  public static Set<PrivilegeType> toPriType(Set<Integer> priSet) {
+    Set<PrivilegeType> typeSet = new HashSet<>();
+    for (Integer pri : priSet) {
+      typeSet.add(PrivilegeType.values()[pri]);
+    }
+    return typeSet;
+  }
 }
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/role/LocalFileRoleAccessor.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/role/LocalFileRoleAccessor.java
index 530b09b05c9..e46bd249130 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/role/LocalFileRoleAccessor.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/role/LocalFileRoleAccessor.java
@@ -291,6 +291,8 @@ public class LocalFileRoleAccessor implements IRoleAccessor 
{
       for (File file : files) {
         FileUtils.deleteFileIfExist(file);
       }
+    } else {
+      LOGGER.warn("Role folder not exists");
     }
   }
 
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 774cfe5a1e8..aeeac635e24 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
@@ -313,15 +313,9 @@ public abstract class BasicUserManager implements 
IUserManager {
     }
   }
 
-  // If system.users is empty, it means we are init our system, so init an 
admin user.
-  // If system.user is not empty when we start system, it means we will boost 
our system with
-  // snapshot data,
-  // init admin when we load snapshot.
   private void init() throws AuthException {
     this.accessor.reset();
-    if (accessor.listAllUsers().isEmpty()) {
-      initAdmin();
-    }
+    initAdmin();
   }
 
   @Override
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/LocalFileUserAccessor.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/LocalFileUserAccessor.java
index b59743161d2..65435b5ec10 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/LocalFileUserAccessor.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/LocalFileUserAccessor.java
@@ -421,8 +421,12 @@ public class LocalFileUserAccessor implements 
IUserAccessor {
   @Override
   public void cleanUserFolder() {
     File[] files = SystemFileFactory.INSTANCE.getFile(userDirPath).listFiles();
-    for (File file : files) {
-      FileUtils.deleteFileIfExist(file);
+    if (files != null) {
+      for (File file : files) {
+        FileUtils.deleteFileIfExist(file);
+      }
+    } else {
+      LOGGER.warn("User folder not exists");
     }
   }
 

Reply via email to