Skip to content

Commit 9f5bd59

Browse files
authored
Merge pull request #344 from alex268/master
Fix NPE for transaction id handling
2 parents fe3af55 + da4f249 commit 9f5bd59

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

query/src/main/java/tech/ydb/query/impl/SessionImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ public QueryStream createQuery(String query, TxMode tx, Params prms, ExecuteQuer
210210
YdbQuery.TransactionControl tc = TxControl.txModeCtrl(tx, true);
211211
return new StreamImpl(createGrpcStream(query, tc, prms, settings)) {
212212
@Override
213-
void handleTxMeta(YdbQuery.TransactionMeta meta) {
214-
String txID = meta == null ? null : meta.getId();
213+
void handleTxMeta(String txID) {
215214
if (txID != null && !txID.isEmpty()) {
216215
logger.warn("{} got unexpected transaction id {}", SessionImpl.this, txID);
217216
}
@@ -253,7 +252,7 @@ abstract class StreamImpl implements QueryStream {
253252
this.grpcStream = grpcStream;
254253
}
255254

256-
abstract void handleTxMeta(YdbQuery.TransactionMeta meta);
255+
abstract void handleTxMeta(String txId);
257256
void handleCompletion(Status status, Throwable th) { }
258257

259258
@Override
@@ -276,7 +275,7 @@ public CompletableFuture<Result<QueryInfo>> execute(PartsHandler handler) {
276275
}
277276

278277
if (msg.hasTxMeta()) {
279-
handleTxMeta(msg.getTxMeta());
278+
handleTxMeta(msg.getTxMeta().getId());
280279
}
281280
if (issues.length > 0) {
282281
if (handler != null) {
@@ -352,8 +351,8 @@ public QueryStream createQuery(String query, boolean commitAtEnd, Params prms, E
352351

353352
return new StreamImpl(createGrpcStream(query, tc, prms, settings)) {
354353
@Override
355-
void handleTxMeta(YdbQuery.TransactionMeta meta) {
356-
String newId = meta == null || meta.getId() == null || meta.getId().isEmpty() ? null : meta.getId();
354+
void handleTxMeta(String txID) {
355+
String newId = txID == null || txID.isEmpty() ? null : txID;
357356
if (!txId.compareAndSet(currentId, newId)) {
358357
logger.warn("{} lost transaction meta id {}", SessionImpl.this, newId);
359358
}

query/src/main/java/tech/ydb/query/impl/TableClientImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,17 @@ public CompletableFuture<Result<DataQueryResult>> executeDataQueryInternal(
156156
.withRequestTimeout(settings.getTimeoutDuration())
157157
.build();
158158

159-
final AtomicReference<String> txID = new AtomicReference<>("");
159+
final AtomicReference<String> txRef = new AtomicReference<>("");
160160
QueryStream stream = querySession.new StreamImpl(querySession.createGrpcStream(query, tc, prms, qs)) {
161161
@Override
162-
void handleTxMeta(YdbQuery.TransactionMeta meta) {
163-
txID.set(meta.getId());
162+
void handleTxMeta(String txID) {
163+
txRef.set(txID);
164164
}
165165
};
166166

167167
return QueryReader.readFrom(stream)
168168
.thenApply(r -> r.map(
169-
reader -> new ProxedDataQueryResult(txID.get(), reader)
169+
reader -> new ProxedDataQueryResult(txRef.get(), reader)
170170
));
171171
}
172172

0 commit comments

Comments
 (0)