protected String getSelfId() { return Service.getId(getSelfLink()); }
private void prepareRequest(Operation op) { // avoid URI allocation and parsing by using cached host URI string StringBuilder sb = Utils.getBuilder(); sb.append(getHost().getPublicUriAsString()).append(getSelfLink()); op.setReferer(sb.toString()); }
private int queueGetRequestInternal(final Operation op, int stopped) { // queue GETs, if updates are pending synchronized (this.context) { if (this.context.processingStage == ProcessingStage.STOPPED) { stopped |= STOP_FLAG; } else if (this.context.isUpdateActive) { if (!this.context.operationQueue.offer(op)) { failRequestLimitExceeded(op, "operationQueue for GET on " + getSelfLink()); } return RETURN_TRUE_FLAG; } else { this.context.getActiveCount++; } } return stopped; }
private int queueUpdateRequestInternal(final Operation op, int stopped) { // serialize updates synchronized (this.context) { if (this.context.processingStage == ProcessingStage.STOPPED) { stopped |= STOP_FLAG; } else if ((this.context.isUpdateActive || this.context.getActiveCount != 0)) { if (op.isSynchronizeOwner()) { // Synchronization requests are queued in a separate queue // so that they can prioritized higher than other updates. if (this.context.synchQueue == null) { this.context.synchQueue = OperationQueue .createFifo(Service.SYNCH_QUEUE_DEFAULT_LIMIT); } if (!this.context.synchQueue.offer(op)) { failRequestLimitExceeded(op, "synchQueue on " + getSelfLink()); } } else if (!this.context.operationQueue.offer(op)) { failRequestLimitExceeded(op, "operationQueue for update on " + getSelfLink()); } return RETURN_TRUE_FLAG; } else { this.context.isUpdateActive = true; } } return stopped; }
public static void findFactoryService(StatefulService service, Consumer<FactoryService> handler) { findService(service.getHost(), UriUtils.getParentPath(service.getSelfLink()), s -> { handler.accept((FactoryService) s); }); }
removedOptions = docOwner; getHost().scheduleServiceOptionToggleMaintenance(getSelfLink(), addedOptions, removedOptions);
@Override public void setProcessingStage(ProcessingStage stage) { boolean logTransition = false; synchronized (this.context) { if (this.context.processingStage == stage) { return; } if (this.context.processingStage == ProcessingStage.STOPPED) { // a service can be stopped while an attempt to start is being processed logTransition = true; } else if (this.context.processingStage.ordinal() > stage.ordinal()) { throw new IllegalArgumentException(this.context.processingStage + " can not move to " + stage); } if (logTransition) { logInfo("Transition from %s to %s", this.context.processingStage, stage); } this.context.processingStage = stage; } if (stage == ProcessingStage.AVAILABLE) { getHost().processPendingServiceAvailableOperations(this, null, false); getHost().getOperationTracker().processPendingServiceStartOperations( getSelfLink(), ProcessingStage.AVAILABLE, this); } if (stage == ProcessingStage.STOPPED) { getHost().getOperationTracker().processPendingServiceStartOperations( getSelfLink(), ProcessingStage.STOPPED, this); } }
/** * Notify the transaction coordinator */ static Operation notifyTransactionCoordinatorOp(StatefulService s, Operation op, Throwable e) { URI txCoordinator = UriUtils.buildTransactionUri(s.getHost(), op.getTransactionId()); s.addPendingTransaction(txCoordinator.getPath()); Operation.TransactionContext operationsLogRecord = new Operation.TransactionContext(); operationsLogRecord.action = op.getAction(); operationsLogRecord.isSuccessful = e == null; Operation notifyCoordinatorOp = Operation.createPut(txCoordinator).setTransactionId(null); notifyCoordinatorOp.addRequestHeader(Operation.TRANSACTION_REFLINK_HEADER, s.getSelfLink()); return s.setPendingTransactionsAsBody(notifyCoordinatorOp, operationsLogRecord); }
public static Service findFactoryService(StatefulService service) { return findService(service.getHost(), UriUtils.getParentPath(service.getSelfLink())); }
private void cancelPendingRequests(Operation op) { Collection<Operation> opsToCancel = null; boolean isDeleteAndStop = ServiceHost.isServiceDeleteAndStop(op); synchronized (this.context) { opsToCancel = this.context.operationQueue.toCollection(); this.context.operationQueue.clear(); if (this.context.synchQueue != null) { opsToCancel.addAll(this.context.synchQueue.toCollection()); this.context.synchQueue.clear(); } } for (Operation o : opsToCancel) { if (o.isFromReplication() && o.getAction() == Action.DELETE) { o.complete(); } else { if (!isDeleteAndStop) { // Pending requests need to be retried on services that are being stopped. getHost().retryOnDemandLoadConflict(o, this); } else { o.fail(new CancellationException(getSelfLink())); } } } }
private static Operation buildLatestInTransactionQueryTaskOp(StatefulService s, String txid, AuthorizationContext authContext) { Query.Builder queryBuilder = Query.Builder.create(); queryBuilder.addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, s.getSelfLink()); queryBuilder.addFieldClause(ServiceDocument.FIELD_NAME_TRANSACTION_ID, txid); QueryTask.Builder queryTaskBuilder = QueryTask.Builder.createDirectTask() .setQuery(queryBuilder.build()); queryTaskBuilder.addOption(QueryOption.EXPAND_CONTENT); queryTaskBuilder.addOption(QueryOption.INCLUDE_ALL_VERSIONS); queryTaskBuilder.orderDescending(ServiceDocument.FIELD_NAME_VERSION, TypeName.LONG); QueryTask task = queryTaskBuilder.build(); Operation returnOp = Operation .createPost(s.getHost(), ServiceUriPaths.CORE_QUERY_TASKS) .setBody(task); returnOp.setAuthorizationContext(authContext); return returnOp; }
private static Operation buildLatestNonTransactionQueryTaskOp(StatefulService s, AuthorizationContext authContext) { Query.Builder queryBuilder = Query.Builder.create(); queryBuilder.addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, s.getSelfLink()); queryBuilder.addFieldClause(ServiceDocument.FIELD_NAME_TRANSACTION_ID, "*", MatchType.WILDCARD, Occurance.MUST_NOT_OCCUR); QueryTask.Builder queryTaskBuilder = QueryTask.Builder.createDirectTask() .setQuery(queryBuilder.build()); queryTaskBuilder.addOption(QueryOption.EXPAND_CONTENT); queryTaskBuilder.addOption(QueryOption.INCLUDE_ALL_VERSIONS); queryTaskBuilder.orderDescending(ServiceDocument.FIELD_NAME_VERSION, TypeName.LONG); QueryTask task = queryTaskBuilder.build(); Operation returnOp = Operation .createPost(s.getHost(), ServiceUriPaths.CORE_QUERY_TASKS) .setBody(task); returnOp.setAuthorizationContext(authContext); return returnOp; }
QueryTask.Query selfLinkClause = new QueryTask.Query().setTermPropertyName( ServiceDocument.FIELD_NAME_SELF_LINK) .setTermMatchValue(s.getSelfLink()); selfLinkClause.occurance = QueryTask.Query.Occurance.MUST_OCCUR; q.query.addBooleanClause(selfLinkClause);
getPeerNodeSelectorPath(), getSelfLink(), op); return true;
&& resolutionRequest.resolutionKind.equals(ResolutionKind.ABORT))) { this.parent.logInfo("Resolution of transaction %s is complete", this.parent.getSelfLink()); op.setBodyNoCloning(notifyOp.getBodyRaw()); op.setStatusCode(notifyOp.getStatusCode()); String errorMsg = String.format( "Resolution %s of transaction %s is different than requested", resolve.resolutionKind, this.parent.getSelfLink()); this.parent.logWarning(errorMsg); op.fail(new IllegalStateException(errorMsg));
private void synchWithPeersAndReProcess(Operation op) { ServiceDocument d = new ServiceDocument(); d.documentSelfLink = UriUtils.getLastPathSegment(getSelfLink()); Operation synchOwnerRequest = Operation.createPost(getUri()) .setBody(d) .linkState(op.getLinkedState()) .setReferer(getUri()) .setConnectionSharing(true) .setConnectionTag(ServiceClient.CONNECTION_TAG_SYNCHRONIZATION) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_SYNCH_OWNER) .setRetryCount(0) .setExpiration(op.getExpirationMicrosUtc()) .setCompletion((o, e) -> { if (e != null) { op.fail(e); return; } // now that we have the latest state, and are marked as owner, // we can re-process the request handleRequest(op); }); synchronizeWithPeers(synchOwnerRequest, null); }
getSelfLink(), commitOp); return;