steveloughran commented on a change in pull request #1707: HADOOP-16697. 
Tune/audit auth mode
URL: https://github.com/apache/hadoop/pull/1707#discussion_r354277577
 
 

 ##########
 File path: 
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/ITestDynamoDBMetadataStoreAuthoritativeMode.java
 ##########
 @@ -0,0 +1,558 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a.s3guard;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+
+import org.assertj.core.api.Assertions;
+import org.junit.AfterClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.LocatedFileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.RemoteIterator;
+import org.apache.hadoop.fs.contract.ContractTestUtils;
+import org.apache.hadoop.fs.s3a.AbstractS3ATestBase;
+import org.apache.hadoop.fs.s3a.S3AFileStatus;
+import org.apache.hadoop.fs.s3a.S3AFileSystem;
+import org.apache.hadoop.fs.s3a.S3ATestUtils;
+import org.apache.hadoop.fs.s3a.Tristate;
+import org.apache.hadoop.fs.s3a.impl.StoreContext;
+import org.apache.hadoop.io.IOUtils;
+
+import static org.apache.hadoop.fs.contract.ContractTestUtils.rm;
+import static org.apache.hadoop.fs.contract.ContractTestUtils.writeTextFile;
+import static org.apache.hadoop.fs.s3a.Constants.AUTHORITATIVE_PATH;
+import static org.apache.hadoop.fs.s3a.Constants.METADATASTORE_AUTHORITATIVE;
+import static 
org.apache.hadoop.fs.s3a.Constants.S3GUARD_DDB_BACKGROUND_SLEEP_MSEC_KEY;
+import static org.apache.hadoop.fs.s3a.Constants.S3_METADATA_STORE_IMPL;
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.assume;
+import static 
org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
+import static org.apache.hadoop.fs.s3a.S3AUtils.applyLocatedFiles;
+import static org.apache.hadoop.fs.s3a.Statistic.OBJECT_LIST_REQUESTS;
+import static 
org.apache.hadoop.fs.s3a.Statistic.S3GUARD_METADATASTORE_AUTHORITATIVE_DIRECTORIES_UPDATED;
+import static 
org.apache.hadoop.fs.s3a.s3guard.PathMetadataDynamoDBTranslation.emptyDirectoryMarker;
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
+
+/**
+ * Test to verify the expected behaviour of DynamoDB and authoritative mode.
+ * The main testFS is non-auth; we also create a test FS which runs in auth 
mode.
+ * Making the default FS non-auth means that test path cleanup in the
+ * superclass isn't going to get mislead by anything authoritative.
+ *
+ * For performance boosting we demand create the auth FS and its test
+ * paths on the first test setup().
+ * This also fixes the auth/nonauth paths so that a specific
+ * bit of the FS is expected to be auth in the FS.
+ *
+ * This test is designed to run in parallel mode with other tests which
+ * may or may not be auth mode.
+ *
+ * It shouldn't make any difference -tests here simply must not make
+ * any assumptions about the state of any path outside the test tree.
+ */
+@SuppressWarnings("StaticNonFinalField")
+public class ITestDynamoDBMetadataStoreAuthoritativeMode
+    extends AbstractS3ATestBase {
+
+  private static final Logger LOG = LoggerFactory.getLogger(
+      ITestDynamoDBMetadataStoreAuthoritativeMode.class);
+
+  private StoreContext storeContext;
+
+  private String fsUriStr;
+
+  private DynamoDBMetadataStore metastore;
+
+  /**
+   * Authoritative FS.
+   */
+  private static S3AFileSystem authFS;
+
+  /**
+   * The unguarded file system.
+   */
+  private static S3AFileSystem unguardedFS;
+
+  private static Path basePath;
+
+  private static Path authPath;
+
+  private static Path nonauthPath;
+
+  private Path methodAuthPath;
+
+  private Path methodNonauthPath;
+
+  private AuthoritativeAuditOperation auditor;
+
+  private Path dir;
+
+  private Path dirFile;
+
+  @AfterClass
+  public static void closeFileSystems() {
+    IOUtils.cleanupWithLogger(LOG, authFS, unguardedFS);
+  }
+
+  @Override
+  protected Configuration createConfiguration() {
+    Configuration conf = super.createConfiguration();
+    removeBaseAndBucketOverrides(conf,
+        S3GUARD_DDB_BACKGROUND_SLEEP_MSEC_KEY,
+        METADATASTORE_AUTHORITATIVE,
+        AUTHORITATIVE_PATH);
+    conf.setTimeDuration(
+        S3GUARD_DDB_BACKGROUND_SLEEP_MSEC_KEY,
+        0,
+        TimeUnit.MILLISECONDS);
+    return conf;
+  }
+
+  @Override
+  public void setup() throws Exception {
+    super.setup();
+    S3AFileSystem fs = getFileSystem();
+    Configuration conf = fs.getConf();
+    S3ATestUtils.assumeS3GuardState(true, conf);
+    storeContext = fs.createStoreContext();
+    assume("Filesystem isn't running DDB",
+        storeContext.getMetadataStore() instanceof DynamoDBMetadataStore);
+    metastore = (DynamoDBMetadataStore) storeContext.getMetadataStore();
+    URI fsURI = storeContext.getFsURI();
+    fsUriStr = fsURI.toString();
+    if (!fsUriStr.endsWith("/")) {
+      fsUriStr = fsUriStr + "/";
+    }
+    auditor = new AuthoritativeAuditOperation(storeContext,
+        metastore, true);
+
+
+    if (authFS == null) {
+      // creating the test stores
+      basePath = path("base");
+      authPath = new Path(basePath, "auth");
+      nonauthPath = new Path(basePath, "nonauth");
+      final Configuration authconf = new Configuration(conf);
+      final URI uri = authPath.toUri();
+      authconf.set(AUTHORITATIVE_PATH, uri.toString());
+      authconf.setBoolean(METADATASTORE_AUTHORITATIVE, true);
+      authFS = (S3AFileSystem) FileSystem.newInstance(uri, authconf);
+
+      // and create the unguarded at the same time
+      final Configuration unguardedConf = new Configuration(conf);
+      removeBaseAndBucketOverrides(unguardedConf,
+          S3_METADATA_STORE_IMPL);
+      unguardedFS = (S3AFileSystem) FileSystem.newInstance(uri, unguardedConf);
+    }
+    cleanupMethodPaths();
+    dir = new Path(methodAuthPath, "dir");
+    dirFile = new Path(dir, "file");
+  }
+
+  @Override
+  public void teardown() throws Exception {
+    try {
+      cleanupMethodPaths();
+    } catch (IOException ignored) {
+    }
+    super.teardown();
+  }
+
+  /**
+   * Clean up from other test runs which halted.
+   * Uses the authfs; no-op if null.
+   * @throws IOException Failure
+   */
+  private void cleanupMethodPaths() throws IOException {
+    S3AFileSystem fs = authFS;
+    if (fs != null) {
+      methodAuthPath = new Path(authPath, getMethodName());
+      fs.delete(methodAuthPath, true);
+      methodNonauthPath = new Path(nonauthPath, getMethodName());
+      fs.delete(methodNonauthPath, true);
+    }
+  }
+
+  @Test
+  public void testEmptyDirMarkerIsAuth() {
+    final S3AFileStatus st = new S3AFileStatus(true, dir, "root");
+    final DDBPathMetadata md = (DDBPathMetadata) emptyDirectoryMarker(st);
+    Assertions.assertThat(md)
+        .describedAs("Metadata %s", md)
+        .matches(DDBPathMetadata::isAuthoritativeDir, "is auth dir")
+        .matches(d -> d.isEmptyDirectory() == Tristate.TRUE,
+            "isEmptyDirectory");
+  }
+
+  @Test
+  @Ignore("Needs mkdir to be authoritative")
 
 Review comment:
   yes, filed JIRA and referenced., I will not fix here as the PR is big enough 
already

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to