Example #1
0
 /**
  * Get an ESP content manager based on a collection name and a cluster location
  *
  * @param collectionName collection to get manager for
  * @param loc cluster location
  * @param callbackHandler for handling ESP callbacks
  * @return content manager
  * @throws ContentManagerException if an error occurs
  */
 private IContentManager getContentManager(
     String collectionName, ClusterLocation loc, ESPCallbackHandler callbackHandler)
     throws ContentManagerException {
   Cluster cluster = m_clusterManager.getCluster(loc.getClusterId());
   try {
     IContentManagerFactory contentManagerFactory =
         ContentManagerFactory.newInstance(cluster.getProperties());
     return contentManagerFactory.create(
         collectionName, cluster.getProperties(), callbackHandler, 0, false);
   } catch (FactoryException e) {
     throw new ContentManagerException("FactoryException", e);
   }
 }
Example #2
0
  /**
   * @param loc ClusterLocation
   * @param keysToRemove content ids to remove
   * @return ids that failed to purge
   * @throws IndexException if an error occurs
   */
  public Set<String> purgeIndexData(
      final String collectionName, final ClusterLocation loc, final Set<String> keysToRemove)
      throws IndexException {
    if (s_logCategory.isDebugEnabled()) {
      s_logCategory.debug(
          "purgeIndexData("
              + collectionName
              + ","
              + loc.getName()
              + ",...) # items = "
              + keysToRemove.size());
    }
    // if not thing to do, just return empty list
    if (CollectionsUtils.isNullOrEmpty(keysToRemove)) {
      return Collections.emptySet();
    }

    Cluster cluster = m_clusterManager.getCluster(loc.getClusterId());
    if (!cluster.isPurgeEnabled() || !loc.isPurgeEnabled()) {
      s_logCategory.warn(
          "Not processing "
              + keysToRemove.size()
              + " items because purge is disabled on "
              + cluster
              + " and "
              + loc);
      return keysToRemove; // fail all
    }

    try {
      final RoutingAttributes ra = new RoutingAttributes();
      ra.addElement("column", String.valueOf(loc.getColumnId()));

      final List<RoutingAttributes> routingAttributes =
          new ArrayList<RoutingAttributes>(
              Itertools.map(
                  new UnaryFunction<String, RoutingAttributes>() {
                    public RoutingAttributes execute(String key) {
                      return ra;
                    }
                  },
                  keysToRemove));

      Set<String> results =
          new HashSet<String>(
              (new FASTExecuteFunction(collectionName, loc, "purge", keysToRemove) {
                    public String executeWithFAST(IContentManager fast)
                        throws ContentManagerException {
                      // s_logCategory.debug("Calling fast.removeContents() with keys, subsystems
                      // and routing attributes (sz=" + routingAttributes.size() + ")");
                      return fast.removeContents(
                          keysToRemove, Arrays.asList(DOC_PROC, INDEXING), routingAttributes);
                    }
                  })
                  .execute(getBatchTimeoutMillis())
                  .keySet());

      if (!CollectionsUtils.isNullOrEmpty(results)) {
        s_logCategory.info("There were " + results.size() + " failed items at location " + loc);
      }

      if (s_logCategory.isDebugEnabled()) {
        s_logCategory.debug("Failed items at location " + loc.getName() + ": " + results);
      }

      return results;
    } catch (ContentManagerException e) {
      throw new IndexException("ContentManagerException", e);
    }
  }