ivanzlenko commented on code in PR #5808:
URL: https://github.com/apache/ignite-3/pull/5808#discussion_r2097557515


##########
modules/rocksdb-common/src/test/java/org/apache/ignite/internal/rocksdb/flush/RocksDbFlusherTest.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.ignite.internal.rocksdb.flush;
+
+import static java.util.concurrent.CompletableFuture.allOf;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.util.IgniteUtils.closeAll;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.components.NoOpLogSyncer;
+import org.apache.ignite.internal.testframework.ExecutorServiceExtension;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.internal.testframework.InjectExecutorService;
+import org.apache.ignite.internal.util.ByteUtils;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.rocksdb.Options;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+
+@ExtendWith(ExecutorServiceExtension.class)
+class RocksDbFlusherTest extends IgniteAbstractTest {
+    private RocksDbFlusher flusher;
+
+    private Options dbOptions;
+
+    private RocksDB db;
+
+    private final CompletableFuture<Throwable> failureProcessorError = new 
CompletableFuture<>();
+
+    @BeforeEach
+    void setUp(
+            @InjectExecutorService ScheduledExecutorService scheduledExecutor,
+            @InjectExecutorService ExecutorService executor
+    ) throws RocksDBException {
+        flusher = new RocksDbFlusher(
+                "RocksDbFlusherTest",
+                new IgniteSpinBusyLock(),
+                scheduledExecutor,
+                executor,
+                () -> 0,
+                new NoOpLogSyncer(),
+                failureCtx -> 
failureProcessorError.completeExceptionally(failureCtx.error()),
+                () -> {}
+        );
+
+        dbOptions = new Options()
+                .setCreateIfMissing(true)
+                .setListeners(List.of(flusher.listener()));
+
+        db = RocksDB.open(dbOptions, workDir.toString());
+
+        flusher.init(db, List.of(db.getDefaultColumnFamily()));
+
+        setUpLogFilter();
+    }
+
+    /**
+     * Sets a filter that removes warning messages produced by the flusher. 
This is needed, because the CI server has been configured to
+     * fail the build if these warnings are found in the logs. In this test we 
intentionally create a situation where such warnings will
+     * be produced.
+     */
+    private static void setUpLogFilter() {
+        var filter = new AbstractFilter() {
+            @Override
+            public Result filter(LogEvent event) {
+                if (event.getMessage().getFormattedMessage().contains("Unable 
to perform explicit flush, will try again.")) {
+                    return Result.DENY;
+                }
+
+                return Result.NEUTRAL;
+            }
+        };
+
+        var context = (LoggerContext) LogManager.getContext(false);
+
+        LoggerConfig loggerConfig = 
context.getConfiguration().getLoggerConfig(RocksDbFlusher.class.getName());
+
+        loggerConfig.addFilter(filter);
+
+        context.updateLoggers();
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        closeAll(flusher::stop, db, dbOptions);
+    }
+
+    @Test
+    void testFlushRetryOnWriteThrottling() {
+        CompletableFuture<?>[] flushFutures = IntStream.range(0, 200)
+                .mapToObj(ByteUtils::intToBytes)
+                .map(bytes -> {
+                    try {
+                        // Wait a little bit, because otherwise batching still 
works and less flushes will be issued.
+                        Thread.sleep(1);
+
+                        db.put(bytes, bytes);
+                    } catch (RocksDBException | InterruptedException e) {
+                        throw new AssertionError(e);
+                    }
+
+                    return flusher.awaitFlush(true);

Review Comment:
   Let'd move it into a separate method



##########
modules/rocksdb-common/src/main/java/org/apache/ignite/internal/rocksdb/flush/RocksDbFlusher.java:
##########
@@ -230,7 +235,13 @@ public void run() {
                         db.flush(flushOptions, columnFamilyHandles);
                     }
                 } catch (RocksDBException e) {
-                    failureProcessor.process(new FailureContext(e, "Error 
occurred during the explicit flush"));
+                    if (e.getStatus().getCode() == Code.TryAgain) {
+                        LOG.warn("Unable to perform explicit flush, will try 
again.", e);

Review Comment:
   Feels like it could be info



##########
modules/rocksdb-common/src/main/java/org/apache/ignite/internal/rocksdb/flush/RocksDbFlusher.java:
##########
@@ -230,7 +235,13 @@ public void run() {
                         db.flush(flushOptions, columnFamilyHandles);
                     }
                 } catch (RocksDBException e) {
-                    failureProcessor.process(new FailureContext(e, "Error 
occurred during the explicit flush"));
+                    if (e.getStatus().getCode() == Code.TryAgain) {
+                        LOG.warn("Unable to perform explicit flush, will try 
again.", e);

Review Comment:
   Or even debug



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to