Java Code Examples for org.apache.solr.update.DeleteUpdateCommand#setVersion()

The following examples show how to use org.apache.solr.update.DeleteUpdateCommand#setVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DistributedUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void doLocalDeleteByQuery(DeleteUpdateCommand cmd, long versionOnUpdate, boolean isReplayOrPeersync) throws IOException {
  if (versionsStored) {
    final boolean leaderLogic = isLeader & !isReplayOrPeersync;
    if (leaderLogic) {
      long version = vinfo.getNewClock();
      cmd.setVersion(-version);
      // TODO update versions in all buckets

      doLocalDelete(cmd);

    } else {
      cmd.setVersion(-versionOnUpdate);

      if (ulog.getState() != UpdateLog.State.ACTIVE && isReplayOrPeersync == false) {
        // we're not in an active state, and this update isn't from a replay, so buffer it.
        cmd.setFlags(cmd.getFlags() | UpdateCommand.BUFFERING);
        ulog.deleteByQuery(cmd);
        return;
      }

      if (!isSubShardLeader && replicaType == Replica.Type.TLOG && (cmd.getFlags() & UpdateCommand.REPLAY) == 0) {
        // TLOG replica not leader, don't write the DBQ to IW
        cmd.setFlags(cmd.getFlags() | UpdateCommand.IGNORE_INDEXWRITER);
      }
      doLocalDelete(cmd);
    }
  }
}
 
Example 2
Source File: JavabinLoader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void delete(SolrQueryRequest req, UpdateRequest update, UpdateRequestProcessor processor) throws IOException {
  SolrParams params = update.getParams();
  DeleteUpdateCommand delcmd = new DeleteUpdateCommand(req);
  if(params != null) {
    delcmd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);
  }
  
  if(update.getDeleteByIdMap() != null) {
    Set<Entry<String,Map<String,Object>>> entries = update.getDeleteByIdMap().entrySet();
    for (Entry<String,Map<String,Object>> e : entries) {
      delcmd.id = e.getKey();
      Map<String,Object> map = e.getValue();
      if (map != null) {
        Long version = (Long) map.get("ver");
        if (version != null) {
          delcmd.setVersion(version);
        }
      }
      if (map != null) {
        String route = (String) map.get(ShardParams._ROUTE_);
        if (route != null) {
          delcmd.setRoute(route);
        }
      }
      processor.processDelete(delcmd);
      delcmd.clear();
    }
  }
  
  if(update.getDeleteQuery() != null) {
    for (String s : update.getDeleteQuery()) {
      delcmd.query = s;
      processor.processDelete(delcmd);
    }
  }
}
 
Example 3
Source File: XmlUpdateRequestHandlerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void expectDelete(String id, String query, int commitWithin, long version, String route) {
  DeleteUpdateCommand cmd = new DeleteUpdateCommand(null);
  cmd.id = id;
  cmd.query = query;
  cmd.commitWithin = commitWithin;
  if (version!=0)
    cmd.setVersion(version);
  if (route!=null)
    cmd.setRoute(route);
  deleteCommands.add(cmd);
}
 
Example 4
Source File: DistributedUpdateProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * This method is used when an update on which a particular in-place update has been lost for some reason. This method
 * sends a request to the shard leader to fetch the latest full document as seen on the leader.
 * @return AddUpdateCommand containing latest full doc at shard leader for the given id, or null if not found.
 */
private UpdateCommand fetchFullUpdateFromLeader(AddUpdateCommand inplaceAdd, long versionOnUpdate) throws IOException {
  String id = inplaceAdd.getPrintableId();
  UpdateShardHandler updateShardHandler = inplaceAdd.getReq().getCore().getCoreContainer().getUpdateShardHandler();
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(DISTRIB, false);
  params.set("getInputDocument", id);
  params.set("onlyIfActive", true);
  SolrRequest<SimpleSolrResponse> ur = new GenericSolrRequest(METHOD.GET, "/get", params);

  String leaderUrl = getLeaderUrl(id);

  if(leaderUrl == null) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Can't find document with id=" + id);
  }

  NamedList<Object> rsp;
  try {
    ur.setBasePath(leaderUrl);
    rsp = updateShardHandler.getUpdateOnlyHttpClient().request(ur);
  } catch (SolrServerException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Error during fetching [" + id +
        "] from leader (" + leaderUrl + "): ", e);
  }
  Object inputDocObj = rsp.get("inputDocument");
  Long version = (Long)rsp.get("version");
  SolrInputDocument leaderDoc = (SolrInputDocument) inputDocObj;

  if (leaderDoc == null) {
    // this doc was not found (deleted) on the leader. Lets delete it here as well.
    DeleteUpdateCommand del = new DeleteUpdateCommand(inplaceAdd.getReq());
    del.setIndexedId(inplaceAdd.getIndexedId());
    del.setId(inplaceAdd.getIndexedId().utf8ToString());
    del.setVersion((version == null || version == 0)? -versionOnUpdate: version);
    return del;
  }

  AddUpdateCommand cmd = new AddUpdateCommand(req);
  cmd.solrDoc = leaderDoc;
  cmd.setVersion((long)leaderDoc.getFieldValue(CommonParams.VERSION_FIELD));
  return cmd;
}