From 6a31852713fb6a07a98eb0153a05d9059a5896fb Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Mon, 2 Sep 2024 15:56:07 +0100 Subject: [PATCH 1/5] Added name to pom.xml --- pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 865a4c2..6ec640b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,9 @@ 1.7-SNAPSHOT jar + + YDB JDBC Importer + UTF-8 1.8 @@ -190,4 +193,4 @@ - \ No newline at end of file + From 4b95c87a8856c50d23e81c0c3f00efb0b63f9ab8 Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Mon, 2 Sep 2024 15:57:03 +0100 Subject: [PATCH 2/5] Updated logger pattern --- src/main/resources/log4j2.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 778f684..08f65a0 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -2,7 +2,7 @@ - + @@ -12,4 +12,4 @@ - \ No newline at end of file + From 61afc198ca6383c5d19babc78cc254ffeef5c2b0 Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Mon, 2 Sep 2024 16:02:35 +0100 Subject: [PATCH 3/5] Hide warnings on JDK9+ builds --- pom.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pom.xml b/pom.xml index 6ec640b..60a96bd 100644 --- a/pom.xml +++ b/pom.xml @@ -131,6 +131,24 @@ + + jdk8-bootstrap + + [9 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 8 + + + + + release-profile From a72ad6cdf58389a0fe844db1eda416608a2a7077 Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Mon, 2 Sep 2024 16:18:48 +0100 Subject: [PATCH 4/5] Generare app version by maven --- pom.xml | 17 +++++++++++ .../java/tech/ydb/importer/YdbImporter.java | 29 ++++++++++++++----- .../resources/importer_version.properties | 1 + 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/importer_version.properties diff --git a/pom.xml b/pom.xml index 60a96bd..667e963 100644 --- a/pom.xml +++ b/pom.xml @@ -130,6 +130,23 @@ test + + + + src/main/resources + + *.properties + + true + + + src/main/resources + + *.properties + + + + jdk8-bootstrap diff --git a/src/main/java/tech/ydb/importer/YdbImporter.java b/src/main/java/tech/ydb/importer/YdbImporter.java index 272ecba..2f44268 100644 --- a/src/main/java/tech/ydb/importer/YdbImporter.java +++ b/src/main/java/tech/ydb/importer/YdbImporter.java @@ -2,6 +2,8 @@ import java.io.BufferedWriter; import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.sql.Connection; @@ -9,13 +11,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import tech.ydb.importer.config.ImporterConfig; import tech.ydb.importer.config.JdomHelper; +import static tech.ydb.importer.config.JdomHelper.isBlank; import tech.ydb.importer.source.AnyTableLister; import tech.ydb.importer.source.SourceCP; import tech.ydb.importer.source.TableMapList; @@ -30,18 +37,12 @@ import tech.ydb.table.values.StructType; import tech.ydb.table.values.Type; -import static tech.ydb.importer.config.JdomHelper.isBlank; - /** * * @author zinal */ public class YdbImporter { - - private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(YdbImporter.class); - - // X.Y[-SNAPSHOT] - public static final String VERSION = "1.7-SNAPSHOT"; + private static final Logger LOG = LoggerFactory.getLogger(YdbImporter.class); private final ImporterConfig config; private final TableMapList tableMaps; @@ -257,7 +258,7 @@ private void loadTableData(ExecutorService es, List tables) throw } public static void main(String[] args) { - LOG.info("{} version {}", YdbImporter.class.getSimpleName(), VERSION); + LOG.info("{} version {}", YdbImporter.class.getSimpleName(), getVersion()); if (args.length != 1) { LOG.info("Single argument is expected: config-file.xml"); System.exit(2); @@ -279,6 +280,18 @@ public static void main(String[] args) { } } + public static String getVersion() { + try { + Properties prop = new Properties(); + InputStream in = YdbImporter.class.getResourceAsStream("/importer_version.properties"); + prop.load(in); + return prop.getProperty("version"); + } catch (IOException ex) { + LOG.error("cannot load version", ex); + return "unknown"; + } + } + public static final class WorkerFactory implements ThreadFactory { private final YdbImporter owner; diff --git a/src/main/resources/importer_version.properties b/src/main/resources/importer_version.properties new file mode 100644 index 0000000..defbd48 --- /dev/null +++ b/src/main/resources/importer_version.properties @@ -0,0 +1 @@ +version=${project.version} From acd2da914d3309ee65e6eab4ab50621719279729 Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Mon, 2 Sep 2024 16:26:15 +0100 Subject: [PATCH 5/5] More simple thread factory --- .../java/tech/ydb/importer/YdbImporter.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/tech/ydb/importer/YdbImporter.java b/src/main/java/tech/ydb/importer/YdbImporter.java index 2f44268..8a9ad3a 100644 --- a/src/main/java/tech/ydb/importer/YdbImporter.java +++ b/src/main/java/tech/ydb/importer/YdbImporter.java @@ -16,13 +16,13 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import tech.ydb.importer.config.ImporterConfig; import tech.ydb.importer.config.JdomHelper; -import static tech.ydb.importer.config.JdomHelper.isBlank; import tech.ydb.importer.source.AnyTableLister; import tech.ydb.importer.source.SourceCP; import tech.ydb.importer.source.TableMapList; @@ -77,7 +77,7 @@ public AnyTableLister getTableLister() { public void run() throws Exception { String jdbcClassName = config.getSource().getClassName(); - if (!isBlank(jdbcClassName)) { + if (!JdomHelper.isBlank(jdbcClassName)) { LOG.info("Loading driver class {}", jdbcClassName); Class.forName(config.getSource().getClassName()); } @@ -139,8 +139,7 @@ public void run() throws Exception { } private ExecutorService makeWorkers() { - return Executors.newFixedThreadPool(config.getWorkers().getPoolSize(), - new WorkerFactory(this)); + return Executors.newFixedThreadPool(config.getWorkers().getPoolSize(), new WorkerFactory()); } private void retrieveSourceMetadata(List tables, ExecutorService workers) @@ -293,25 +292,18 @@ public static String getVersion() { } public static final class WorkerFactory implements ThreadFactory { - - private final YdbImporter owner; - private int counter = 0; - - public WorkerFactory(YdbImporter owner) { - this.owner = owner; - } + private final AtomicInteger counter = new AtomicInteger(); @Override public Thread newThread(Runnable r) { + int workerId = counter.getAndIncrement(); final Thread t = new Thread(() -> { - BlobSaver.initCounter(counter); + BlobSaver.initCounter(workerId); r.run(); - }, "YdbImporter-worker-" + counter); + }, "YdbImporter-worker-" + workerId); t.setDaemon(false); - ++counter; return t; } - } }