Ejemplo n.º 1
0
  /**
   * convert Object to String depending on key.
   *
   * <p>StoreRepository takes only StorageEngine<ByteArray,byte[]> and for persistence on disk we
   * need to convert them to String.<br>
   *
   * @param key
   * @param value
   * @return
   */
  private Versioned<Object> convertStringToObject(String key, Versioned<String> value) {
    Object valueObject = null;

    if (CLUSTER_KEY.equals(key)) {
      valueObject = clusterMapper.readCluster(new StringReader(value.getValue()));
    } else if (STORES_KEY.equals(key)) {
      valueObject = storeMapper.readStoreList(new StringReader(value.getValue()));
    } else if (SERVER_STATE_KEY.equals(key) || CLUSTER_STATE_KEY.equals(key)) {
      valueObject = VoldemortState.valueOf(value.getValue());
    } else if (NODE_ID_KEY.equals(key)) {
      valueObject = Integer.parseInt(value.getValue());
    } else if (REBALANCING_STEAL_INFO.equals(key)) {
      String valueString = value.getValue();
      if (valueString.startsWith("[")) {
        valueObject = RebalancerState.create(valueString);
      } else {
        valueObject =
            new RebalancerState(Arrays.asList(RebalancePartitionsInfo.create(valueString)));
      }
    } else {
      throw new VoldemortException(
          "Unhandled key:'" + key + "' for String to Object serialization.");
    }

    return new Versioned<Object>(valueObject, value.getVersion());
  }
Ejemplo n.º 2
0
  public void cleanRebalancingState(RebalancePartitionsInfo stealInfo) {
    synchronized (lock) {
      RebalancerState rebalancerState = getRebalancerState();

      if (!rebalancerState.remove(stealInfo))
        throw new IllegalArgumentException("Couldn't find " + stealInfo + " in " + rebalancerState);

      if (rebalancerState.isEmpty()) {
        logger.debug("stealInfoList empty, cleaning all rebalancing state");
        cleanAllRebalancingState();
      } else {
        put(REBALANCING_STEAL_INFO, rebalancerState);
        initCache(REBALANCING_STEAL_INFO);
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * Converts Object to byte[] depending on the key
   *
   * <p>StoreRepository takes only StorageEngine<ByteArray,byte[]> and for persistence on disk we
   * need to convert them to String.<br>
   *
   * @param key
   * @param value
   * @return
   */
  @SuppressWarnings("unchecked")
  private Versioned<String> convertObjectToString(String key, Versioned<Object> value) {
    String valueStr = value.getValue().toString();

    if (CLUSTER_KEY.equals(key)) {
      valueStr = clusterMapper.writeCluster((Cluster) value.getValue());
    } else if (STORES_KEY.equals(key)) {
      valueStr = storeMapper.writeStoreList((List<StoreDefinition>) value.getValue());
    } else if (REBALANCING_STEAL_INFO.equals(key)) {
      RebalancerState rebalancerState = (RebalancerState) value.getValue();
      valueStr = rebalancerState.toJsonString();
    } else if (SERVER_STATE_KEY.equals(key)
        || CLUSTER_STATE_KEY.equals(key)
        || NODE_ID_KEY.equals(key)) {
      valueStr = value.getValue().toString();
    } else {
      throw new VoldemortException(
          "Unhandled key:'" + key + "' for Object to String serialization.");
    }

    return new Versioned<String>(valueStr, value.getVersion());
  }