Skip to content

Commit

Permalink
[IOTDB-303]fix user profile when online upgrading (#555)
Browse files Browse the repository at this point in the history
* [fix] upgrade *.profile to 0.9.0
  • Loading branch information
EJTTianYu authored and qiaojialin committed Nov 14, 2019
1 parent 41e7e5f commit 3043acf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
39 changes: 39 additions & 0 deletions 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. |



Expand Up @@ -78,7 +78,7 @@ public User loadUser(String username) throws IOException {
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;
Expand Down Expand Up @@ -106,7 +106,17 @@ public User loadUser(String username) throws IOException {
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);
Expand All @@ -122,7 +132,8 @@ public User loadUser(String username) throws IOException {
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);
Expand All @@ -144,7 +155,7 @@ public void saveUser(User user) throws IOException {
.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) {
Expand Down

0 comments on commit 3043acf

Please sign in to comment.