1
0

Change from deprecated closeQuietly to try with resources

This commit is contained in:
Danny Chen
2017-05-31 17:41:27 -07:00
committed by prazanna
parent 36fa6f66ac
commit c192dd60b4
2 changed files with 12 additions and 25 deletions

View File

@@ -18,7 +18,6 @@ package com.uber.hoodie.common.table.timeline;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
import com.uber.hoodie.common.table.HoodieTableMetaClient; import com.uber.hoodie.common.table.HoodieTableMetaClient;
import com.uber.hoodie.common.table.HoodieTimeline; import com.uber.hoodie.common.table.HoodieTimeline;
import com.uber.hoodie.common.util.FSUtils; import com.uber.hoodie.common.util.FSUtils;
@@ -303,16 +302,10 @@ public class HoodieActiveTimeline extends HoodieDefaultTimeline {
} }
protected Optional<byte[]> readDataFromPath(Path detailPath) { protected Optional<byte[]> readDataFromPath(Path detailPath) {
FSDataInputStream is = null; try (FSDataInputStream is = fs.open(detailPath)) {
try {
is = fs.open(detailPath);
return Optional.of(IOUtils.toByteArray(is)); return Optional.of(IOUtils.toByteArray(is));
} catch (IOException e) { } catch (IOException e) {
throw new HoodieIOException("Could not read commit details from " + detailPath, e); throw new HoodieIOException("Could not read commit details from " + detailPath, e);
} finally {
if (is != null) {
Closeables.closeQuietly(is);
}
} }
} }

View File

@@ -16,7 +16,6 @@
package com.uber.hoodie.common.table.timeline; package com.uber.hoodie.common.table.timeline;
import com.google.common.io.Closeables;
import com.uber.hoodie.common.table.HoodieTimeline; import com.uber.hoodie.common.table.HoodieTimeline;
import com.uber.hoodie.common.util.FSUtils; import com.uber.hoodie.common.util.FSUtils;
import com.uber.hoodie.exception.HoodieIOException; import com.uber.hoodie.exception.HoodieIOException;
@@ -56,23 +55,18 @@ public class HoodieArchivedTimeline extends HoodieDefaultTimeline {
public HoodieArchivedTimeline(FileSystem fs, String metaPath) { public HoodieArchivedTimeline(FileSystem fs, String metaPath) {
// Read back the commits to make sure // Read back the commits to make sure
Path archiveLogPath = getArchiveLogPath(metaPath); Path archiveLogPath = getArchiveLogPath(metaPath);
try { try (SequenceFile.Reader reader =
SequenceFile.Reader reader = new SequenceFile.Reader(fs.getConf(), SequenceFile.Reader.file(archiveLogPath))) {
new SequenceFile.Reader(fs.getConf(), SequenceFile.Reader.file(archiveLogPath)); Text key = new Text();
try { Text val = new Text();
Text key = new Text(); while (reader.next(key, val)) {
Text val = new Text(); // TODO - limit the number of commits loaded in memory. this could get very large.
while (reader.next(key, val)) { // This is okay because only tooling will load the archived commit timeline today
// TODO - limit the number of commits loaded in memory. this could get very large. readCommits.put(key.toString(), Arrays.copyOf(val.getBytes(), val.getLength()));
// This is okay because only tooling will load the archived commit timeline today
readCommits.put(key.toString(), Arrays.copyOf(val.getBytes(), val.getLength()));
}
this.instants = readCommits.keySet().stream().map(
s -> new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, s)).collect(
Collectors.toList());
} finally {
Closeables.closeQuietly(reader);
} }
this.instants = readCommits.keySet().stream().map(
s -> new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, s)).collect(
Collectors.toList());
} catch (IOException e) { } catch (IOException e) {
throw new HoodieIOException( throw new HoodieIOException(
"Could not load archived commit timeline from path " + archiveLogPath, e); "Could not load archived commit timeline from path " + archiveLogPath, e);