HDFS-11805. Ensure LevelDB DBIterator is closed. Contributed by Chen Liang.

This commit is contained in:
Xiaoyu Yao 2017-05-14 06:06:58 -07:00 committed by Owen O'Malley
parent b592df6413
commit a6013e2b5b
2 changed files with 45 additions and 44 deletions

View File

@ -74,7 +74,6 @@ import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICERPC_HA
import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICERPC_HANDLER_COUNT_KEY;
import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICE_LEVELDB_PATH_DEFAULT;
import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICE_LEVELDB_PATH_KEY;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT;
/**
* The main entry point of CBlock operations, ALL the CBlock operations
@ -269,8 +268,8 @@ public class CBlockManager implements CBlockServiceProtocol,
levelDBStore.delete(key);
}
public void readFromPersistentStore() {
DBIterator iter = levelDBStore.getIterator();
public void readFromPersistentStore() throws IOException {
try (DBIterator iter = levelDBStore.getIterator()) {
iter.seekToFirst();
while (iter.hasNext()) {
Map.Entry<byte[], byte[]> entry = iter.next();
@ -284,6 +283,7 @@ public class CBlockManager implements CBlockServiceProtocol,
}
}
}
}
@Override
public synchronized VolumeInfo infoVolume(String userName, String volumeName

View File

@ -452,7 +452,7 @@ public final class OzoneMetadataManager {
String prevKey = args.getPrevKey();
int maxCount = args.getMaxKeys();
String userName = null;
DBIterator iterator = this.userDB.getDB().iterator();
try (DBIterator iterator = this.userDB.getDB().iterator()) {
if (prevKey != null) {
// Format is username/volumeName
@ -486,12 +486,13 @@ public final class OzoneMetadataManager {
throw ErrorTable.newError(ErrorTable.USER_NOT_FOUND, args.getArgs());
}
returnSet.getVolumes().addAll(
getFilteredVolumes(volumeList, prefix, prevKey, count).getVolumes());
returnSet.getVolumes().addAll(getFilteredVolumes(
volumeList, prefix, prevKey, count).getVolumes());
count = maxCount - returnSet.getVolumes().size();
}
return returnSet;
}
}
/**
* Returns the first user name from the UserDB.