Example #1
0
 public void addRedirectingSocketStore(int nodeId, Store<ByteArray, byte[], byte[]> store) {
   Pair<String, Integer> key = Pair.create(store.getName(), nodeId);
   Store<ByteArray, byte[], byte[]> found = this.redirectingSocketStores.putIfAbsent(key, store);
   if (found != null)
     throw new VoldemortException(
         "Store '" + store.getName() + "' for node " + nodeId + " has already been initialized.");
 }
Example #2
0
  public void unregisterSystemEngine(StorageEngine<ByteArray, byte[], byte[]> engine) {
    String storeName = engine.getName();
    Store<ByteArray, byte[], byte[]> store = storeRepository.removeLocalStore(storeName);

    if (store != null) {
      if (voldemortConfig.isJmxEnabled()) {
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

        if (voldemortConfig.isEnableRebalanceService()) {

          ObjectName name = null;
          if (this.voldemortConfig.isEnableJmxClusterName())
            name =
                JmxUtils.createObjectName(
                    metadata.getCluster().getName()
                        + "."
                        + JmxUtils.getPackageName(RedirectingStore.class),
                    store.getName());
          else
            name =
                JmxUtils.createObjectName(
                    JmxUtils.getPackageName(RedirectingStore.class), store.getName());

          synchronized (mbeanServer) {
            if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);
          }
        }

        if (voldemortConfig.isStatTrackingEnabled()) {
          ObjectName name = null;
          if (this.voldemortConfig.isEnableJmxClusterName())
            name =
                JmxUtils.createObjectName(
                    metadata.getCluster().getName()
                        + "."
                        + JmxUtils.getPackageName(store.getClass()),
                    store.getName());
          else
            name =
                JmxUtils.createObjectName(
                    JmxUtils.getPackageName(store.getClass()), store.getName());

          synchronized (mbeanServer) {
            if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);
          }
        }
      }
      if (voldemortConfig.isServerRoutingEnabled()) {
        this.storeRepository.removeRoutedStore(storeName);
        for (Node node : metadata.getCluster().getNodes())
          this.storeRepository.removeNodeStore(storeName, node.getId());
      }
    }

    storeRepository.removeStorageEngine(storeName);
    // engine.truncate(); why truncate here when unregister? Isn't close
    // good enough?
    engine.close();
  }
Example #3
0
  public void registerSystemEngine(StorageEngine<ByteArray, byte[], byte[]> engine) {

    Cluster cluster = this.metadata.getCluster();
    storeRepository.addStorageEngine(engine);

    /* Now add any store wrappers that are enabled */
    Store<ByteArray, byte[], byte[]> store = engine;

    if (voldemortConfig.isVerboseLoggingEnabled())
      store =
          new LoggingStore<ByteArray, byte[], byte[]>(
              store, cluster.getName(), SystemTime.INSTANCE);

    if (voldemortConfig.isMetadataCheckingEnabled())
      store = new InvalidMetadataCheckingStore(metadata.getNodeId(), store, metadata);

    if (voldemortConfig.isStatTrackingEnabled()) {
      StatTrackingStore statStore = new StatTrackingStore(store, this.storeStats);
      store = statStore;
      if (voldemortConfig.isJmxEnabled()) {

        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = null;
        if (this.voldemortConfig.isEnableJmxClusterName())
          name =
              JmxUtils.createObjectName(
                  metadata.getCluster().getName() + "." + JmxUtils.getPackageName(store.getClass()),
                  store.getName());
        else
          name =
              JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()), store.getName());

        synchronized (mbeanServer) {
          if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);

          JmxUtils.registerMbean(
              mbeanServer,
              JmxUtils.createModelMBean(new StoreStatsJmx(statStore.getStats())),
              name);
        }
      }
    }

    storeRepository.addLocalStore(store);
  }
Example #4
0
  @Override
  public <K, V, T> Store<K, V, T> getRawStore(
      String storeName, InconsistencyResolver<Versioned<V>> resolver) {

    Store<K, V, T> clientStore = null;

    // The lowest layer : Transporting request to coordinator
    R2Store r2store = null;
    this.d2Client = restClientFactoryConfig.getD2Client();
    if (this.d2Client == null) {
      r2store =
          new R2Store(
              storeName, this.config.getHttpBootstrapURL(), this.transportClient, this.config);
    } else {
      r2store =
          new R2Store(storeName, this.config.getHttpBootstrapURL(), this.d2Client, this.config);
    }

    this.rawStoreList.add(r2store);

    // bootstrap from the coordinator and obtain all the serialization
    // information.
    String serializerInfoXml = r2store.getSerializerInfoXml();
    SerializerDefinition keySerializerDefinition =
        RestUtils.parseKeySerializerDefinition(serializerInfoXml);
    SerializerDefinition valueSerializerDefinition =
        RestUtils.parseValueSerializerDefinition(serializerInfoXml);

    synchronized (this) {
      keySerializerMap.put(storeName, keySerializerDefinition);
      valueSerializerMap.put(storeName, valueSerializerDefinition);
    }

    if (logger.isDebugEnabled()) {
      logger.debug(
          "Bootstrapping for " + storeName + ": Key serializer " + keySerializerDefinition);
      logger.debug(
          "Bootstrapping for " + storeName + ": Value serializer " + valueSerializerDefinition);
    }

    // Start building the stack..
    // First, the transport layer
    Store<ByteArray, byte[], byte[]> store = r2store;

    // TODO: Add jmxId / some unique identifier to the Mbean name
    if (this.config.isEnableJmx()) {
      StatTrackingStore statStore = new StatTrackingStore(store, this.stats);
      store = statStore;
      JmxUtils.registerMbean(
          new StoreStatsJmx(statStore.getStats()),
          JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()), store.getName()));
    }

    // Add compression layer
    if (keySerializerDefinition.hasCompression() || valueSerializerDefinition.hasCompression()) {
      store =
          new CompressingStore(
              store,
              new CompressionStrategyFactory().get(keySerializerDefinition.getCompression()),
              new CompressionStrategyFactory().get(valueSerializerDefinition.getCompression()));
    }

    // Add Serialization layer
    Serializer<K> keySerializer =
        (Serializer<K>) serializerFactory.getSerializer(keySerializerDefinition);
    Serializer<V> valueSerializer =
        (Serializer<V>) serializerFactory.getSerializer(valueSerializerDefinition);
    clientStore = SerializingStore.wrap(store, keySerializer, valueSerializer, null);

    // Add inconsistency Resolving layer
    InconsistencyResolver<Versioned<V>> secondaryResolver =
        resolver == null ? new TimeBasedInconsistencyResolver<V>() : resolver;
    clientStore =
        new InconsistencyResolvingStore<K, V, T>(
            clientStore,
            new ChainedResolver<Versioned<V>>(
                new VectorClockInconsistencyResolver<V>(), secondaryResolver));
    return clientStore;
  }
Example #5
0
 public void addRoutedStore(Store<ByteArray, byte[], byte[]> store) {
   Store<ByteArray, byte[], byte[]> found = this.routedStores.putIfAbsent(store.getName(), store);
   if (found != null)
     throw new VoldemortException("Store '" + store.getName() + "' has already been initialized.");
 }
Example #6
0
  /**
   * Register the given engine with the storage repository
   *
   * @param engine Register the storage engine
   * @param isReadOnly Boolean indicating if this store is read-only
   * @param storeType The type of the store
   * @param storeDef store definition for the store to be registered
   */
  public void registerEngine(
      StorageEngine<ByteArray, byte[], byte[]> engine,
      boolean isReadOnly,
      String storeType,
      StoreDefinition storeDef) {
    Cluster cluster = this.metadata.getCluster();
    storeRepository.addStorageEngine(engine);

    /* Now add any store wrappers that are enabled */
    Store<ByteArray, byte[], byte[]> store = engine;

    boolean isMetadata = store.getName().compareTo(MetadataStore.METADATA_STORE_NAME) == 0;
    boolean isSlop = storeType.compareTo("slop") == 0;
    boolean isView = storeType.compareTo(ViewStorageConfiguration.TYPE_NAME) == 0;

    if (voldemortConfig.isVerboseLoggingEnabled())
      store =
          new LoggingStore<ByteArray, byte[], byte[]>(
              store, cluster.getName(), SystemTime.INSTANCE);
    if (!isSlop) {
      if (!isReadOnly && !isMetadata && !isView) {
        // wrap store to enforce retention policy
        if (voldemortConfig.isEnforceRetentionPolicyOnRead() && storeDef != null) {
          RetentionEnforcingStore retentionEnforcingStore =
              new RetentionEnforcingStore(
                  store,
                  storeDef,
                  voldemortConfig.isDeleteExpiredValuesOnRead(),
                  SystemTime.INSTANCE);
          metadata.addMetadataStoreListener(store.getName(), retentionEnforcingStore);
          store = retentionEnforcingStore;
        }

        if (voldemortConfig.isEnableRebalanceService()) {
          ProxyPutStats proxyPutStats = new ProxyPutStats(aggregatedProxyPutStats);
          if (voldemortConfig.isJmxEnabled()) {
            JmxUtils.registerMbean(
                proxyPutStats,
                JmxUtils.createObjectName(
                    "voldemort.store.rebalancing", engine.getName() + "-proxy-puts"));
          }
          store =
              new RedirectingStore(
                  store,
                  metadata,
                  storeRepository,
                  failureDetector,
                  storeFactory,
                  proxyPutWorkerPool,
                  proxyPutStats);
          if (voldemortConfig.isJmxEnabled()) {
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            ObjectName name = null;
            if (this.voldemortConfig.isEnableJmxClusterName())
              name =
                  JmxUtils.createObjectName(
                      cluster.getName() + "." + JmxUtils.getPackageName(RedirectingStore.class),
                      store.getName());
            else
              name =
                  JmxUtils.createObjectName(
                      JmxUtils.getPackageName(RedirectingStore.class), store.getName());

            synchronized (mbeanServer) {
              if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);

              JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(store), name);
            }
          }
        }
      }

      if (voldemortConfig.isMetadataCheckingEnabled() && !isMetadata) {
        store = new InvalidMetadataCheckingStore(metadata.getNodeId(), store, metadata);
      }
    }

    if (voldemortConfig.isStatTrackingEnabled()) {
      StatTrackingStore statStore = new StatTrackingStore(store, this.storeStats);
      store = statStore;
      if (voldemortConfig.isJmxEnabled()) {

        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = null;
        if (this.voldemortConfig.isEnableJmxClusterName())
          name =
              JmxUtils.createObjectName(
                  metadata.getCluster().getName() + "." + JmxUtils.getPackageName(store.getClass()),
                  store.getName());
        else
          name =
              JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()), store.getName());

        synchronized (mbeanServer) {
          if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);

          JmxUtils.registerMbean(
              mbeanServer,
              JmxUtils.createModelMBean(new StoreStatsJmx(statStore.getStats())),
              name);
        }
      }

      // Wrap everything under the rate limiting store (barring the
      // metadata store)
      if (voldemortConfig.isEnableQuotaLimiting() && !isMetadata) {
        FileBackedCachingStorageEngine quotaStore =
            (FileBackedCachingStorageEngine)
                storeRepository.getStorageEngine(
                    SystemStoreConstants.SystemStoreName.voldsys$_store_quotas.toString());
        QuotaLimitStats quotaStats = new QuotaLimitStats(this.aggregatedQuotaStats);
        QuotaLimitingStore rateLimitingStore =
            new QuotaLimitingStore(store, this.storeStats, quotaStats, quotaStore);
        if (voldemortConfig.isJmxEnabled()) {
          JmxUtils.registerMbean(
              this.aggregatedQuotaStats,
              JmxUtils.createObjectName(
                  "voldemort.store.quota", store.getName() + "-quota-limit-stats"));
        }
        store = rateLimitingStore;
      }
    }

    storeRepository.addLocalStore(store);
  }
Example #7
0
  /**
   * Unregister and remove the engine from the storage repository. This is called during deletion of
   * stores and if there are exceptions adding/opening stores
   *
   * @param engine The actual engine to remove
   * @param isReadOnly Is this read-only?
   * @param storeType The storage type of the store
   * @param truncate Should the store be truncated?
   */
  public void removeEngine(
      StorageEngine<ByteArray, byte[], byte[]> engine,
      boolean isReadOnly,
      String storeType,
      boolean truncate) {
    String storeName = engine.getName();
    Store<ByteArray, byte[], byte[]> store = storeRepository.removeLocalStore(storeName);

    boolean isSlop = storeType.compareTo("slop") == 0;
    boolean isView = storeType.compareTo(ViewStorageConfiguration.TYPE_NAME) == 0;
    boolean isMetadata = storeName.compareTo(MetadataStore.METADATA_STORE_NAME) == 0;

    if (store != null) {
      if (voldemortConfig.isJmxEnabled()) {
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

        if (!isSlop
            && voldemortConfig.isEnableRebalanceService()
            && !isReadOnly
            && !isMetadata
            && !isView) {

          ObjectName name = null;
          if (this.voldemortConfig.isEnableJmxClusterName())
            name =
                JmxUtils.createObjectName(
                    metadata.getCluster().getName()
                        + "."
                        + JmxUtils.getPackageName(RedirectingStore.class),
                    store.getName());
          else
            name =
                JmxUtils.createObjectName(
                    JmxUtils.getPackageName(RedirectingStore.class), store.getName());

          synchronized (mbeanServer) {
            if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);
          }
        }

        if (voldemortConfig.isStatTrackingEnabled()) {
          ObjectName name = null;
          if (this.voldemortConfig.isEnableJmxClusterName())
            name =
                JmxUtils.createObjectName(
                    metadata.getCluster().getName()
                        + "."
                        + JmxUtils.getPackageName(store.getClass()),
                    store.getName());
          else
            name =
                JmxUtils.createObjectName(
                    JmxUtils.getPackageName(store.getClass()), store.getName());

          synchronized (mbeanServer) {
            if (mbeanServer.isRegistered(name)) JmxUtils.unregisterMbean(mbeanServer, name);
          }
        }
      }
      if (voldemortConfig.isServerRoutingEnabled() && !isSlop) {
        this.storeRepository.removeRoutedStore(storeName);
        for (Node node : metadata.getCluster().getNodes())
          this.storeRepository.removeNodeStore(storeName, node.getId());
      }
    }

    storeRepository.removeStorageEngine(storeName);
    if (truncate) engine.truncate();
    engine.close();
  }
Example #8
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);
  }
Example #9
0
 @Override
 public boolean equals(Object o) {
   if (o == null || !Store.class.isAssignableFrom(o.getClass())) return false;
   Store<?, ?> s = (Store<?, ?>) o;
   return s.getName().equals(s.getName());
 }
Example #10
0
  protected void outputJSON(HttpServletResponse response) {
    StringBuilder sb = new StringBuilder("{\n");

    sb.append("  \"servertime\": \"");
    sb.append(new Date());
    sb.append("\",");

    sb.append("\n  \"server\": \"");
    sb.append(myMachine);
    sb.append("\",");

    sb.append("\n  \"node\": \"");
    sb.append(server.getMetadataStore().getNodeId());
    sb.append("\",");

    sb.append("\n  \"uptime\": \"");
    sb.append(abstractSocketService.getStatusManager().getFormattedUptime());
    sb.append("\",");

    sb.append("\n  \"num_workers\": ");
    sb.append(abstractSocketService.getStatusManager().getActiveWorkersCount());
    sb.append(",");

    sb.append("\n  \"pool_size\": ");
    sb.append(abstractSocketService.getStatusManager().getWorkerPoolSize());
    sb.append(",");

    sb.append("\n  \"stores\": {");

    int i = 0;
    for (Store<ByteArray, byte[], byte[]> store : server.getStoreRepository().getAllLocalStores()) {

      if (i++ > 0) {
        sb.append(",");
      }
      sb.append("\n    \"");
      sb.append(store.getName());
      sb.append("\" : {\n");

      if (store instanceof StatTrackingStore) {
        StatTrackingStore statStore = (StatTrackingStore) store;
        Map<Tracked, RequestCounter> stats = statStore.getStats().getCounters();
        for (Tracked t : Tracked.values()) {
          if (t == Tracked.EXCEPTION) {
            continue;
          }
          sb.append(fillCommonStats(stats, t));
        }
        sb.append(",\n        \"num_exceptions\": ");
        sb.append(statStore.getStats().getCount(Tracked.EXCEPTION));
        sb.append("\n");
        sb.append("    }");
      }

      if (store instanceof QuotaLimitingStore) {
        QuotaLimitingStore quotaStore = (QuotaLimitingStore) store;
        Map<Tracked, RequestCounter> stats = quotaStore.getStats().getCounters();
        for (Tracked t : Tracked.values()) {
          if (t == Tracked.EXCEPTION) {
            continue;
          }
          sb.append(fillCommonStats(stats, t));
        }
        sb.append(",\n        \"num_exceptions\": ");
        sb.append(quotaStore.getStats().getCount(Tracked.EXCEPTION));
        sb.append("\n");
        sb.append("    }");
      }
    }

    sb.append("\n  }\n");
    sb.append("}\n");

    try {
      response.setContentType("text/plain");
      OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
      writer.write(sb.toString());
      writer.flush();
    } catch (Exception e) {
      throw new VoldemortException(e);
    }
  }