Skip to content

Commit ba7bed9

Browse files
authored
Fix QuerySession pool autoresize (#69)
2 parents ed0e695 + 19e98b3 commit ba7bed9

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

jdbc/src/main/java/tech/ydb/jdbc/context/StreamQueryResult.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public void onNextPart(QueryResultPart part) {
250250
private class LazyResultSet extends BaseYdbResultSet {
251251
private final BlockingQueue<ResultSetReader> readers = new ArrayBlockingQueue<>(5);
252252
private final AtomicLong rowsCount = new AtomicLong();
253-
private volatile boolean isCompleted = false;
253+
private final CompletableFuture<Void> isCompleted = new CompletableFuture<>();
254254
private volatile boolean isClosed = false;
255255

256256
private ResultSetReader current = null;
@@ -300,7 +300,7 @@ public boolean next() throws SQLException {
300300
return true;
301301
}
302302

303-
if (isCompleted && readers.isEmpty()) {
303+
if (isCompleted.isDone() && readers.isEmpty()) {
304304
current = null;
305305
if (rowsCount.get() > 0) {
306306
rowIndex = rowsCount.intValue() + 1;
@@ -317,10 +317,7 @@ public boolean next() throws SQLException {
317317
}
318318

319319
public void complete() {
320-
if (isCompleted) {
321-
return;
322-
}
323-
isCompleted = true;
320+
isCompleted.complete(null);
324321
}
325322

326323
@Override
@@ -351,7 +348,8 @@ public boolean isBeforeFirst() throws SQLException {
351348

352349
@Override
353350
public boolean isAfterLast() throws SQLException {
354-
return isCompleted && rowsCount.get() > 0 && rowIndex > rowsCount.intValue();
351+
isCompleted.join();
352+
return rowsCount.get() > 0 && rowIndex > rowsCount.intValue();
355353
}
356354

357355
@Override
@@ -361,7 +359,8 @@ public boolean isFirst() throws SQLException {
361359

362360
@Override
363361
public boolean isLast() throws SQLException {
364-
return isCompleted && rowsCount.get() > 0 && rowIndex == rowsCount.intValue();
362+
isCompleted.join();
363+
return rowsCount.get() > 0 && rowIndex == rowsCount.intValue();
365364
}
366365

367366
@Override

jdbc/src/main/java/tech/ydb/jdbc/context/YdbContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public void register() {
219219
int newSize = maxSize + SESSION_POOL_RESIZE_STEP;
220220
if (maxSize == tableClient.sessionPoolStats().getMaxSize()) {
221221
tableClient.updatePoolMaxSize(newSize);
222+
queryClient.updatePoolMaxSize(newSize);
222223
}
223224
}
224225
}
@@ -231,6 +232,7 @@ public void deregister() {
231232
int newSize = maxSize - SESSION_POOL_RESIZE_STEP;
232233
if (maxSize == tableClient.sessionPoolStats().getMaxSize()) {
233234
tableClient.updatePoolMaxSize(newSize);
235+
queryClient.updatePoolMaxSize(newSize);
234236
}
235237
}
236238
}

0 commit comments

Comments
 (0)