@Override public void onCompleted() { tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Complete"); List<DocumentSnapshot> documentSnapshots = new ArrayList<>(); for (DocumentReference documentReference : documentReferences) { documentSnapshots.add(resultMap.get(documentReference)); } futureList.set(documentSnapshots); } };
@Override public void onError(Throwable throwable) { tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Error"); futureList.setException(throwable); }
span.addAnnotation("Acquiring session"); Waiter waiter = null; PooledSession sess = null; synchronized (lock) { if (closureFuture != null) { span.addAnnotation("Pool has been closed"); throw new IllegalStateException("Pool has been closed"); sess = writePreparedSessions.poll(); if (sess == null) { span.addAnnotation("No session available"); maybeCreateSession(); waiter = new Waiter(); readWaiters.add(waiter); } else { span.addAnnotation("Acquired read write session"); span.addAnnotation("Acquired read only session"); Level.FINE, "No session available in the pool. Blocking for one to become available/created"); span.addAnnotation("Waiting for read only session to be available"); sess = waiter.take(); span.addAnnotation(sessionAnnotation(sess)); return sess;
void ensureTxn() { if (transactionId == null) { span.addAnnotation("Creating Transaction"); try { transactionId = session.beginTransaction(); span.addAnnotation( "Transaction Creation Done", ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(transactionId.toStringUtf8()))); txnLogger.log( Level.FINER, "Started transaction {0}", txnLogger.isLoggable(Level.FINER) ? transactionId.asReadOnlyByteBuffer() : null); } catch (SpannerException e) { span.addAnnotation("Transaction Creation Failed", TraceUtil.getExceptionAnnotations(e)); throw e; } } else { span.addAnnotation( "Transaction Initialized", ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(transactionId.toStringUtf8()))); txnLogger.log( Level.FINER, "Using prepared transaction {0}", txnLogger.isLoggable(Level.FINER) ? transactionId.asReadOnlyByteBuffer() : null); } }
span.addAnnotation("Acquiring read write session"); Waiter waiter = null; PooledSession sess = null; PooledSession readSession = readSessions.poll(); if (readSession != null) { span.addAnnotation("Acquired read only session. Preparing for read write transaction"); prepareSession(readSession); } else { span.addAnnotation("No session available"); maybeCreateSession(); readWriteWaiters.add(waiter); } else { span.addAnnotation("Acquired read write session"); Level.FINE, "No session available in the pool. Blocking for one to become available/created"); span.addAnnotation("Waiting for read write session to be available"); sess = waiter.take(); span.addAnnotation(sessionAnnotation(sess)); return sess;
@Override public void onError(Throwable throwable) { Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: Error"); documentObserver.onError(throwable); }
@Override public void onCompleted() { Tracing.getTracer() .getCurrentSpan() .addAnnotation( "Firestore.Query: Completed", ImmutableMap.of( "numDocuments", AttributeValue.longAttributeValue(numDocuments))); documentObserver.onCompleted(readTime); } };
private void backoff(Context context, BackOff backoff) { long delay = txn.getRetryDelayInMillis(backoff); txn = session.newTransaction(); span.addAnnotation( "Backing off", ImmutableMap.of("Delay", AttributeValue.longAttributeValue(delay))); sleeper.backoffSleep(context, delay); } }
void rollback() { // We're exiting early due to a user exception, but the transaction is still active. // Send a rollback for the transaction to release any locks held. // TODO(user): Make this an async fire-and-forget request. try { // Note that we're not retrying this request since we don't particularly care about the // response. Normally, the next thing that will happen is that we will make a fresh // transaction attempt, which should implicitly abort this one. span.addAnnotation("Starting Rollback"); rpc.rollback( RollbackRequest.newBuilder() .setSession(session.getName()) .setTransactionId(transactionId) .build(), session.options); span.addAnnotation("Rollback Done"); } catch (SpannerException e) { txnLogger.log(Level.FINE, "Exception during rollback", e); span.addAnnotation("Rollback Failed", TraceUtil.getExceptionAnnotations(e)); } }
private void maybeCreateSession() { Span span = Tracing.getTracer().getCurrentSpan(); synchronized (lock) { if (numWaiters() >= numSessionsBeingCreated) { if (canCreateSession()) { span.addAnnotation("Creating session"); createSession(); } else if (options.isFailIfPoolExhausted()) { span.addAnnotation("Pool exhausted. Failing"); // throw specific exception throw newSpannerException( ErrorCode.RESOURCE_EXHAUSTED, "No session available in the pool. Maximum number of sessions in the pool can be" + " overridden by invoking SessionPoolOptions#Builder#setMaxSessions. Client can be made to block" + " rather than fail by setting SessionPoolOptions#Builder#setBlockIfPoolExhausted."); } } } } /**
private static void backoffSleep(Context context, long backoffMillis) throws SpannerException { tracer .getCurrentSpan() .addAnnotation( "Backing off", ImmutableMap.of("Delay", AttributeValue.longAttributeValue(backoffMillis)));
attempt++; try { span.addAnnotation( "Starting operation", ImmutableMap.of("Attempt", AttributeValue.longAttributeValue(attempt)));
@Override public void submit() { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_BATCH_SUBMIT); Scope scope = tracer.withSpan(span); try { span.putAttribute("batch size", AttributeValue.longAttributeValue(batches.size())); for (BatchRequest batch : batches) { // TODO(hailongwen@): instrument 'google-api-java-client' to further break down the span. // Here we only add a annotation to at least know how much time each batch takes. span.addAnnotation("Execute batch request"); batch.setBatchUrl( new GenericUrl(String.format("%s/batch/storage/v1", options.getHost()))); batch.execute(); } } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } } }
private void maybeRetry() { if (attemptsRemaining > 0) { span.addAnnotation("retrying"); runTransactionAttempt( transactionCallback, resultFuture, new TransactionOptions( attemptsRemaining, options.getExecutor(), transaction.getTransactionId()), span); } else { span.setStatus(TOO_MANY_RETRIES_STATUS); rejectTransaction( FirestoreException.serverRejected( Status.ABORTED, "Transaction was cancelled because of too many retries.")); } }
@Override public void onNext(RunQueryResponse response) { if (!firstResponse) { firstResponse = true; Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: First response"); } if (response.hasDocument()) { numDocuments++; if (numDocuments % 100 == 0) { Tracing.getTracer() .getCurrentSpan() .addAnnotation("Firestore.Query: Received 100 documents"); } Document document = response.getDocument(); QueryDocumentSnapshot documentSnapshot = QueryDocumentSnapshot.fromDocument( firestore, Timestamp.fromProto(response.getReadTime()), document); documentObserver.onNext(documentSnapshot); } if (readTime == null) { readTime = Timestamp.fromProto(response.getReadTime()); } }
void commit() { span.addAnnotation("Starting Commit"); CommitRequest.Builder builder = CommitRequest.newBuilder().setSession(session.getName()).setTransactionId(transactionId); opSpan.end(); } catch (RuntimeException e) { span.addAnnotation("Commit Failed", TraceUtil.getExceptionAnnotations(e)); TraceUtil.endSpanWithFailure(opSpan, e); throw e; span.addAnnotation("Commit Done");
Tracing.getTracer() .getCurrentSpan() .addAnnotation( "CloudFirestore.Commit", ImmutableMap.of("numDocuments", AttributeValue.longAttributeValue(mutations.size())));
return; span.addAnnotation("Creating Transaction"); try { TransactionOptions.Builder options = TransactionOptions.newBuilder(); span.addAnnotation( "Transaction Creation Done", TraceUtil.getTransactionAnnotations(transaction)); } catch (SpannerException e) { span.addAnnotation("Transaction Creation Failed", TraceUtil.getExceptionAnnotations(e)); throw e;
tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: First response"); } else if (numResponses % 100 == 0) { tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Received 100 responses");
.addAnnotation( "Firestore.Query: Start", ImmutableMap.of(