@After
 public void tearDown() {
   client.close();
   for (VoldemortServer vs : this.vservers.values()) {
     vs.stop();
   }
   for (SocketStoreFactory ssf : this.socketStoreFactories.values()) {
     ssf.close();
   }
   ClusterTestUtils.reset();
 }
Esempio n. 2
0
  /**
   * Get the {@link voldemort.store.socket.SocketStore} to redirect to for the donor, creating one
   * if needed.
   *
   * @param storeName Name of the store
   * @param donorNodeId Donor node id
   * @return <code>SocketStore</code> object for <code>storeName</code> and <code>donorNodeId</code>
   */
  private Store<ByteArray, byte[], byte[]> getRedirectingSocketStore(
      String storeName, int donorNodeId) {
    if (!storeRepository.hasRedirectingSocketStore(storeName, donorNodeId)) {
      synchronized (storeRepository) {
        if (!storeRepository.hasRedirectingSocketStore(storeName, donorNodeId)) {
          Node donorNode = getNodeIfPresent(donorNodeId);
          logger.info(
              "Creating new redirecting store for donor node "
                  + donorNode.getId()
                  + " and store "
                  + storeName);
          storeRepository.addRedirectingSocketStore(
              donorNode.getId(),
              storeFactory.create(
                  storeName,
                  donorNode.getHost(),
                  donorNode.getSocketPort(),
                  RequestFormatType.PROTOCOL_BUFFERS,
                  RequestRoutingType.IGNORE_CHECKS));
        }
      }
    }

    return storeRepository.getRedirectingSocketStore(storeName, donorNodeId);
  }
Esempio n. 3
0
 private Store<ByteArray, byte[], byte[]> createNodeStore(String storeName, Node node) {
   return storeFactory.create(
       storeName,
       node.getHost(),
       node.getSocketPort(),
       voldemortConfig.getRequestFormatType(),
       RequestRoutingType.NORMAL);
 }
  public SocketStoreClientFactory(ClientConfig config) {
    super(config);
    this.requestRoutingType =
        RequestRoutingType.getRequestRoutingType(
            RoutingTier.SERVER.equals(config.getRoutingTier()), false);

    this.storeFactory =
        new ClientRequestExecutorPool(
            config.getSelectors(),
            config.getMaxConnectionsPerNode(),
            config.getConnectionTimeout(TimeUnit.MILLISECONDS),
            config.getSocketTimeout(TimeUnit.MILLISECONDS),
            config.getSocketBufferSize(),
            config.getSocketKeepAlive());
    if (config.isJmxEnabled())
      JmxUtils.registerMbean(storeFactory, JmxUtils.createObjectName(storeFactory.getClass()));
  }
 @Override
 protected Store<ByteArray, byte[], byte[]> getStore(
     String storeName, String host, int port, RequestFormatType type) {
   return storeFactory.create(storeName, host, port, type, requestRoutingType);
 }
Esempio n. 6
0
  @Override
  protected void stopInner() {
    /*
     * We may end up closing a given store more than once, but that is cool
     * because close() is idempotent
     */

    Exception lastException = null;
    logger.info("Closing all stores.");
    /* This will also close the node stores including local stores */
    for (Store<ByteArray, byte[], byte[]> store : this.storeRepository.getAllRoutedStores()) {
      logger.info("Closing routed store for " + store.getName());
      try {
        store.close();
      } catch (Exception e) {
        logger.error(e);
        lastException = e;
      }
    }
    /* This will also close the storage engines */
    for (Store<ByteArray, byte[], byte[]> store : this.storeRepository.getAllStorageEngines()) {
      logger.info("Closing storage engine for " + store.getName());
      try {
        store.close();
      } catch (Exception e) {
        logger.error(e);
        lastException = e;
      }
    }
    logger.info("All stores closed.");

    /* Close slop store if necessary */
    if (this.storeRepository.hasSlopStore()) {
      try {
        this.storeRepository.getSlopStore().close();
      } catch (Exception e) {
        logger.error(e);
        lastException = e;
      }
    }

    /* Close all storage configs */
    logger.info("Closing storage configurations.");
    for (StorageConfiguration config : storageConfigs.values()) {
      logger.info("Closing " + config.getType() + " storage config.");
      try {
        config.close();
      } catch (Exception e) {
        logger.error(e);
        lastException = e;
      }
    }

    this.clientThreadPool.shutdown();

    try {
      if (!this.clientThreadPool.awaitTermination(10, TimeUnit.SECONDS))
        this.clientThreadPool.shutdownNow();
    } catch (InterruptedException e) {
      // okay, fine, playing nice didn't work
      this.clientThreadPool.shutdownNow();
    }

    logger.info("Closed client threadpool.");

    storeFactory.close();

    if (this.failureDetector != null) {
      try {
        this.failureDetector.destroy();
      } catch (Exception e) {
        lastException = e;
      }
    }
    logger.info("Closed failure detector.");

    // shut down the proxy put thread pool
    this.proxyPutWorkerPool.shutdown();
    try {
      if (!this.proxyPutWorkerPool.awaitTermination(10, TimeUnit.SECONDS))
        this.proxyPutWorkerPool.shutdownNow();
    } catch (InterruptedException e) {
      this.proxyPutWorkerPool.shutdownNow();
    }
    logger.info("Closed proxy put thread pool.");

    /* If there is an exception, throw it */
    if (lastException instanceof VoldemortException) throw (VoldemortException) lastException;
    else if (lastException != null) throw new VoldemortException(lastException);
  }