Skip to content

Commit

Permalink
HBASE-22890 Verify the file integrity in persistent IOEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoBQ committed Sep 18, 2019
1 parent e8ea5f1 commit b4d4aa5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,10 @@ private void retrieveFromFile(int[] bucketSizes) throws IOException,
"Attempt to restore non-persistent cache mappings!");
ois = new ObjectInputStream(new FileInputStream(persistencePath));
// there are two situations that can cause verification to fail
if (!((FileIOEngine) ioEngine).verifyFileIntegrity(persistencePath, ois)) {
if (!((PersistentIOEngine) ioEngine).verifyFileIntegrity(persistencePath, ois)) {
// 1. persistent file is old version, it's not support verification,
// so reopen ObjectInputStream and read the persistent file from head
if (((FileIOEngine) ioEngine).isOldVersion()) {
if (((PersistentIOEngine) ioEngine).isOldVersion()) {
ois.close();
ois = new ObjectInputStream(new FileInputStream(persistencePath));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public FileIOEngine(String algorithmName, String persistentPath,
* @return true if verify successfully
*/
@Override
public boolean verifyFileIntegrity(String persistentPath, ObjectInputStream ois) throws IOException {
public boolean verifyFileIntegrity(String persistentPath, ObjectInputStream ois)
throws IOException {
try {
byte[] PBMagic = new byte[ProtobufUtil.PB_MAGIC.length];
ois.read(PBMagic);
Expand Down Expand Up @@ -148,7 +149,7 @@ private void init() throws IOException {

/**
* Delete cache file and reinitialized the FileIOEngine
* @throws IOException
* @throws IOException the IOException
*/
private void reinit() throws IOException {
shutdown();
Expand Down

0 comments on commit b4d4aa5

Please sign in to comment.