@Override public void close() { span.end(); synchronized (lock) { isClosed = true; } }
@Override public void close(@Nullable String message) { if (stream != null) { stream.close(message); } span.end(); }
@Override public void close() { try { if (txnState == TransactionState.STARTED && !txn.isAborted()) { txn.rollback(); txnState = TransactionState.ROLLED_BACK; } } finally { span.end(); } }
static void endSpanWithFailure(Span span, Exception e) { if (e instanceof SpannerException) { endSpanWithFailure(span, (SpannerException) e); } else { span.setStatus(Status.INTERNAL.withDescription(e.getMessage())); span.end(); } }
@Override public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_OPEN_REWRITE); Scope scope = tracer.withSpan(span); try { return rewrite(rewriteRequest, null); } finally { scope.close(); span.end(); } }
@Override public RewriteResponse continueRewrite(RewriteResponse previousResponse) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CONTINUE_REWRITE); Scope scope = tracer.withSpan(span); try { return rewrite(previousResponse.rewriteRequest, previousResponse.rewriteToken); } finally { scope.close(); span.end(); } }
static void endSpanWithFailure(Span span, SpannerException e) { span.setStatus( StatusConverter.fromGrpcStatus(e.getErrorCode().getGrpcStatus()) .withDescription(e.getMessage())); span.end(); }
@Override public Timestamp write(Iterable<Mutation> mutations) throws SpannerException { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().write(mutations); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } finally { span.end(); } }
@Override public StorageObject patch(StorageObject storageObject, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_OBJECT); Scope scope = tracer.withSpan(span); try { return patchCall(storageObject, options).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Timestamp writeAtLeastOnce(Iterable<Mutation> mutations) throws SpannerException { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().writeAtLeastOnce(mutations); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } finally { span.end(); } }
@Override public Notification createNotification(String bucket, Notification notification) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_NOTIFICATION); Scope scope = tracer.withSpan(span); try { return storage.notifications().insert(bucket, notification).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public List<Notification> listNotifications(String bucket) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LIST_NOTIFICATIONS); Scope scope = tracer.withSpan(span); try { return storage.notifications().list(bucket).execute().getItems(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public ObjectAccessControl createDefaultAcl(ObjectAccessControl acl) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_OBJECT_DEFAULT_ACL); Scope scope = tracer.withSpan(span); try { return storage.defaultObjectAccessControls().insert(acl.getBucket(), acl).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public List<ObjectAccessControl> listDefaultAcls(String bucket) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LIST_OBJECT_DEFAULT_ACLS); Scope scope = tracer.withSpan(span); try { return storage.defaultObjectAccessControls().list(bucket).execute().getItems(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public StorageObject get(StorageObject object, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_OBJECT); Scope scope = tracer.withSpan(span); try { return getCall(object, options).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } finally { scope.close(); span.end(); } }
@Override public ServiceAccount getServiceAccount(String projectId) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_SERVICE_ACCOUNT); Scope scope = tracer.withSpan(span); try { return storage.projects().serviceAccount().get(projectId).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } } }
@Override public ObjectAccessControl patchDefaultAcl(ObjectAccessControl acl) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_OBJECT_DEFAULT_ACL); Scope scope = tracer.withSpan(span); try { return storage .defaultObjectAccessControls() .patch(acl.getBucket(), acl.getEntity(), acl) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Policy setIamPolicy(String bucket, Policy policy, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_SET_BUCKET_IAM_POLICY); Scope scope = tracer.withSpan(span); try { return storage .buckets() .setIamPolicy(bucket, policy) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public void close() { Span span = tracer.spanBuilder(DELETE_SESSION).startSpan(); try (Scope s = tracer.withSpan(span)) { runWithRetries( new Callable<Void>() { @Override public Void call() throws Exception { gapicRpc.deleteSession(name, options); return null; } }); span.end(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
@Override public Bucket lockRetentionPolicy(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_LOCK_RETENTION_POLICY); Scope scope = tracer.withSpan(span); try { return storage .buckets() .lockRetentionPolicy(bucket.getName(), Option.IF_METAGENERATION_MATCH.getLong(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }