예제 #1
0
  /**
   * Method to remove an object's metadata entry from the cache given its unique identifier.
   *
   * @param oid the object's unique identifier
   * @return boolean true if successful false otherwise.
   */
  public void removeMetadata(NewObjectIdentifier oid, byte[] MDField, Disk disk)
      throws EMDException {

    // Find the cacheId
    MDHeader header = null;
    try {
      header = new MDHeader(MDField);
    } catch (IOException e) {
      EMDException newe =
          new EMDException("Failed to retrieve the cacheId value [" + e.getMessage() + "]");
      newe.initCause(e);
      throw newe;
    }

    ConnectionFactory.DiskConnection[] connections = new ConnectionFactory.DiskConnection[1];
    connections[0] = ConnectionFactory.getConnection(disk);
    String cacheId = header.getCacheId();

    // Remove the system Metadata
    removeMetadata(oid, CacheClientInterface.SYSTEM_CACHE, connections);

    // Remove the other metadata entry
    if (cacheId != null) {
      removeMetadata(oid, cacheId, connections);
    }
  }
예제 #2
0
  /**
   * This <code>setMetadata</code> method is the OA callback to populate a local cache.
   *
   * @param <code>SystemMetadata</code> are the SystemMetadata extracted from the local fragment
   * @param <code>Disk</code> is the disk containing the fragment
   *     <p>note: this method DEPRECIATED, crawl uses above methods instead. Kept here for reference
   *     until replacement methods are validated.
   */
  public void setMetadata(SystemMetadata systemMD, byte[] MDField, Disk disk) {
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine(
          "setMetadata has been called for oid " + systemMD.getOID() + " on disk [" + disk + "]");
    }

    // Precompute the connection
    ConnectionFactory.DiskConnection[] connections = new ConnectionFactory.DiskConnection[1];
    connections[0] = ConnectionFactory.getConnection(disk);

    // Check if the system metadata should be set
    ArrayList disks =
        MDDiskAbstraction.getInstance((byte) 0)
            .getUsedDisksFromMapId(systemMD.getLayoutMapId(), CacheClientInterface.SYSTEM_CACHE);
    if (disks.contains(disk)) {
      setMetadata(CacheClientInterface.SYSTEM_CACHE, connections, systemMD.getOID(), systemMD);
    }

    try {
      // Find the cacheId
      MDHeader header = new MDHeader(MDField);

      String cacheId = header.getCacheId();

      if (cacheId != null) {
        disks =
            MDDiskAbstraction.getInstance((byte) 0)
                .getUsedDisksFromMapId(systemMD.getLayoutMapId(), cacheId);

        if (disks.contains(disk)) {
          CacheRecord metadataObject =
              CacheManager.getInstance()
                  .getClientInterface(cacheId)
                  .generateMetadataObject(systemMD.getOID());

          // Set the metadata
          setMetadata(cacheId, connections, systemMD.getOID(), metadataObject);
        }
      }

    } catch (IOException e) {
      LOG.log(Level.SEVERE, "Failed to update the metadata [" + e.getMessage() + "]", e);
    } catch (EMDException e) {
      LOG.log(Level.SEVERE, "Failed to update the metadata [" + e.getMessage() + "]", e);
    }
  }
예제 #3
0
  /** Sets metadata for cacheId on given disk (not system MD) */
  private void setExtMetadata(
      NewObjectIdentifier oid,
      String cacheId,
      Disk disk,
      ConnectionFactory.DiskConnection[] connections) {

    // not all layout disks necessarily used, depends on reduncancy
    if (usesDisk(oid.getLayoutMapId(), cacheId, disk)) {
      try {
        CacheRecord metadataObject =
            CacheManager.getInstance().getClientInterface(cacheId).generateMetadataObject(oid);
        // Set the metadata
        setMetadata(cacheId, connections, oid, metadataObject);
      } catch (EMDException e) {
        LOG.log(Level.SEVERE, "Failed to update the metadata [" + e.getMessage() + "]", e);
      }
    }
  }
예제 #4
0
  /**
   * **************************************
   *
   * <p>selectUnique APIs
   *
   * <p>**************************************
   */
  public MetadataClient.SelectUniqueResult selectUnique(
      String cacheId,
      String query,
      String attribute,
      Cookie _cookie,
      int maxResults,
      int timeout,
      boolean forceResults,
      Object[] boundParameters,
      MDOutputStream outputStream)
      throws EMDException {
    // Sanity checks
    if ((_cookie != null) && (maxResults == -1)) {
      // Has to specify an offset AND a row count
      throw new EMDException(
          "Invalid argument : when "
              + "using cookies, you have to "
              + "specify the number of "
              + "entries to return");
    }

    ConnectionFactory.DiskConnection[] connections = ConnectionFactory.getConnections();
    Socket socket = null;
    ArrayList sockets = new ArrayList();
    ObjectBroker[] brokers = null;
    StreamHead[] heads = null;

    try {

      EMDCookie cookie = (EMDCookie) _cookie;
      String lastAttribute = null;
      int toBeSkipped = 0;

      if (cookie != null) {
        query = cookie.getQuery();
        attribute = cookie.getAttribute();
        lastAttribute = cookie.getLastAttribute();
        toBeSkipped = cookie.getToBeSkipped();
        boundParameters = cookie.getBoundParameters();
      }

      // Construct the brokers and launch the queries
      for (int i = 0; i < connections.length; i++) {
        try {
          socket = ConnectionFactory.connect(connections[i]);
          sockets.add(socket);
        } catch (IOException e) {
          LOG.warning(
              "Failed to connect to node "
                  + connections[i].getNodeAddress()
                  + ". Skipping this node ["
                  + e.getMessage()
                  + "]");

          String str = BundleAccess.getInstance().getBundle().getString("warn.emd.selectUnique.io");
          Object[] args = {connections[i].toString()};
          LOG.log(ExtLevel.EXT_WARNING, MessageFormat.format(str, args));

          throw new EMDException(
              "Failed to connect to node "
                  + connections[i].getNodeAddress()
                  + ". Skipping this node.",
              e);
        }
      }

      brokers = new ObjectBroker[sockets.size()];
      heads = new StreamHead[sockets.size()];
      Iterator iter = sockets.iterator();

      for (int i = 0; i < brokers.length; i++) {
        brokers[i] = new ObjectBroker((Socket) iter.next());
        brokers[i].launchSelectUniqueClient(
            cacheId,
            query,
            attribute,
            lastAttribute,
            maxResults + toBeSkipped,
            timeout,
            forceResults,
            boundParameters);
        heads[i] = new StreamHead(brokers[i]);
      }

      // Merge the result and compute the output
      ArrayList array = null;
      Object lastHit = null;

      if (outputStream == null) {
        array = StreamHead.mergeStreams(heads, toBeSkipped, maxResults, false);
        if (array != null && array.size() != 0) lastHit = array.get(array.size() - 1);
      } else {
        StreamHead.mergeStreams(heads, outputStream, toBeSkipped, maxResults);
        lastHit = outputStream.getLastObject();
      }

      MetadataClient.SelectUniqueResult result = new MetadataClient.SelectUniqueResult();
      if (lastHit != null) {

        if (array != null) {
          ArrayList stringList = new ArrayList();
          for (int i = 0; i < array.size(); i++) {
            stringList.add(array.get(i).toString());
          }
          result.results = new StringList(stringList);
        }

        result.cookie = new EMDCookie(lastHit.toString(), query, attribute, 0, boundParameters);
      } else {
        result.cookie = null;
        result.results = StringList.EMPTY_LIST;
      }

      return (result);

    } catch (IOException e) {
      EMDException newe =
          new EMDException("Failed to run the distributed select unique [" + e.getMessage() + "]");
      newe.initCause(e);
      throw newe;
    } finally {
      // Close the connections
      Iterator iter = sockets.iterator();
      while (iter.hasNext()) {
        try {
          ((Socket) iter.next()).close();
        } catch (IOException ignored) {
        }
      }
    }
  }