Vladsz83 commented on a change in pull request #8159:
URL: https://github.com/apache/ignite/pull/8159#discussion_r475494815
##########
File path:
modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/DataGenerationApplication.java
##########
@@ -20,27 +20,103 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.internal.NodeStoppingException;
import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
/**
*
*/
public class DataGenerationApplication extends IgniteAwareApplication {
+ /** Logger. */
+ protected static final Logger log =
LogManager.getLogger(DataGenerationApplication.class.getName());
+
+ /** */
+ private static final long DATAGEN_NOTIFY_INTERVAL_NANO = 1500 * 1000000L;
+
+ /** */
+ private static final int DATAGEN_NOTIFY_INTERVAL_AMOUNT = 10_000;
+
+ /** */
+ private static final int DELAYED_INITIALIZATION_AMOUNT = 10_000;
+
/** {@inheritDoc} */
@Override protected void run(JsonNode jsonNode) {
- log.info("Creating cache...");
+ String cacheName = jsonNode.get("cacheName").asText();
+ boolean infinite = jsonNode.hasNonNull("infinite") &&
jsonNode.get("infinite").asBoolean();
+ boolean optimized = !jsonNode.hasNonNull("optimized") ||
jsonNode.get("optimized").asBoolean();
+ int range = jsonNode.get("range").asInt();
- IgniteCache<Integer, Integer> cache =
ignite.createCache(jsonNode.get("cacheName").asText());
+ if (infinite) {
+ log.info("Generating data in background...");
- try (IgniteDataStreamer<Integer, Integer> stmr =
ignite.dataStreamer(cache.getName())) {
- for (int i = 0; i < jsonNode.get("range").asInt(); i++) {
- stmr.addData(i, i);
+ while (active()) {
+ generateData(cacheName, range, true, optimized, true);
- if (i % 10_000 == 0)
- log.info("Streamed " + i + " entries");
+ // Delayed initialization for small data amount ( <
DELAYED_INITIALIZATION_AMOUNT ).
+ if (!inited())
+ markInitialized();
}
+
+ log.info("Background data generation finished.");
+
+ markFinished();
}
+ else {
+ log.info("Generating data...");
+
+ generateData(cacheName, range, false, optimized, false);
+
+ log.info("Data generation finished. Generated " + range + "
entries.");
+
+ markSyncExecutionComplete();
+ }
+ }
+
+ /** */
+ private void generateData(String cacheName, int range, boolean
delayedInit, boolean optimized, boolean overwrite) {
+ long notifyTime = System.nanoTime();
- markSyncExecutionComplete();
+ int streamed = 0;
+
+ if (log.isDebugEnabled())
+ log.debug("Creating cache...");
+
+ IgniteCache<Integer, Integer> cache =
ignite.getOrCreateCache(cacheName);
+
+ try (IgniteDataStreamer<Integer, Integer> streamer =
ignite.dataStreamer(cacheName)) {
Review comment:
The reason is simplier code. If/ try-catch witch finally-close.
----------------------------------------------------------------
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:
[email protected]