Java Code Examples for org.apache.lucene.store.DataInput#readVInt()

The following examples show how to use org.apache.lucene.store.DataInput#readVInt() . 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: SimpleServer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Pulls CopyState off the wire */
static CopyState readCopyState(DataInput in) throws IOException {

  // Decode a new CopyState
  byte[] infosBytes = new byte[in.readVInt()];
  in.readBytes(infosBytes, 0, infosBytes.length);

  long gen = in.readVLong();
  long version = in.readVLong();
  Map<String,FileMetaData> files = readFilesMetaData(in);

  int count = in.readVInt();
  Set<String> completedMergeFiles = new HashSet<>();
  for(int i=0;i<count;i++) {
    completedMergeFiles.add(in.readString());
  }
  long primaryGen = in.readVLong();

  return new CopyState(files, version, gen, infosBytes, completedMergeFiles, primaryGen, null);
}
 
Example 2
Source File: SimplePrimaryNode.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void handleAddDocument(DataInput in, DataOutput out) throws IOException {
  int fieldCount = in.readVInt();
  Document doc = new Document();
  for(int i=0;i<fieldCount;i++) {
    String name = in.readString();
    String value = in.readString();
    // NOTE: clearly NOT general!
    if (name.equals("docid") || name.equals("marker")) {
      doc.add(new StringField(name, value, Field.Store.YES));
    } else if (name.equals("title")) {
      doc.add(new StringField("title", value, Field.Store.YES));
      doc.add(new Field("titleTokenized", value, tokenizedWithTermVectors));
    } else if (name.equals("body")) {
      doc.add(new Field("body", value, tokenizedWithTermVectors));
    } else {
      throw new IllegalArgumentException("unhandled field name " + name);
    }
  }
  writer.addDocument(doc);
}
 
Example 3
Source File: BlockHeader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public BlockHeader read(DataInput input, BlockHeader reuse) throws IOException {
  int linesCount = input.readVInt();
  if (linesCount <= 0 || linesCount > UniformSplitTermsWriter.MAX_NUM_BLOCK_LINES) {
    throw new CorruptIndexException("Illegal number of lines in block: " + linesCount, input);
  }

  long baseDocsFP = input.readVLong();
  long basePositionsFP = input.readVLong();
  long basePayloadsFP = input.readVLong();

  int termStatesBaseOffset = input.readVInt();
  if (termStatesBaseOffset < 0) {
    throw new CorruptIndexException("Illegal termStatesBaseOffset= " + termStatesBaseOffset, input);
  }
  int middleTermOffset = input.readVInt();
  if (middleTermOffset < 0) {
    throw new CorruptIndexException("Illegal middleTermOffset= " + middleTermOffset, input);
  }

  BlockHeader blockHeader = reuse == null ? new BlockHeader() : reuse;
  return blockHeader.reset(linesCount, baseDocsFP, basePositionsFP, basePayloadsFP, termStatesBaseOffset, middleTermOffset);
}
 
Example 4
Source File: FSTTermOutputs.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void skipOutput(DataInput in) throws IOException {
  int bits = in.readByte() & 0xff;
  int bit0 = bits & 1;
  int bit1 = bits & 2;
  int bytesSize = (bits >>> 2);
  if (bit0 > 0 && bytesSize == 0) {  // determine extra length
    bytesSize = in.readVInt();
  }
  if (bit0 > 0) {  // bytes exists
    in.skipBytes(bytesSize);
  }
  if (bit1 > 0) {  // stats exist
    int code = in.readVInt();
    if (hasPos && (code & 1) == 0) {
      in.readVLong();
    }
  }
}
 
Example 5
Source File: FSTOrdsOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void skipOutput(DataInput in) throws IOException {
  int len = in.readVInt();
  in.skipBytes(len);
  in.readVLong();
  in.readVLong();
}
 
Example 6
Source File: IDVersionPostingsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void decodeTerm(DataInput in, FieldInfo fieldInfo, BlockTermState _termState, boolean absolute)
  throws IOException {
  final IDVersionTermState termState = (IDVersionTermState) _termState;
  termState.docID = in.readVInt();
  if (absolute) {
    termState.idVersion = in.readVLong();
  } else {
    termState.idVersion += in.readZLong();
  }
}
 
Example 7
Source File: ByteSequenceOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public BytesRef read(DataInput in) throws IOException {
  final int len = in.readVInt();
  if (len == 0) {
    return NO_OUTPUT;
  } else {
    final BytesRef output = new BytesRef(len);
    in.readBytes(output.bytes, 0, len);
    output.length = len;
    return output;
  }
}
 
Example 8
Source File: FST.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Reads one BYTE1/2/4 label from the provided {@link DataInput}. */
public int readLabel(DataInput in) throws IOException {
  final int v;
  if (inputType == INPUT_TYPE.BYTE1) {
    // Unsigned byte:
    v = in.readByte() & 0xFF;
  } else if (inputType == INPUT_TYPE.BYTE2) {
    // Unsigned short:
    v = in.readShort() & 0xFFFF;
  } else { 
    v = in.readVInt();
  }
  return v;
}
 
Example 9
Source File: AnalyzingSuggester.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public boolean load(DataInput input) throws IOException {
  count = input.readVLong();
  this.fst = new FST<>(input, input, new PairOutputs<>(PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton()));
  maxAnalyzedPathsForOneInput = input.readVInt();
  hasPayloads = input.readByte() == 1;
  return true;
}
 
Example 10
Source File: CharSequenceOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void skipOutput(DataInput in) throws IOException {
  final int len = in.readVInt();
  for(int idx=0;idx<len;idx++) {
    in.readVInt();
  }
}
 
Example 11
Source File: STBlockLine.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Reads all the field ids in the current block line of the provided input.
 */
public int[] readFieldIds(DataInput termStatesInput, int numFields) throws IOException {
  int[] fieldIds = new int[numFields];
  for (int i = 0; i < numFields; i++) {
    fieldIds[i] = termStatesInput.readVInt();
  }
  return fieldIds;
}
 
Example 12
Source File: DocValuesUpdate.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static BytesRef readFrom(DataInput in, BytesRef scratch) throws IOException {
  scratch.length = in.readVInt();
  if (scratch.bytes.length < scratch.length) {
    scratch.bytes = ArrayUtil.grow(scratch.bytes, scratch.length);
  }
  in.readBytes(scratch.bytes, 0, scratch.length);
  return scratch;
}
 
Example 13
Source File: BlockLine.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the current line.
 *
 * @param isIncrementalEncodingSeed Whether the term is a seed of the
 *                                  incremental encoding. {@code true} for the first and
 *                                  middle term, {@code false} for other terms.
 * @param reuse                     A {@link BlockLine} instance to reuse; or null if none.
 */
public BlockLine readLine(DataInput blockInput, boolean isIncrementalEncodingSeed, BlockLine reuse) throws IOException {
  int termStateRelativeOffset = blockInput.readVInt();
  if (termStateRelativeOffset < 0) {
    throw new CorruptIndexException("Illegal termStateRelativeOffset= " + termStateRelativeOffset, blockInput);
  }
  return reuse == null ?
      new BlockLine(readIncrementallyEncodedTerm(blockInput, isIncrementalEncodingSeed, null), termStateRelativeOffset)
      : reuse.reset(readIncrementallyEncodedTerm(blockInput, isIncrementalEncodingSeed, reuse.termBytes), termStateRelativeOffset);
}
 
Example 14
Source File: XAnalyzingSuggester.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public boolean load(InputStream input) throws IOException {
  DataInput dataIn = new InputStreamDataInput(input);
  try {
    this.fst = new FST<>(dataIn, new PairOutputs<>(PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton()));
    maxAnalyzedPathsForOneInput = dataIn.readVInt();
    hasPayloads = dataIn.readByte() == 1;
  } finally {
    IOUtils.close(input);
  }
  return true;
}
 
Example 15
Source File: FSTTermOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public TermData read(DataInput in) throws IOException {
  byte[] bytes = null;
  int docFreq = 0;
  long totalTermFreq = -1;
  int bits = in.readByte() & 0xff;
  int bit0 = bits & 1;
  int bit1 = bits & 2;
  int bytesSize = (bits >>> 2);
  if (bit0 > 0 && bytesSize == 0) {  // determine extra length
    bytesSize = in.readVInt();
  }
  if (bit0 > 0) {  // bytes exists
    bytes = new byte[bytesSize];
    in.readBytes(bytes, 0, bytesSize);
  }
  if (bit1 > 0) {  // stats exist
    int code = in.readVInt();
    if (hasPos) {
      totalTermFreq = docFreq = code >>> 1;
      if ((code & 1) == 0) {
        totalTermFreq += in.readVLong();
      }
    } else {
      docFreq = code;
    }
  }
  return new TermData(bytes, docFreq, totalTermFreq);
}
 
Example 16
Source File: IntSequenceOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public IntsRef read(DataInput in) throws IOException {
  final int len = in.readVInt();
  if (len == 0) {
    return NO_OUTPUT;
  } else {
    final IntsRef output = new IntsRef(len);
    for(int idx=0;idx<len;idx++) {
      output.ints[idx] = in.readVInt();
    }
    output.length = len;
    return output;
  }
}
 
Example 17
Source File: ByteSequenceOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void skipOutput(DataInput in) throws IOException {
  final int len = in.readVInt();
  if (len != 0) {
    in.skipBytes(len);
  }
}
 
Example 18
Source File: CharSequenceOutputs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public CharsRef read(DataInput in) throws IOException {
  final int len = in.readVInt();
  if (len == 0) {
    return NO_OUTPUT;
  } else {
    final CharsRef output = new CharsRef(len);
    for(int idx=0;idx<len;idx++) {
      output.chars[idx] = (char) in.readVInt();
    }
    output.length = len;
    return output;
  }
}
 
Example 19
Source File: XAnalyzingSuggester.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public boolean load(DataInput input) throws IOException {
  count = input.readVLong();
  this.fst = new FST<>(input, new PairOutputs<>(PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton()));
  maxAnalyzedPathsForOneInput = input.readVInt();
  hasPayloads = input.readByte() == 1;
  return true;
}
 
Example 20
Source File: SimplePrimaryNode.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Flushes all indexing ops to disk and notifies all replicas that they should now copy */
private void handleFlush(DataInput topIn, DataOutput topOut, BufferedOutputStream bos) throws IOException {
  Thread.currentThread().setName("flush");

  int atLeastMarkerCount = topIn.readVInt();

  int[] replicaTCPPorts;
  int[] replicaIDs;
  synchronized (this) {
    replicaTCPPorts = this.replicaTCPPorts;
    replicaIDs = this.replicaIDs;
  }

  message("now flush; " + replicaIDs.length + " replicas");

  if (flushAndRefresh()) {
    // Something did get flushed (there were indexing ops since the last flush):

    verifyAtLeastMarkerCount(atLeastMarkerCount, null);
 
   // Tell caller the version before pushing to replicas, so that even if we crash after this, caller will know what version we
    // (possibly) pushed to some replicas.  Alternatively we could make this 2 separate ops?
    long version = getCopyStateVersion();
    message("send flushed version=" + version);
    topOut.writeLong(version);
    bos.flush();

    // Notify current replicas:
    for(int i=0;i<replicaIDs.length;i++) {
      int replicaID = replicaIDs[i];
      try (Connection c = new Connection(replicaTCPPorts[i])) {
        message("send NEW_NRT_POINT to R" + replicaID + " at tcpPort=" + replicaTCPPorts[i]);
        c.out.writeByte(SimpleReplicaNode.CMD_NEW_NRT_POINT);
        c.out.writeVLong(version);
        c.out.writeVLong(primaryGen);
        c.out.writeInt(tcpPort);
        c.flush();
        // TODO: we should use multicast to broadcast files out to replicas
        // TODO: ... replicas could copy from one another instead of just primary
        // TODO: we could also prioritize one replica at a time?
      } catch (Throwable t) {
        message("top: failed to connect R" + replicaID + " for newNRTPoint; skipping: " + t.getMessage());
      }
    }
  } else {
    // No changes flushed:
    topOut.writeLong(-getCopyStateVersion());
  }
}