You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2019/11/14 05:29:15 UTC

[incubator-iotdb] 01/02: [IOTDB-303]fix user profile when online upgrading (#555)

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

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

commit 3043acff218a1c6566bfa0d61ada708af482af5f
Author: gwmh <16...@qq.com>
AuthorDate: Thu Nov 14 13:26:02 2019 +0800

    [IOTDB-303]fix user profile when online upgrading (#555)
    
    * [fix] upgrade *.profile to 0.9.0
---
 server/server-changelist.md                        | 39 ++++++++++++++++++++++
 .../iotdb/db/auth/user/LocalFileUserAccessor.java  | 19 ++++++++---
 2 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/server/server-changelist.md b/server/server-changelist.md
new file mode 100644
index 0000000..3893f62
--- /dev/null
+++ b/server/server-changelist.md
@@ -0,0 +1,39 @@
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+        http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+# 0.8.0 (version-0) -> version-1
+
+## User profile
+Last Updated on November 14th, 2019 by EJTTianYu.
+
+| PR#   | Name                                                         | Author          | Changes                                                      |
+| ---- | ------------------------------------------------------------ | --------------- | ------------------------------------------------------------ |
+| 299  | Turn watermark-demo into watermark feature                   | LeiRui          | Add watermark in the end of the profile.                     |
+
+## Upgrading Log
+Last Updated on November 14th, 2019 by EJTTianYu.
+
+| PR#   | Name                                                         | Author          | Changes                                                      |
+| ---- | ------------------------------------------------------------ | --------------- | ------------------------------------------------------------ |
+| 467  | [IOTDB-294]online upgrade from v0.8.0 to current version     | EJTTianYu       | Add upgrade/upgrade.txt in the system dir to record the upgrading process.     |
+
+
+
diff --git a/server/src/main/java/org/apache/iotdb/db/auth/user/LocalFileUserAccessor.java b/server/src/main/java/org/apache/iotdb/db/auth/user/LocalFileUserAccessor.java
index 6946a86..88ffd74 100644
--- a/server/src/main/java/org/apache/iotdb/db/auth/user/LocalFileUserAccessor.java
+++ b/server/src/main/java/org/apache/iotdb/db/auth/user/LocalFileUserAccessor.java
@@ -78,7 +78,7 @@ public class LocalFileUserAccessor implements IUserAccessor {
       File newProfile = SystemFileFactory.INSTANCE.getFile(
           userDirPath + File.separator + username + IoTDBConstant.PROFILE_SUFFIX + TEMP_SUFFIX);
       if (newProfile.exists() && newProfile.isFile()) {
-        if(!newProfile.renameTo(userProfile)) {
+        if (!newProfile.renameTo(userProfile)) {
           logger.error("New profile renaming not succeed.");
         }
         userProfile = newProfile;
@@ -106,7 +106,17 @@ public class LocalFileUserAccessor implements IUserAccessor {
         roleList.add(userName);
       }
       user.setRoleList(roleList);
-      user.setUseWaterMark(dataInputStream.readInt() != 0);
+
+      // for online upgrading, profile for 0.8.x does not contain waterMark
+      try {
+        user.setUseWaterMark(dataInputStream.readInt() != 0);
+      } catch (EOFException e1) {
+        user.setUseWaterMark(false);
+        try (RandomAccessFile file = new RandomAccessFile(userProfile, "rw")) {
+          file.seek(file.length());
+          file.writeInt(0);
+        }
+      }
       return user;
     } catch (Exception e) {
       throw new IOException(e);
@@ -122,7 +132,8 @@ public class LocalFileUserAccessor implements IUserAccessor {
   public void saveUser(User user) throws IOException {
     File userProfile = SystemFileFactory.INSTANCE.getFile(
         userDirPath + File.separator + user.getName() + IoTDBConstant.PROFILE_SUFFIX + TEMP_SUFFIX);
-    try(BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(userProfile))) {
+    try (BufferedOutputStream outputStream = new BufferedOutputStream(
+        new FileOutputStream(userProfile))) {
       try {
         IOUtils.writeString(outputStream, user.getName(), STRING_ENCODING, encodingBufferLocal);
         IOUtils.writeString(outputStream, user.getPassword(), STRING_ENCODING, encodingBufferLocal);
@@ -144,7 +155,7 @@ public class LocalFileUserAccessor implements IUserAccessor {
               .writeString(outputStream, user.getRoleList().get(i), STRING_ENCODING,
                   encodingBufferLocal);
         }
-        IOUtils.writeInt(outputStream, user.isUseWaterMark()? 1 : 0, encodingBufferLocal);
+        IOUtils.writeInt(outputStream, user.isUseWaterMark() ? 1 : 0, encodingBufferLocal);
         outputStream.flush();
 
       } catch (Exception e) {