More refactoring, don't open file handles until necessary.
diff --git a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java
index f47f5a9..2b0a2e7 100644
--- a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java
+++ b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java
@@ -67,8 +67,6 @@
channel.close();
resultState.readClose();
}
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
} catch (HyracksDataException e) {
throw new RuntimeException(e);
}
diff --git a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/ResultState.java b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/ResultState.java
index a91db17..550e0a0 100644
--- a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/ResultState.java
+++ b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/ResultState.java
@@ -110,20 +110,14 @@
notifyAll();
}
- public synchronized void readOpen() throws InterruptedException, HyracksDataException {
- while (fileRef == null) {
- wait();
- }
- readFileHandle = ioManager.open(fileRef, IIOManager.FileReadWriteMode.READ_ONLY,
- IIOManager.FileSyncMode.METADATA_ASYNC_DATA_ASYNC);
+ public synchronized void readOpen() {
+ // It is a noOp for now, leaving here to keep the API stable for future usage.
}
- public synchronized void readClose() throws InterruptedException, HyracksDataException {
- while (fileRef == null) {
- wait();
+ public synchronized void readClose() throws HyracksDataException {
+ if (readFileHandle != null) {
+ ioManager.close(readFileHandle);
}
- readFileHandle = ioManager.open(fileRef, IIOManager.FileReadWriteMode.READ_ONLY,
- IIOManager.FileSyncMode.METADATA_ASYNC_DATA_ASYNC);
}
public synchronized long read(DatasetMemoryManager datasetMemoryManager, long offset, ByteBuffer buffer)
@@ -144,6 +138,9 @@
}
if (offset < persistentSize) {
+ if (readFileHandle == null) {
+ initReadFileHandle();
+ }
readSize = ioManager.syncRead(readFileHandle, offset, buffer);
}
@@ -243,4 +240,16 @@
}
return page;
}
+
+ private void initReadFileHandle() throws HyracksDataException {
+ while (fileRef == null) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new HyracksDataException(e);
+ }
+ }
+ readFileHandle = ioManager.open(fileRef, IIOManager.FileReadWriteMode.READ_ONLY,
+ IIOManager.FileSyncMode.METADATA_ASYNC_DATA_ASYNC);
+ }
}
\ No newline at end of file