Commit c865b65
feat: add Batcher#close(timeout) and Batcher#cancelOutstanding (#3141)
There have been reports of batcher.close() hanging every once in awhile.
Currently it is impossible to debug because we dont expose any internal
state to analyze.
This PR adds 2 additional methods that should help in diagnosing issues:
1. close(timeout) will try to close the batcher, but if any of the
underlying batch operations fail, the exception message will contain a
wealth of information describing the underlying state of operations as
provided by #3140
2. cancelOutstanding this allows for remediation for close(timeout)
throwing an exception.
The intended usecase is dataflow connector's FinishBundle:
```java
try {
batcher.close(Duration.ofMinutes(1));
} catch(TimeoutException e) {
// log details why the batch failed to close with the help of #3140
logger.error(e);
batcher.cancelOutstanding();
batcher.close(Duration.ofMinutes(1));
}
```
Example exception message:
> Exception in thread "main"
com.google.api.gax.batching.BatchingException: Timed out trying to close
batcher after PT1S. Batch request prototype:
com.google.cloud.bigtable.data.v2.models.BulkMutation@2bac9ba.
Outstanding batches:
Batch{operation=CallbackChainRetryingFuture{super=null,
latestCompletedAttemptResult=ImmediateFailedFuture@6a9d5dff[status=FAILURE,
cause=[com.google.cloud.bigtable.data.v2.models.MutateRowsException:
Some mutations failed to apply]], attemptResult=null,
attemptSettings=TimedAttemptSettings{globalSettings=RetrySettings{totalTimeout=PT10M,
initialRetryDelay=PT0.01S, retryDelayMultiplier=2.0, maxRetryDelay=PT1M,
maxAttempts=0, jittered=true, initialRpcTimeout=PT1M,
rpcTimeoutMultiplier=1.0, maxRpcTimeout=PT1M}, retryDelay=PT1.28S,
rpcTimeout=PT1M, randomizedRetryDelay=PT0.877S, attemptCount=8,
overallAttemptCount=8, firstAttemptStartTimeNanos=646922035424541}},
elements=com.google.cloud.bigtable.data.v2.models.RowMutationEntry@7a344b65}
Co-authored-by: Blake Li <[email protected]>1 parent 9dc2410 commit c865b65
File tree
4 files changed
+228
-13
lines changed- gax-java/gax
- src
- main/java/com/google/api/gax/batching
- test/java/com/google/api/gax/batching
4 files changed
+228
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
108 | 114 | | |
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
80 | 86 | | |
81 | | - | |
82 | | - | |
| 87 | + | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
87 | 102 | | |
88 | 103 | | |
89 | 104 | | |
| |||
Lines changed: 78 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
60 | | - | |
| 64 | + | |
61 | 65 | | |
62 | 66 | | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
86 | 91 | | |
87 | 92 | | |
88 | 93 | | |
89 | | - | |
| 94 | + | |
| 95 | + | |
90 | 96 | | |
91 | 97 | | |
92 | 98 | | |
| |||
297 | 303 | | |
298 | 304 | | |
299 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
300 | 309 | | |
301 | | - | |
302 | 310 | | |
303 | 311 | | |
304 | 312 | | |
| |||
310 | 318 | | |
311 | 319 | | |
312 | 320 | | |
313 | | - | |
| 321 | + | |
314 | 322 | | |
315 | 323 | | |
316 | 324 | | |
| |||
322 | 330 | | |
323 | 331 | | |
324 | 332 | | |
325 | | - | |
| 333 | + | |
326 | 334 | | |
327 | 335 | | |
328 | 336 | | |
329 | 337 | | |
330 | 338 | | |
331 | 339 | | |
332 | | - | |
| 340 | + | |
333 | 341 | | |
334 | 342 | | |
335 | 343 | | |
336 | | - | |
| 344 | + | |
| 345 | + | |
337 | 346 | | |
338 | 347 | | |
339 | 348 | | |
| |||
349 | 358 | | |
350 | 359 | | |
351 | 360 | | |
352 | | - | |
| 361 | + | |
353 | 362 | | |
354 | 363 | | |
355 | | - | |
| 364 | + | |
356 | 365 | | |
357 | 366 | | |
358 | 367 | | |
359 | 368 | | |
360 | 369 | | |
361 | 370 | | |
362 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
363 | 378 | | |
364 | 379 | | |
365 | 380 | | |
366 | 381 | | |
367 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
368 | 398 | | |
369 | 399 | | |
370 | 400 | | |
| |||
374 | 404 | | |
375 | 405 | | |
376 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
377 | 418 | | |
378 | 419 | | |
379 | 420 | | |
| |||
393 | 434 | | |
394 | 435 | | |
395 | 436 | | |
396 | | - | |
| 437 | + | |
397 | 438 | | |
398 | 439 | | |
399 | 440 | | |
| |||
435 | 476 | | |
436 | 477 | | |
437 | 478 | | |
| 479 | + | |
| 480 | + | |
438 | 481 | | |
439 | 482 | | |
440 | 483 | | |
| |||
457 | 500 | | |
458 | 501 | | |
459 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
460 | 514 | | |
461 | 515 | | |
462 | 516 | | |
| |||
480 | 534 | | |
481 | 535 | | |
482 | 536 | | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
483 | 550 | | |
484 | 551 | | |
485 | 552 | | |
| |||
0 commit comments