/** FOR TESTING PURPOSES. See CommitLogAllocator. */
 public void stopUnsafe(boolean deleteSegments) {
   executor.shutdown();
   try {
     executor.awaitTermination();
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   }
   allocator.stopUnsafe(deleteSegments);
 }
 /** FOR TESTING PURPOSES. See CommitLogAllocator */
 public int restartUnsafe() throws IOException {
   allocator.start();
   executor.restartUnsafe();
   try {
     return recover();
   } catch (FSWriteError e) {
     // Workaround for a class of races that keeps showing up on Windows tests.
     // stop/start/reset path on Windows with segment deletion is very touchy/brittle
     // and the timing keeps getting screwed up. Rather than chasing our tail further
     // or rewriting the CLSM, just report that we didn't recover anything back up
     // the chain. This will silence most intermittent test failures on Windows
     // and appropriately fail tests that expected segments to be recovered that
     // were not.
     return 0;
   }
 }
  /**
   * Add a Mutation to the commit log.
   *
   * @param mutation the Mutation to add to the log
   */
  public ReplayPosition add(Mutation mutation) {
    assert mutation != null;

    long size = Mutation.serializer.serializedSize(mutation, MessagingService.current_version);

    long totalSize = size + ENTRY_OVERHEAD_SIZE;
    if (totalSize > MAX_MUTATION_SIZE) {
      throw new IllegalArgumentException(
          String.format(
              "Mutation of %s bytes is too large for the maxiumum size of %s",
              totalSize, MAX_MUTATION_SIZE));
    }

    Allocation alloc = allocator.allocate(mutation, (int) totalSize);
    ICRC32 checksum = CRC32Factory.instance.create();
    final ByteBuffer buffer = alloc.getBuffer();
    try (BufferedDataOutputStreamPlus dos = new DataOutputBufferFixed(buffer)) {
      // checksummed length
      dos.writeInt((int) size);
      checksum.update(buffer, buffer.position() - 4, 4);
      buffer.putInt(checksum.getCrc());

      int start = buffer.position();
      // checksummed mutation
      Mutation.serializer.serialize(mutation, dos, MessagingService.current_version);
      checksum.update(buffer, start, (int) size);
      buffer.putInt(checksum.getCrc());
    } catch (IOException e) {
      throw new FSWriteError(e, alloc.getSegment().getPath());
    } finally {
      alloc.markWritten();
    }

    executor.finishWriteFor(alloc);
    return alloc.getReplayPosition();
  }
 /** Shuts down the threads used by the commit log, blocking until completion. */
 public void shutdownBlocking() throws InterruptedException {
   executor.shutdown();
   executor.awaitTermination();
   allocator.shutdown();
   allocator.awaitTermination();
 }
 /** Preempts the CLExecutor, telling to to sync immediately */
 public void requestExtraSync() {
   executor.requestExtraSync();
 }
 CommitLog start() {
   executor.start();
   allocator.start();
   return this;
 }