提交 7ef94b7f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix IOException caused by race in CreateCluster

上级 452cbd69
......@@ -154,9 +154,9 @@ public class CreateCluster extends Tool {
}
private static Future<?> startWriter(final PipedReader pipeReader,
final Statement statSource) {
final Statement statSource) throws IOException {
final ExecutorService thread = Executors.newFixedThreadPool(1);
final PipedWriter pipeWriter = new PipedWriter(pipeReader);
// Since exceptions cannot be thrown across thread boundaries, return
// the task's future so we can check manually
Future<?> threadFuture = thread.submit(new Runnable() {
......@@ -167,10 +167,10 @@ public class CreateCluster extends Tool {
// - if the pipe is broken, unconnected, closed, or an I/O error
// occurs. The reader's IOException will then trigger the
// finally{} that releases exclusive mode on the source DB.
try (final PipedWriter pipeWriter = new PipedWriter(pipeReader);
try (PipedWriter writer = pipeWriter;
final ResultSet rs = statSource.executeQuery("SCRIPT")) {
while (rs.next()) {
pipeWriter.write(rs.getString(1) + "\n");
writer.write(rs.getString(1) + "\n");
}
} catch (SQLException | IOException ex) {
throw new IllegalStateException("Producing script from the source DB is failing.", ex);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论