Example #1
0
  public long writeCommit(CommitUpdateCommand cmd, int flags) {
    LogCodec codec = new LogCodec(resolver);
    synchronized (this) {
      try {
        long pos = fos.size(); // if we had flushed, this should be equal to channel.position()

        if (pos == 0) {
          writeLogHeader(codec);
          pos = fos.size();
        }
        codec.init(fos);
        codec.writeTag(JavaBinCodec.ARR, 3);
        codec.writeInt(UpdateLog.COMMIT | flags); // should just take one byte
        codec.writeLong(cmd.getVersion());
        codec.writeStr(END_MESSAGE); // ensure these bytes are (almost) last in the file

        endRecord(pos);

        fos.flush(); // flush since this will be the last record in a log fill
        assert fos.size() == channel.size();

        return pos;
      } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
      }
    }
  }
  public void distribCommit(CommitUpdateCommand cmd, List<Node> nodes, ModifiableSolrParams params)
      throws IOException {

    // we need to do any retries before commit...
    blockAndDoRetries();

    UpdateRequest uReq = new UpdateRequest();
    uReq.setParams(params);

    addCommit(uReq, cmd);

    log.debug("Distrib commit to: {} params: {}", nodes, params);

    for (Node node : nodes) {
      submit(new Req(cmd.toString(), node, uReq, false), true);
    }
  }
  @Override
  public long writeCommit(CommitUpdateCommand cmd, int flags) {
    LogCodec codec = new LogCodec(resolver);
    synchronized (this) {
      try {
        long pos = fos.size(); // if we had flushed, this should be equal to channel.position()

        if (pos == 0) {
          writeLogHeader(codec);
          pos = fos.size();
        }
        codec.init(fos);
        codec.writeTag(JavaBinCodec.ARR, 4);
        codec.writeInt(UpdateLog.COMMIT | flags); // should just take one byte
        codec.writeLong(cmd.getVersion());
        codec.writeTag(
            JavaBinCodec.INT); // Enforce the encoding of a plain integer, to simplify decoding
        fos.writeInt(
            numRecords
                + 1); // the number of records in the file - +1 to account for the commit operation
                      // being written
        codec.writeStr(END_MESSAGE); // ensure these bytes are (almost) last in the file

        endRecord(pos);

        fos.flush(); // flush since this will be the last record in a log fill
        assert fos.size() == channel.size();

        isReplaying =
            false; // we have replayed and appended a commit record with the number of records in
                   // the file

        return pos;
      } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
      }
    }
  }