|
@@ -20,9 +20,12 @@ package org.apache.hadoop.fs.s3a;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.contract.AbstractFSContract;
|
|
import org.apache.hadoop.fs.contract.AbstractFSContract;
|
|
import org.apache.hadoop.fs.contract.s3a.S3AContract;
|
|
import org.apache.hadoop.fs.contract.s3a.S3AContract;
|
|
|
|
+import org.apache.hadoop.fs.s3a.s3guard.DirListingMetadata;
|
|
|
|
+import org.apache.hadoop.fs.s3a.s3guard.S3Guard;
|
|
import org.junit.Assume;
|
|
import org.junit.Assume;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
@@ -76,4 +79,65 @@ public class ITestS3GuardListConsistency extends AbstractS3ATestBase {
|
|
// This should fail without S3Guard, and succeed with it.
|
|
// This should fail without S3Guard, and succeed with it.
|
|
assertTrue(list.contains(inconsistentPath));
|
|
assertTrue(list.contains(inconsistentPath));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testListStatusWriteBack() throws Exception {
|
|
|
|
+ Assume.assumeTrue(getFileSystem().hasMetadataStore());
|
|
|
|
+
|
|
|
|
+ Configuration conf;
|
|
|
|
+ Path directory = path("ListStatusWriteBack");
|
|
|
|
+
|
|
|
|
+ // Create a FileSystem that is S3-backed only
|
|
|
|
+ conf = createConfiguration();
|
|
|
|
+ conf.setBoolean("fs.s3a.impl.disable.cache", true);
|
|
|
|
+ conf.set(Constants.S3_METADATA_STORE_IMPL,
|
|
|
|
+ Constants.S3GUARD_METASTORE_NULL);
|
|
|
|
+ FileSystem noS3Guard = FileSystem.get(directory.toUri(), conf);
|
|
|
|
+
|
|
|
|
+ // Create a FileSystem with S3Guard and write-back disabled
|
|
|
|
+ conf = createConfiguration();
|
|
|
|
+ S3ATestUtils.maybeEnableS3Guard(conf);
|
|
|
|
+ conf.setBoolean("fs.s3a.impl.disable.cache", true);
|
|
|
|
+ conf.setBoolean(Constants.METADATASTORE_AUTHORITATIVE, false);
|
|
|
|
+ FileSystem noWriteBack = FileSystem.get(directory.toUri(), conf);
|
|
|
|
+
|
|
|
|
+ // Create a FileSystem with S3Guard and write-back enabled
|
|
|
|
+ conf = createConfiguration();
|
|
|
|
+ S3ATestUtils.maybeEnableS3Guard(conf);
|
|
|
|
+ conf.setBoolean("fs.s3a.impl.disable.cache", true);
|
|
|
|
+ conf.setBoolean(Constants.METADATASTORE_AUTHORITATIVE, true);
|
|
|
|
+ FileSystem yesWriteBack = FileSystem.get(directory.toUri(), conf);
|
|
|
|
+
|
|
|
|
+ // Create a directory on S3 only
|
|
|
|
+ noS3Guard.mkdirs(new Path(directory, "123"));
|
|
|
|
+ // Create a directory on metastore only
|
|
|
|
+ noWriteBack.mkdirs(new Path(directory, "XYZ"));
|
|
|
|
+
|
|
|
|
+ FileStatus[] fsResults;
|
|
|
|
+ DirListingMetadata mdResults;
|
|
|
|
+
|
|
|
|
+ // FS should return both
|
|
|
|
+ fsResults = noWriteBack.listStatus(directory);
|
|
|
|
+ assertTrue("Unexpected number of results from filesystem. " +
|
|
|
|
+ "Should have /XYZ and /123: " + fsResults.toString(),
|
|
|
|
+ fsResults.length == 2);
|
|
|
|
+
|
|
|
|
+ // Metastore without write-back should still only contain 1
|
|
|
|
+ mdResults = S3Guard.getMetadataStore(noWriteBack).listChildren(directory);
|
|
|
|
+ assertTrue("Unexpected number of results from metastore. " +
|
|
|
|
+ "Metastore should only know about /XYZ: " + mdResults.toString(),
|
|
|
|
+ mdResults.numEntries() == 1);
|
|
|
|
+
|
|
|
|
+ // FS should return both (and will write it back)
|
|
|
|
+ fsResults = yesWriteBack.listStatus(directory);
|
|
|
|
+ assertTrue("Unexpected number of results from filesystem. " +
|
|
|
|
+ "Should have /XYZ and /123: " + fsResults.toString(),
|
|
|
|
+ fsResults.length == 2);
|
|
|
|
+
|
|
|
|
+ // Metastore should not contain both
|
|
|
|
+ mdResults = S3Guard.getMetadataStore(yesWriteBack).listChildren(directory);
|
|
|
|
+ assertTrue("Unexpected number of results from metastore. " +
|
|
|
|
+ "Should have /XYZ and /123: " + mdResults.toString(),
|
|
|
|
+ mdResults.numEntries() == 2);
|
|
|
|
+ }
|
|
}
|
|
}
|