You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "smengcl (via GitHub)" <gi...@apache.org> on 2024/08/14 00:13:46 UTC
[PR] HDDS-11184. [hsync] Add a client config to limit write concurrency on the same key [ozone]
smengcl opened a new pull request, #7073:
URL: https://github.com/apache/ozone/pull/7073
## What changes were proposed in this pull request?
Since HDDS-9844, writes on a single key are allowed to be interleaved outside the critical section. This PR aims to add a config to be able to restore the strictly serialized behavior before HDDS-9844 is merged as a safety measure.
```
ozone.client.key.write.concurrency
Maximum concurrent writes allowed on each key.
Defaults to 1 which matches the behavior before HDDS-9844.
For unlimited write concurrency, set this to -1 or any negative integer value.
```
### TODO
- [ ] Check if other test cases like `TestHSync` would need the `ozone.client.key.write.concurrency` set to unlimited.
- [ ] Could add more `TestKeyOutputStream` test cases around `flush()` and other write ops.
- [ ] Could add `TestKeyOutputStreamSemaphore`.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-11184
## How was this patch tested?
- Added UT
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-11184. [hsync] Add a client config to limit write concurrency on the same key [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang commented on code in PR #7073:
URL: https://github.com/apache/ozone/pull/7073#discussion_r1717347861
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java:
##########
@@ -200,24 +213,30 @@ public synchronized void write(int b) throws IOException {
@Override
public void write(byte[] b, int off, int len)
throws IOException {
- checkNotClosed();
- if (b == null) {
- throw new NullPointerException();
- }
- if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
- || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- }
- if (len == 0) {
- return;
- }
- synchronized (this) {
- handleWrite(b, off, len, false);
- writeOffset += len;
+ try {
+ getRequestSemaphore().acquire();
+ checkNotClosed();
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
+ || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len == 0) {
+ return;
+ }
+
+ synchronized (this) {
+ handleWrite(b, off, len, false);
+ writeOffset += len;
+ }
+ } finally {
+ getRequestSemaphore().release();
}
}
Review Comment:
```suggestion
@VisibleForTesting
```
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-11184. [hsync] Add a client config to limit write concurrency on the same key [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang merged PR #7073:
URL: https://github.com/apache/ozone/pull/7073
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-11184. [hsync] Add a client config to limit write concurrency on the same key [ozone]
Posted by "smengcl (via GitHub)" <gi...@apache.org>.
smengcl commented on PR #7073:
URL: https://github.com/apache/ozone/pull/7073#issuecomment-2294715690
Thanks @jojochuang for reviewing and merging this!
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-11184. [hsync] Add a client config to limit write concurrency on the same key [ozone]
Posted by "smengcl (via GitHub)" <gi...@apache.org>.
smengcl commented on code in PR #7073:
URL: https://github.com/apache/ozone/pull/7073#discussion_r1717597217
##########
hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/io/TestKeyOutputStream.java:
##########
@@ -0,0 +1,126 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ozone.client.io;
+
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.slf4j.event.Level;
+
+import java.io.IOException;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests KeyOutputStream.
+ * This is a unit test meant to verify specific behaviors of KeyOutputStream.
+ */
+public class TestKeyOutputStream {
+
+ @BeforeAll
+ static void init() {
+ GenericTestUtils.setLogLevel(KeyOutputStreamSemaphore.LOG, Level.DEBUG);
+ }
+
+ @Test
+ void testConcurrentWriteLimitOne() throws Exception {
+ // Verify the semaphore is working to a limited the number of concurrent writes allowed.
Review Comment:
```suggestion
// Verify the semaphore is working to limit the number of concurrent writes allowed.
```
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-11184. [hsync] Add a client config to limit write concurrency on the same key [ozone]
Posted by "smengcl (via GitHub)" <gi...@apache.org>.
smengcl commented on code in PR #7073:
URL: https://github.com/apache/ozone/pull/7073#discussion_r1717586024
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java:
##########
@@ -200,24 +213,30 @@ public synchronized void write(int b) throws IOException {
@Override
public void write(byte[] b, int off, int len)
throws IOException {
- checkNotClosed();
- if (b == null) {
- throw new NullPointerException();
- }
- if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
- || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- }
- if (len == 0) {
- return;
- }
- synchronized (this) {
- handleWrite(b, off, len, false);
- writeOffset += len;
+ try {
+ getRequestSemaphore().acquire();
+ checkNotClosed();
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
+ || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len == 0) {
+ return;
+ }
+
+ synchronized (this) {
+ handleWrite(b, off, len, false);
+ writeOffset += len;
+ }
+ } finally {
+ getRequestSemaphore().release();
}
}
-
- private void handleWrite(byte[] b, int off, long len, boolean retry)
+ @VisibleForTesting
Review Comment:
```suggestion
@VisibleForTesting
```
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org