com.google.cloud.spanner.AbortedException Java Examples
The following examples show how to use
com.google.cloud.spanner.AbortedException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalSpannerIO.java From DataflowTemplates with Apache License 2.0 | 6 votes |
private void spannerWriteWithRetryIfSchemaChange(Iterable<Mutation> batch) throws SpannerException { for (int retry = 1; ; retry++) { try { spannerAccessor.getDatabaseClient().writeAtLeastOnce(batch); return; } catch (AbortedException e) { if (retry >= ABORTED_RETRY_ATTEMPTS) { throw e; } if (e.isRetryable() || e.getMessage().contains(errString)) { continue; } throw e; } } }
Example #2
Source File: SpannerIO.java From beam with Apache License 2.0 | 6 votes |
private void spannerWriteWithRetryIfSchemaChange(Iterable<Mutation> batch) throws SpannerException { for (int retry = 1; ; retry++) { try { spannerAccessor.getDatabaseClient().writeAtLeastOnce(batch); return; } catch (AbortedException e) { if (retry >= ABORTED_RETRY_ATTEMPTS) { throw e; } if (e.isRetryable() || e.getMessage().contains(errString)) { continue; } throw e; } } }
Example #3
Source File: DatabaseClientSnippets.java From google-cloud-java with Apache License 2.0 | 6 votes |
/** Example of using {@link TransactionManager}. */ // [TARGET transactionManager()] // [VARIABLE my_singer_id] public void transactionManager(final long singerId) throws InterruptedException { // [START transactionManager] try (TransactionManager manager = dbClient.transactionManager()) { TransactionContext txn = manager.begin(); while (true) { try { String column = "FirstName"; Struct row = txn.readRow("Singers", Key.of(singerId), Collections.singleton(column)); String name = row.getString(column); txn.buffer( Mutation.newUpdateBuilder("Singers").set(column).to(name.toUpperCase()).build()); manager.commit(); break; } catch (AbortedException e) { Thread.sleep(e.getRetryDelayInMillis() / 1000); txn = manager.resetForRetry(); } } } // [END transactionManager] }
Example #4
Source File: SpannerTransactionManagerTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testDoCommitRollbackExceptions() { this.expectedEx.expect(UnexpectedRollbackException.class); this.expectedEx.expectMessage("Transaction Got Rolled Back; " + "nested exception is com.google.cloud.spanner.AbortedException"); when(transactionManager.getState()).thenReturn(TransactionState.STARTED); Mockito.doThrow(AbortedException.class).when(transactionManager).commit(); tx.transactionManager = transactionManager; manager.doCommit(status); }