smengcl commented on code in PR #11897: URL: https://github.com/apache/ozone/pull/11897#discussion_r4557145984
########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSyncOverwriteWithOMHA.java: ########## @@ -0,0 +1,322 @@ +/* + * 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.ozone; + +import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OFS_URI_SCHEME; +import static org.apache.ozone.test.OzoneTestBase.uniqueObjectName; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.TimeoutException; +import org.apache.hadoop.fs.CommonConfigurationKeysPublic; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdds.client.OzoneQuota; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.cache.CacheKey; +import org.apache.hadoop.hdds.utils.db.cache.CacheValue; +import org.apache.hadoop.ozone.DataTestUtil; +import org.apache.hadoop.ozone.MiniOzoneCluster; +import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl; +import org.apache.hadoop.ozone.OzoneConfigKeys; +import org.apache.hadoop.ozone.client.OzoneBucket; +import org.apache.hadoop.ozone.client.OzoneClient; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.exceptions.OMException; +import org.apache.hadoop.ozone.om.helpers.BucketLayout; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.ratis.OzoneManagerDoubleBuffer; +import org.apache.ozone.test.GenericTestUtils; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Tests hsync and a rejected overwrite commit in OM HA setup. + * + * <p>HDDS-16765: a rejected overwrite commit used to leave OVERWRITTEN_HSYNC_KEY on another writer's + * open entry in the open file table cache until the double buffer flushed and evicted that epoch. + * + * <p>Client sequence (FileSystem API only), bucket namespace quota = 2: + * <pre> + * A: create f, write, hsync (used namespace 1) + * B: create f (overwrite), write (create passes: 1 + 1 <= 2) + * C: create g, close (used namespace 2) + * B: close -> QUOTA_EXCEEDED, the overwrite never takes effect + * A: write, hsync, close -> must still succeed + * </pre> + * + * <p>The same sequence is run in four situations, and each asserts the same outcome: writer A keeps + * its own stream writable and every OM ends up holding what A committed. What they showed before + * the fix: + * <pre> + * no flush lag, repeated rounds -> the window is not hit on timing alone + * every OM flushed beforehand -> passes cleanly + * one follower's flush held -> A sees success, but that follower's RocksDB diverges + * the leader's flush held -> A's close is rejected, although the followers applied it + * </pre> + */ +public class TestHSyncOverwriteWithOMHA { Review Comment: The new unit test in `TestOMKeyCommitRequest` already reproduces this deterministically, and it runs for both OBS and FSO through `TestOMKeyCommitRequestWithFSO`. So I'm not sure we need this class, since it starts another 3-OM cluster. Two of the four cases also don't add much coverage: `testRejectedOverwriteWithoutFlushLag` runs 40 rounds that the Javadoc says are not expected to hit the window, and `testRejectedOverwriteAfterAllOMsFlushed` passed before the fix too. Could we drop this class and rely on the unit test? If you'd like to keep an HA reproduction, keeping only the two flush-held cases would cut most of the runtime. ########## hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyCommitRequest.java: ########## @@ -571,6 +571,47 @@ public void testCommitWithHsyncUsedNamespace() throws Exception { assertEquals(1, bucketInfo.getUsedNamespace()); } + @Test + public void testRejectedOverwriteCommitKeepsHsyncedKeyWritable() throws Exception { Review Comment: nit: in `OMKeyCommitRequest` (OBS) the flag was also put in the cache before `validateAtomicRewrite`, so a rejected atomic rewrite by writer B left the same stale flag on A's entry. This test only covers the quota rejection. Would it be worth adding a small case where B's commit fails the expected data generation check, then A's hsync still returns OK? It would fail on master for OBS and pass with this change. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
