embulk-output-multi 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 133f0b4290cb49bc787590e22edacf2e4f4df4e1
4
- data.tar.gz: bb8c9a01232bb0ab43bc845af45a66039988133d
3
+ metadata.gz: 393cc1011ef55ee4b9cd9cead95df2112598ece9
4
+ data.tar.gz: 985ff4fefca3c02811b77a7199fe2059751b97b9
5
5
  SHA512:
6
- metadata.gz: 7a63b03b9c0d566b49c88fb666390d94ddab230ef21d1fe4254f7131fc4fb6977610b6b95d9966e98631ec8d842dbdcbfc1639d076f6f7bd394f076a4dbe913d
7
- data.tar.gz: 754f5fe52bb5b00f87eebdbaef36157dc4d1e9c1ddcbc541f66d9d6cb54af134c02010a50684f5114a3107ea2dfb2f3ec087807da5aa2b411e13bbd2d1889f7a
6
+ metadata.gz: fd9f992fb29aaa68c5ca6e7a06a824ce24535e0663936a6c556f1701ecb6c28b802bdf4a1a910bb10b571828900f1d8688715552558727eb128b39c3076d44bf
7
+ data.tar.gz: 001124b4d112105d3c345d10bec63a97b62e501f9c56abf2a77d16d918fa8d42e4cb32f959a669dd0d906e6580ebc1470aa5387c185913bb4f523ce7d6f3e8f1
@@ -1 +1 @@
1
- version=0.2.2
1
+ version=0.3.0
@@ -22,10 +22,10 @@ class AsyncRunControl {
22
22
  private final CountDownLatch latch;
23
23
  private final ConcurrentMap<String, TaskSource> taskSources;
24
24
  private final ExecutorService executorService;
25
- private Future<List<TaskReport>> result;
25
+ private final Future<List<TaskReport>> result;
26
26
 
27
27
  static AsyncRunControl start(MultiOutputPlugin.PluginTask task, OutputPlugin.Control control) {
28
- return new AsyncRunControl(task, control).start();
28
+ return new AsyncRunControl(task, control);
29
29
  }
30
30
 
31
31
  private AsyncRunControl(MultiOutputPlugin.PluginTask task, OutputPlugin.Control control) {
@@ -36,6 +36,7 @@ class AsyncRunControl {
36
36
  this.executorService = Executors.newSingleThreadExecutor(
37
37
  new ThreadFactoryBuilder().setNameFormat(THREAD_NAME_FORMAT).build()
38
38
  );
39
+ this.result = executorService.submit(new RunControl());
39
40
  }
40
41
 
41
42
  void cancel() {
@@ -55,11 +56,6 @@ class AsyncRunControl {
55
56
  }
56
57
  }
57
58
 
58
- private AsyncRunControl start() {
59
- this.result = executorService.submit(new RunControl());
60
- return this;
61
- }
62
-
63
59
  private class RunControl implements Callable<List<TaskReport>> {
64
60
  @Override
65
61
  public List<TaskReport> call() throws Exception {
@@ -83,7 +83,7 @@ public class MultiOutputPlugin implements OutputPlugin {
83
83
  final PluginTask task = taskSource.loadTask(PluginTask.class);
84
84
  final ExecSession session = Exec.session();
85
85
  final List<TransactionalPageOutputDelegate> delegates = mapWithPluginDelegate(task, session, delegate ->
86
- new TransactionalPageOutputDelegate(taskIndex, delegate, delegate.open(schema, taskIndex))
86
+ TransactionalPageOutputDelegate.open(schema, taskIndex, delegate)
87
87
  );
88
88
 
89
89
  return new TransactionalPageOutput() {
@@ -3,6 +3,7 @@ package org.embulk.output.multi;
3
3
  import com.google.common.util.concurrent.ThreadFactoryBuilder;
4
4
  import org.embulk.config.TaskReport;
5
5
  import org.embulk.spi.Page;
6
+ import org.embulk.spi.Schema;
6
7
  import org.embulk.spi.TransactionalPageOutput;
7
8
 
8
9
  import java.util.concurrent.BlockingQueue;
@@ -20,9 +21,14 @@ class TransactionalPageOutputDelegate {
20
21
  private final TransactionalPageOutput delegate;
21
22
  private final BlockingQueue<Supplier<Object>> taskQueue;
22
23
  private final ExecutorService executorService;
23
- private final Future<TaskReport> result;
24
+ private final Future<TaskReport> worker;
25
+ private boolean isFailed;
24
26
 
25
- TransactionalPageOutputDelegate(
27
+ static TransactionalPageOutputDelegate open(Schema schema, int taskIndex, OutputPluginDelegate delegate) {
28
+ return new TransactionalPageOutputDelegate(taskIndex, delegate, delegate.open(schema, taskIndex));
29
+ }
30
+
31
+ private TransactionalPageOutputDelegate(
26
32
  int taskIndex,
27
33
  OutputPluginDelegate source,
28
34
  TransactionalPageOutput delegate
@@ -33,7 +39,8 @@ class TransactionalPageOutputDelegate {
33
39
  this.executorService = Executors.newSingleThreadExecutor(
34
40
  new ThreadFactoryBuilder().setNameFormat(String.format(THREAD_NAME_FORMAT, source.getTag(), taskIndex)).build()
35
41
  );
36
- this.result = executorService.submit(new Worker());
42
+ this.worker = executorService.submit(new Worker());
43
+ this.isFailed = false;
37
44
  }
38
45
 
39
46
  void add(Page page) {
@@ -58,20 +65,22 @@ class TransactionalPageOutputDelegate {
58
65
  }
59
66
 
60
67
  void abort() {
61
- taskQueue.add(() -> {
68
+ // Run abort only if the output failed.
69
+ if (isFailed) {
62
70
  delegate.abort();
63
- return null;
64
- });
71
+ }
65
72
  }
66
73
 
67
74
  TaskReport commit() {
68
75
  taskQueue.add(delegate::commit);
69
76
  try {
70
- return result.get();
77
+ return worker.get();
71
78
  } catch (InterruptedException e) {
79
+ isFailed = true;
72
80
  Thread.currentThread().interrupt();
73
81
  throw new RuntimeException(e);
74
82
  } catch (ExecutionException e) {
83
+ isFailed = true;
75
84
  throw new PluginExecutionException(source, e.getCause());
76
85
  } finally {
77
86
  executorService.shutdown();
@@ -115,7 +115,7 @@ class TestMultiOutputPlugin extends EmbulkPluginTest {
115
115
  }
116
116
 
117
117
  @Test
118
- void testAnOutputFailedFailedAfterOpen() throws IOException {
118
+ void testAnOutputFailedAfterOpen() throws IOException {
119
119
  final ConfigSource inConfig = configFromResource("yaml/in_base.yml");
120
120
  final ConfigSource outConfig = configFromResource("yaml/out_failed_output_after_open.yml");
121
121
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -138,7 +138,7 @@ class TestMultiOutputPlugin extends EmbulkPluginTest {
138
138
  }
139
139
 
140
140
  @Test
141
- void testAnOutputFailedFailedBeforeOpen() throws IOException {
141
+ void testAnOutputFailedBeforeOpen() throws IOException {
142
142
  final ConfigSource inConfig = configFromResource("yaml/in_base.yml");
143
143
  final ConfigSource outConfig = configFromResource("yaml/out_failed_output_before_open.yml");
144
144
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-multi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinichi ISHIMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-08 00:00:00.000000000 Z
11
+ date: 2019-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ files:
50
50
  - LICENSE
51
51
  - README.md
52
52
  - build.gradle
53
- - classpath/embulk-output-multi-0.2.2.jar
53
+ - classpath/embulk-output-multi-0.3.0.jar
54
54
  - gradle.properties
55
55
  - gradle/dependency-locks/compileClasspath.lockfile
56
56
  - gradle/dependency-locks/testCompileClasspath.lockfile