private void setExpiration(Operation op) { if (op.getExpirationMicrosUtc() != 0) { return; } long expMicros = this.host != null ? this.host.getOperationTimeoutMicros() : ServiceHostState.DEFAULT_OPERATION_TIMEOUT_MICROS; op.setExpiration(Utils.fromNowMicrosUtc(expMicros)); }
public void registerForServiceAvailability(CompletionHandler completion, String nodeSelectorPath, boolean checkReplica, String... servicePaths) { if (servicePaths == null || servicePaths.length == 0) { throw new IllegalArgumentException("selfLinks are required"); } Operation op = Operation.createPost(null) .setCompletion(completion) .setExpiration(Utils.fromNowMicrosUtc(getOperationTimeoutMicros())); registerForServiceAvailability(op, checkReplica, nodeSelectorPath, servicePaths); }
public static void registerForReplicatedServiceAvailability(ServiceHost host, CompletionHandler completion, AuthorizationContext authorizationContext, String nodeSelectorPath, String... servicePaths) { for (String link : servicePaths) { Operation op = Operation.createPost(host, link) .setCompletion(completion) .setExpiration(Utils.fromNowMicrosUtc(host.getOperationTimeoutMicros())); registerForReplicatedServiceAvailability(host, op, link, nodeSelectorPath, authorizationContext); } }
.setExpiration( Utils.fromNowMicrosUtc( getHost().getOperationTimeoutMicros())) .setCompletion((o, e) -> { if (e != null) {
public static boolean restartStatefulHost(ServiceHost host, boolean failOnIndexDeletion) throws Throwable { long exp = Utils.fromNowMicrosUtc(host.getOperationTimeoutMicros()); do { Thread.sleep(2000); try { if (host.isAuthorizationEnabled()) { host.setAuthenticationService(new AuthorizationContextService()); } host.start(); return true; } catch (Throwable e) { Logger.getAnonymousLogger().warning(String .format("exception on host restart: %s", e.getMessage())); try { host.stop(); } catch (Throwable e1) { return false; } if (e instanceof LockObtainFailedException && !failOnIndexDeletion) { Logger.getAnonymousLogger() .warning("Lock held exception on host restart, retrying"); continue; } return false; } } while (Utils.getSystemNowMicrosUtc() < exp); return false; }
public static boolean restartStatefulHost(ServiceHost host, boolean failOnIndexDeletion) throws Throwable { long exp = Utils.fromNowMicrosUtc(host.getOperationTimeoutMicros()); do { Thread.sleep(2000); try { if (host.isAuthorizationEnabled()) { host.setAuthenticationService(new AuthorizationContextService()); } host.start(); return true; } catch (Throwable e) { Logger.getAnonymousLogger().warning(String .format("exception on host restart: %s", e.getMessage())); try { host.stop(); } catch (Throwable e1) { return false; } if (e instanceof LockObtainFailedException && !failOnIndexDeletion) { Logger.getAnonymousLogger() .warning("Lock held exception on host restart, retrying"); continue; } return false; } } while (Utils.getSystemNowMicrosUtc() < exp); return false; }
getHost().getOperationTimeoutMicros() / 10)); handleJoinPost(joinBody, post, joinTimeOutMicrosUtc, getState(post), null); return;
timeoutMicros = Math.max(timeoutMicros, this.host.getOperationTimeoutMicros()); queryTask.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(timeoutMicros); }) .setReferer(this.host.getUri()) .setExpiration(Utils.fromNowMicrosUtc(this.host.getOperationTimeoutMicros())) .sendWith(this.host);
Utils.fromNowMicrosUtc(this.host.getOperationTimeoutMicros())); Utils.checkAndUpdateDocumentOwnership(this.host, s, ownershipCheckExpiration, (o, ex) -> { if (ex != null) {
long timeoutMicros = Math.min(host.getOperationTimeoutMicros(), TimeUnit.SECONDS.toMicros(NODE_GROUP_UTILS_OPERATION_TIMEOUT_SECONDS));
public static String create(ServiceHost h, ServiceOption... extraOptions) throws Throwable { // create an on demand load factory and services TestContext ctx = TestContext.create(1, h.getOperationTimeoutMicros()); OnDemandLoadFactoryService s = new OnDemandLoadFactoryService(); EnumSet<ServiceOption> childOptions = EnumSet.of(ServiceOption.PERSISTENCE, ServiceOption.REPLICATION, ServiceOption.OWNER_SELECTION); if (extraOptions != null) { for (ServiceOption eo : extraOptions) { childOptions.add(eo); } } s.setChildServiceCaps(childOptions); Operation factoryPost = Operation.createPost( UriUtils.buildUri(h, s.getClass())) .setCompletion(ctx.getCompletion()); h.startService(factoryPost, s); ctx.await(); String factoryLink = s.getSelfLink(); h.log(Level.INFO, "Started on demand load factory at %s", factoryLink); return factoryLink; }
public static String create(ServiceHost h, ServiceOption... extraOptions) throws Throwable { // create an on demand load factory and services TestContext ctx = TestContext.create(1, h.getOperationTimeoutMicros()); OnDemandLoadFactoryService s = new OnDemandLoadFactoryService(); EnumSet<ServiceOption> childOptions = EnumSet.of(ServiceOption.PERSISTENCE, ServiceOption.REPLICATION, ServiceOption.OWNER_SELECTION); if (extraOptions != null) { for (ServiceOption eo : extraOptions) { childOptions.add(eo); } } s.setChildServiceCaps(childOptions); Operation factoryPost = Operation.createPost( UriUtils.buildUri(h, s.getClass())) .setCompletion(ctx.getCompletion()); h.startService(factoryPost, s); ctx.await(); String factoryLink = s.getSelfLink(); h.log(Level.INFO, "Started on demand load factory at %s", factoryLink); return factoryLink; }
public static void setFactoryAvailabilityIfOwner(ServiceHost host, String factoryLink, String factoryNodeSelectorPath, boolean isAvailable) { Operation selectOwnerOp = Operation.createPost(null) .setExpiration(Utils.fromNowMicrosUtc(host.getOperationTimeoutMicros())) .setCompletion((o, e) -> { if (e != null) { host.log(Level.WARNING, "Owner selection for %s failed: %s; cannot set factory availability", factoryLink, e.getMessage()); return; } SelectOwnerResponse rsp = o.getBody(SelectOwnerResponse.class); if (rsp.isLocalHostOwner) { ServiceStats.ServiceStat body = new ServiceStats.ServiceStat(); body.name = Service.STAT_NAME_AVAILABLE; body.latestValue = isAvailable ? Service.STAT_VALUE_TRUE : Service.STAT_VALUE_FALSE; Operation op = Operation.createPost( UriUtils.buildAvailableUri(host, factoryLink)) .setBody(body) .setReferer(host.getUri()) .setConnectionSharing(true) .setConnectionTag(ServiceClient.CONNECTION_TAG_SYNCHRONIZATION); host.sendRequest(op); } }); host.selectOwner(factoryNodeSelectorPath, factoryLink, selectOwnerOp); }
timeoutMicros = Math.max(timeoutMicros, getHost().getOperationTimeoutMicros()); queryTask.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(timeoutMicros);
long expMicros = Utils.fromNowMicrosUtc(this.host.getOperationTimeoutMicros());
getHost().getOperationTimeoutMicros())); selectOwnerOp.setCompletion((o, e) -> { OperationContext.restoreOperationContext(opContext);
getHost().getOperationTimeoutMicros())); selectOwnerOp.setCompletion((o, e) -> { OperationContext.restoreOperationContext(opContext);
private void forwardRequestToOwner(Operation op, SelectOwnerResponse rsp, OperationProcessingContext context) { CompletionHandler fc = (fo, fe) -> { if (fe != null) { retryOrFailRequest(op, fo, fe, context); return; } op.setStatusCode(fo.getStatusCode()); op.setBodyNoCloning(fo.getBodyRaw()); op.setContentType(fo.getContentType()); op.setContentLength(fo.getContentLength()); op.transferResponseHeadersFrom(fo); context.resumeProcessingRequest(op, FilterReturnCode.SUCCESS_STOP_PROCESSING, null); op.complete(); }; Operation forwardOp = op.clone().setCompletion(fc); // Forwarded operations are retried until the parent operation, from the client, // expires. Since a peer might have become unresponsive, we want short time outs // and retries, to whatever peer we select, on each retry. ServiceHost host = context.getHost(); forwardOp.setExpiration(Utils.fromNowMicrosUtc( host.getOperationTimeoutMicros() / 10)); forwardOp.setUri(SelectOwnerResponse.buildUriToOwner(rsp, op)); prepareForwardRequest(forwardOp); host.sendRequest(forwardOp); }
TimeUnit.SECONDS.toMicros(getHost().getOperationTimeoutMicros())); t.querySpec = new QuerySpecification(); t.querySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_KIND)
TimeUnit.SECONDS.toMicros(getHost().getOperationTimeoutMicros())); t.querySpec = new QuerySpecification(); t.querySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_KIND)