Skip to content

Commit 2846f15

Browse files
committed
Shutdown writer synchronously
1 parent adb3720 commit 2846f15

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

ydb-cookbook/src/main/java/tech/ydb/examples/topic/transactions/TransactionWriteSync.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99
import tech.ydb.common.transaction.TxMode;
10+
import tech.ydb.core.Result;
1011
import tech.ydb.core.grpc.GrpcTransport;
1112
import tech.ydb.examples.SimpleExample;
1213
import tech.ydb.query.QueryClient;
@@ -107,20 +108,19 @@ private void tableAndTopicWithinTransaction(TopicClient topicClient, QueryClient
107108
// flush to wait until the message will reach the server before committing transaction
108109
writer.flush();
109110

110-
return transaction.commit()
111-
.thenApply(commitResult -> {
112-
try {
113-
writer.shutdown(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
114-
} catch (TimeoutException exception) {
115-
throw new RuntimeException("Shutdown not finished within " + SHUTDOWN_TIMEOUT_SECONDS +
116-
" seconds");
117-
} catch (InterruptedException | ExecutionException exception) {
118-
throw new RuntimeException("Shutdown not finished due to exception: " + exception);
119-
}
120-
// Return commit status to SessionRetryContext function
121-
return commitResult.getStatus();
122-
});
123-
}).join().expectSuccess("Can't create table series");
111+
// Shutdown writer
112+
try {
113+
writer.shutdown(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
114+
} catch (TimeoutException exception) {
115+
throw new RuntimeException("Shutdown not finished within " + SHUTDOWN_TIMEOUT_SECONDS +
116+
" seconds");
117+
} catch (InterruptedException | ExecutionException exception) {
118+
throw new RuntimeException("Shutdown not finished due to exception: " + exception);
119+
}
120+
121+
// Return commit status to SessionRetryContext function
122+
return transaction.commit().thenApply(Result::getStatus);
123+
}).join().expectSuccess("Couldn't read from table and write to topic in transaction");
124124
}
125125

126126
public static void main(String[] args) {

0 commit comments

Comments
 (0)