Search in sources :

Example 41 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project pulsar by yahoo.

the class OwnershipCacheTest method testRemoveOwnership.

@Test
public void testRemoveOwnership() throws Exception {
    OwnershipCache cache = new OwnershipCache(this.pulsar, bundleFactory);
    NamespaceName testNs = new NamespaceName("pulsar/test/ns-7");
    NamespaceBundle bundle = bundleFactory.getFullBundle(testNs);
    // case 1: no one owns the namespace
    assertFalse(cache.getOwnerAsync(bundle).get().isPresent());
    cache.removeOwnership(bundle).get();
    assertTrue(cache.getOwnedBundles().isEmpty());
    // case 2: this broker owns the namespace
    NamespaceEphemeralData data1 = cache.tryAcquiringOwnership(bundle).get();
    assertEquals(data1.getNativeUrl(), selfBrokerUrl);
    assertTrue(!data1.isDisabled());
    assertTrue(cache.getOwnedBundles().size() == 1);
    cache.removeOwnership(bundle);
    Thread.sleep(500);
    assertTrue(cache.getOwnedBundles().isEmpty());
    Thread.sleep(500);
    try {
        zkCache.getZooKeeper().getData(ServiceUnitZkUtils.path(bundle), null, null);
        fail("Should have failed");
    } catch (NoNodeException nne) {
    // OK
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Test(org.testng.annotations.Test)

Example 42 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project pulsar by yahoo.

the class Namespaces method createNamespace.

@PUT
@Path("/{property}/{cluster}/{namespace}")
@ApiOperation(value = "Creates a new empty namespace with no policies attached.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), @ApiResponse(code = 409, message = "Namespace already exists"), @ApiResponse(code = 412, message = "Namespace name is not valid") })
public void createNamespace(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, BundlesData initialBundles) {
    validateAdminAccessOnProperty(property);
    validatePoliciesReadOnlyAccess();
    // check is made at the time of setting replication.
    if (!cluster.equals(GLOBAL_CLUSTER)) {
        validateClusterForProperty(property, cluster);
    }
    if (!clusters().contains(cluster)) {
        log.warn("[{}] Failed to create namespace. Cluster {} does not exist", clientAppId(), cluster);
        throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
    }
    try {
        checkNotNull(propertiesCache().get(path("policies", property)));
    } catch (NoNodeException nne) {
        log.warn("[{}] Failed to create namespace. Property {} does not exist", clientAppId(), property);
        throw new RestException(Status.NOT_FOUND, "Property does not exist");
    } catch (RestException e) {
        throw e;
    } catch (Exception e) {
        throw new RestException(e);
    }
    try {
        NamedEntity.checkName(namespace);
        policiesCache().invalidate(path("policies", property, cluster, namespace));
        Policies policies = new Policies();
        if (initialBundles != null && initialBundles.getNumBundles() > 0) {
            if (initialBundles.getBoundaries() == null || initialBundles.getBoundaries().size() == 0) {
                policies.bundles = getBundles(initialBundles.getNumBundles());
            } else {
                policies.bundles = validateBundlesData(initialBundles);
            }
        }
        zkCreateOptimistic(path("policies", property, cluster, namespace), jsonMapper().writeValueAsBytes(policies));
        log.info("[{}] Created namespace {}/{}/{}", clientAppId(), property, cluster, namespace);
    } catch (KeeperException.NodeExistsException e) {
        log.warn("[{}] Failed to create namespace {}/{}/{} - already exists", clientAppId(), property, cluster, namespace);
        throw new RestException(Status.CONFLICT, "Namespace already exists");
    } catch (IllegalArgumentException e) {
        log.warn("[{}] Failed to create namespace with invalid name {}", clientAppId(), property, e);
        throw new RestException(Status.PRECONDITION_FAILED, "Namespace name is not valid");
    } catch (Exception e) {
        log.error("[{}] Failed to create namespace {}/{}/{}", clientAppId(), property, cluster, namespace, e);
        throw new RestException(e);
    }
}
Also used : Policies(com.yahoo.pulsar.common.policies.data.Policies) PersistencePolicies(com.yahoo.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) WebApplicationException(javax.ws.rs.WebApplicationException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) KeeperException(org.apache.zookeeper.KeeperException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 43 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project lucene-solr by apache.

the class LeaderElectionTest method getLeaderUrl.

private String getLeaderUrl(final String collection, final String slice) throws KeeperException, InterruptedException {
    int iterCount = 60;
    while (iterCount-- > 0) {
        try {
            byte[] data = zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null, true);
            ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data));
            return leaderProps.getCoreUrl();
        } catch (NoNodeException | SessionExpiredException e) {
            Thread.sleep(500);
        }
    }
    zkClient.printLayoutToStdOut();
    throw new RuntimeException("Could not get leader props");
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException)

Example 44 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project lucene-solr by apache.

the class ZkController method persistConfigResourceToZooKeeper.

/**
   * Persists a config file to ZooKeeper using optimistic concurrency.
   *
   * @return true on success
   */
public static int persistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader, int znodeVersion, String resourceName, byte[] content, boolean createIfNotExists) {
    int latestVersion = znodeVersion;
    final ZkController zkController = zkLoader.getZkController();
    final SolrZkClient zkClient = zkController.getZkClient();
    final String resourceLocation = zkLoader.getConfigSetZkPath() + "/" + resourceName;
    String errMsg = "Failed to persist resource at {0} - old {1}";
    try {
        try {
            Stat stat = zkClient.setData(resourceLocation, content, znodeVersion, true);
            // if the set succeeded , it should have incremented the version by one always
            latestVersion = stat.getVersion();
            log.info("Persisted config data to node {} ", resourceLocation);
            touchConfDir(zkLoader);
        } catch (NoNodeException e) {
            if (createIfNotExists) {
                try {
                    zkClient.create(resourceLocation, content, CreateMode.PERSISTENT, true);
                    //just created so version must be zero
                    latestVersion = 0;
                    touchConfDir(zkLoader);
                } catch (KeeperException.NodeExistsException nee) {
                    try {
                        Stat stat = zkClient.exists(resourceLocation, null, true);
                        log.debug("failed to set data version in zk is {} and expected version is {} ", stat.getVersion(), znodeVersion);
                    } catch (Exception e1) {
                        log.warn("could not get stat");
                    }
                    log.info(StrUtils.formatString(errMsg, resourceLocation, znodeVersion));
                    throw new ResourceModifiedInZkException(ErrorCode.CONFLICT, StrUtils.formatString(errMsg, resourceLocation, znodeVersion) + ", retry.");
                }
            }
        }
    } catch (KeeperException.BadVersionException bve) {
        int v = -1;
        try {
            Stat stat = zkClient.exists(resourceLocation, null, true);
            v = stat.getVersion();
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        log.info(StrUtils.formatString(errMsg + " zkVersion= " + v, resourceLocation, znodeVersion));
        throw new ResourceModifiedInZkException(ErrorCode.CONFLICT, StrUtils.formatString(errMsg, resourceLocation, znodeVersion) + ", retry.");
    } catch (ResourceModifiedInZkException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof InterruptedException) {
            // Restore the interrupted status
            Thread.currentThread().interrupt();
        }
        final String msg = "Error persisting resource at " + resourceLocation;
        log.error(msg, e);
        throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
    }
    return latestVersion;
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) TimeoutException(java.util.concurrent.TimeoutException) SolrException(org.apache.solr.common.SolrException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SolrCoreInitializationException(org.apache.solr.core.SolrCoreInitializationException) Stat(org.apache.zookeeper.data.Stat) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) KeeperException(org.apache.zookeeper.KeeperException) SolrException(org.apache.solr.common.SolrException)

Aggregations

NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)44 KeeperException (org.apache.zookeeper.KeeperException)30 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)16 IOException (java.io.IOException)12 Stat (org.apache.zookeeper.data.Stat)12 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)11 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)9 Job (com.spotify.helios.common.descriptors.Job)8 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)8 JobId (com.spotify.helios.common.descriptors.JobId)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UnknownHostException (java.net.UnknownHostException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)5 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)5 SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)5 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)4 UUID (java.util.UUID)4 TimeoutException (java.util.concurrent.TimeoutException)4