Skip to content

Commit 9f4fb5c

Browse files
committed
HADOOP-13327 add RawLocalFileystem Syncable
Doesn't actually get through as there's a BufferedOutputStream in the way... will need to do something there :) Change-Id: Ib2e4517e266168f3ad106e55ceac987ed443aeec
1 parent 60d3371 commit 9f4fb5c

File tree

7 files changed

+64
-25
lines changed

7 files changed

+64
-25
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.hadoop.classification.InterfaceAudience;
4747
import org.apache.hadoop.classification.InterfaceStability;
4848
import org.apache.hadoop.conf.Configuration;
49+
import org.apache.hadoop.fs.impl.StoreImplementationUtils;
4950
import org.apache.hadoop.fs.permission.FsPermission;
5051
import org.apache.hadoop.io.IOUtils;
5152
import org.apache.hadoop.io.nativeio.NativeIO;
@@ -233,7 +234,8 @@ public FSDataInputStream open(PathHandle fd, int bufferSize)
233234
/*********************************************************
234235
* For create()'s FSOutputStream.
235236
*********************************************************/
236-
class LocalFSFileOutputStream extends OutputStream {
237+
class LocalFSFileOutputStream extends OutputStream
238+
implements Syncable, StreamCapabilities {
237239
private FileOutputStream fos;
238240

239241
private LocalFSFileOutputStream(Path f, boolean append,
@@ -288,6 +290,22 @@ public void write(int b) throws IOException {
288290
throw new FSError(e); // assume native fs error
289291
}
290292
}
293+
294+
@Override
295+
public void hflush() throws IOException {
296+
flush();
297+
}
298+
299+
@Override
300+
public void hsync() throws IOException {
301+
flush();
302+
fos.getFD().sync();
303+
}
304+
305+
@Override
306+
public boolean hasCapability(String capability) {
307+
return StoreImplementationUtils.supportsSyncable(capability);
308+
}
291309
}
292310

293311
@Override

hadoop-common-project/hadoop-common/src/site/markdown/filesystem/outputstream.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,8 @@ local data as can be written to full checksummed blocks of data.
782782
That is, the flush operations are not guaranteed to write all the pending
783783
data until the file is finally closed.
784784

785-
That is, `sync()`, `hsync()` and `hflush()` may not persist all data written
786-
to the stream.
787-
788-
For anyone thinking "this is a violation of this specification" —they are correct.
789-
The local filesystem was intended for testing, rather than production use.
785+
For this reason, the local fileystem accessed via `file://` URLs
786+
does not support syncable.
790787

791788
### <a name="checksummed-fs-issues"></a> Checksummed output streams
792789

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractCreateTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.fs.contract;
2020

21+
import org.apache.hadoop.fs.FSDataInputStream;
2122
import org.apache.hadoop.fs.FSDataOutputStream;
2223
import org.apache.hadoop.fs.FileAlreadyExistsException;
2324
import org.apache.hadoop.fs.FileStatus;
@@ -31,8 +32,10 @@
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

35+
import java.io.FileNotFoundException;
3436
import java.io.IOException;
3537

38+
import static org.apache.hadoop.fs.contract.ContractTestUtils.assertCapabilities;
3639
import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset;
3740
import static org.apache.hadoop.fs.contract.ContractTestUtils.getFileStatusEventually;
3841
import static org.apache.hadoop.fs.contract.ContractTestUtils.skip;
@@ -454,15 +457,22 @@ public void testHSync() throws Throwable {
454457

455458
try (FSDataOutputStream out = fs.create(path, true)) {
456459

457-
boolean doesHFlush = out.hasCapability(
458-
StreamCapabilities.StreamCapability.HFLUSH.getValue());
460+
boolean doesHFlush = out.hasCapability(StreamCapabilities.HFLUSH);
459461
if (doesHFlush) {
460462
out.hflush();
461463
}
462-
assertEquals("hflush support", supportsFlush, doesHFlush);
463-
boolean doesHSync = out.hasCapability(
464-
StreamCapabilities.StreamCapability.HSYNC.getValue());
465-
assertEquals("hsync support", supportsSync, doesHSync);
464+
String[] hflushCapabilities = {
465+
StreamCapabilities.HFLUSH,
466+
};
467+
String[] hsyncCapabilities = {
468+
StreamCapabilities.HSYNC,
469+
};
470+
assertCapabilities(out,
471+
supportsFlush ? hflushCapabilities : null,
472+
supportsFlush ? null : hflushCapabilities);
473+
assertCapabilities(out,
474+
supportsSync ? hsyncCapabilities : null,
475+
supportsSync ? null : hsyncCapabilities);
466476

467477
try {
468478
out.hflush();

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractFSContractTestBase.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ protected void handleRelaxedException(String action,
295295
if (getContract().isSupported(SUPPORTS_STRICT_EXCEPTIONS, false)) {
296296
throw e;
297297
}
298-
LOG.warn("The expected exception {} was not the exception class" +
298+
LOG.warn("The expected exception {} was not the exception class" +
299299
" raised on {}: {}", action , e.getClass(), expectedException, e);
300300
}
301301

@@ -398,13 +398,4 @@ protected String generateAndLogErrorListing(Path src, Path dst) throws
398398
}
399399
return destDirLS;
400400
}
401-
402-
/**
403-
* Get a path from the name of the current test case.
404-
* @return a path based on the test method being executed.
405-
* @throws IOException IO problem
406-
*/
407-
protected Path methodPath() throws IOException {
408-
return path(methodName.getMethodName());
409-
}
410401
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/ContractTestUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,14 +1496,16 @@ public static void assertCapabilities(
14961496
StreamCapabilities source = (StreamCapabilities) stream;
14971497
if (shouldHaveCapabilities != null) {
14981498
for (String shouldHaveCapability : shouldHaveCapabilities) {
1499-
assertTrue("Should have capability: " + shouldHaveCapability,
1499+
assertTrue("Should have capability: " + shouldHaveCapability
1500+
+ " in " + source,
15001501
source.hasCapability(shouldHaveCapability));
15011502
}
15021503
}
15031504

15041505
if (shouldNotHaveCapabilities != null) {
15051506
for (String shouldNotHaveCapability : shouldNotHaveCapabilities) {
1506-
assertFalse("Should not have capability: " + shouldNotHaveCapability,
1507+
assertFalse("Should not have capability: " + shouldNotHaveCapability
1508+
+ " in " + source,
15071509
source.hasCapability(shouldNotHaveCapability));
15081510
}
15091511
}
@@ -1523,7 +1525,8 @@ public static void assertHasPathCapabilities(
15231525

15241526
for (String shouldHaveCapability: capabilities) {
15251527
assertTrue("Should have capability: " + shouldHaveCapability
1526-
+ " under " + path,
1528+
+ " under " + path
1529+
+ " in " + source,
15271530
source.hasPathCapability(path, shouldHaveCapability));
15281531
}
15291532
}

hadoop-common-project/hadoop-common/src/test/resources/contract/localfs.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,14 @@ case sensitivity and permission options are determined at run time from OS type
121121
<value>true</value>
122122
</property>
123123

124+
<property>
125+
<name>fs.contract.supports-settimes</name>
126+
<value>true</value>
127+
</property>
128+
129+
<property>
130+
<name>fs.contract.supports-getfilestatus</name>
131+
<value>true</value>
132+
</property>
133+
124134
</configuration>

hadoop-common-project/hadoop-common/src/test/resources/contract/rawlocal.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@
127127
<value>true</value>
128128
</property>
129129

130+
<property>
131+
<name>fs.contract.supports-hflush</name>
132+
<value>true</value>
133+
</property>
134+
135+
<property>
136+
<name>fs.contract.supports-hsync</name>
137+
<value>true</value>
138+
</property>
139+
130140
</configuration>

0 commit comments

Comments
 (0)