test_class.declarator: folder = new TemporaryFolder(new File("target"))
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public TemporaryFolder folder = new TemporaryFolder(new File("target"));
test_class.type: TemporaryFolder
test_class.var_name: folder
test_class.file: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBufferWriterTest.java
test_class.identifier: SegmentBufferWriterTest
test_case.body: @Test
      public void nonDirtyBuffersShouldNotBeFlushed() throws Exception {
          List<SegmentId> before;
  
          try (FileStore store = openFileStore()) {
              // init
          }
          try (ReadOnlyFileStore store = openReadOnlyFileStore()) {
              before = newArrayList(store.getSegmentIds());
          }
  
          try (FileStore store = openFileStore()) {
              defaultSegmentWriterBuilder("t").build(store).flush();
          }
  
          List<SegmentId> after;
  
          try (ReadOnlyFileStore store = openReadOnlyFileStore()) {
              after = newArrayList(store.getSegmentIds());
          }
  
          assertEquals(before, after);
      }
test_case.class_method_signature: SegmentBufferWriterTest.nonDirtyBuffersShouldNotBeFlushed()
test_case.full_signature: @Test public void nonDirtyBuffersShouldNotBeFlushed()
test_case.identifier: nonDirtyBuffersShouldNotBeFlushed
test_case.invocations: openFileStore openReadOnlyFileStore newArrayList getSegmentIds openFileStore flush build defaultSegmentWriterBuilder openReadOnlyFileStore newArrayList getSegmentIds assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void nonDirtyBuffersShouldNotBeFlushed()
focal_class.declarator: LOG = LoggerFactory.getLogger(SegmentBufferWriter.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOG = LoggerFactory.getLogger(SegmentBufferWriter.class);
focal_class.type: Logger
focal_class.var_name: LOG
focal_class.declarator: recordNumbers = new MutableRecordNumbers()
focal_class.modifier: private
focal_class.original_string: private MutableRecordNumbers recordNumbers = new MutableRecordNumbers();
focal_class.type: MutableRecordNumbers
focal_class.var_name: recordNumbers
focal_class.declarator: segmentReferences = new MutableSegmentReferences()
focal_class.modifier: private
focal_class.original_string: private MutableSegmentReferences segmentReferences = new MutableSegmentReferences();
focal_class.type: MutableSegmentReferences
focal_class.var_name: segmentReferences
focal_class.declarator: idProvider
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final SegmentIdProvider idProvider;
focal_class.type: SegmentIdProvider
focal_class.var_name: idProvider
focal_class.declarator: reader
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final SegmentReader reader;
focal_class.type: SegmentReader
focal_class.var_name: reader
focal_class.declarator: wid
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final String wid;
focal_class.type: String
focal_class.var_name: wid
focal_class.declarator: gcGeneration
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final GCGeneration gcGeneration;
focal_class.type: GCGeneration
focal_class.var_name: gcGeneration
focal_class.declarator: buffer
focal_class.modifier: private
focal_class.original_string: private byte[] buffer;
focal_class.type: byte[]
focal_class.var_name: buffer
focal_class.declarator: segment
focal_class.modifier: private
focal_class.original_string: private Segment segment;
focal_class.type: Segment
focal_class.var_name: segment
focal_class.declarator: length
focal_class.modifier: private
focal_class.original_string: private int length;
focal_class.type: int
focal_class.var_name: length
focal_class.declarator: position
focal_class.modifier: private
focal_class.original_string: private int position;
focal_class.type: int
focal_class.var_name: position
focal_class.declarator: statistics
focal_class.modifier: private
focal_class.original_string: private Statistics statistics;
focal_class.type: Statistics
focal_class.var_name: statistics
focal_class.declarator: dirty
focal_class.modifier: private
focal_class.original_string: private boolean dirty;
focal_class.type: boolean
focal_class.var_name: dirty
focal_class.file: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferWriter.java
focal_class.identifier: SegmentBufferWriter
focal_class.interfaces: implements WriteOperationHandler
focal_class.class_method_signature: SegmentBufferWriter.SegmentBufferWriter(@NotNull SegmentIdProvider idProvider,
                                 @NotNull SegmentReader reader,
                                 @Nullable String wid,
                                 @NotNull GCGeneration gcGeneration)
focal_class.full_signature: public  SegmentBufferWriter(@NotNull SegmentIdProvider idProvider,
                                 @NotNull SegmentReader reader,
                                 @Nullable String wid,
                                 @NotNull GCGeneration gcGeneration)
focal_class.identifier: SegmentBufferWriter
focal_class.modifiers: public
focal_class.parameters: (@NotNull SegmentIdProvider idProvider,
                                 @NotNull SegmentReader reader,
                                 @Nullable String wid,
                                 @NotNull GCGeneration gcGeneration)
focal_class.signature:  SegmentBufferWriter(@NotNull SegmentIdProvider idProvider,
                                 @NotNull SegmentReader reader,
                                 @Nullable String wid,
                                 @NotNull GCGeneration gcGeneration)
focal_class.class_method_signature: SegmentBufferWriter.execute(@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.full_signature: @NotNull @Override public RecordId execute(@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.identifier: execute
focal_class.modifiers: @NotNull @Override public
focal_class.parameters: (@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.return: RecordId
focal_class.signature: RecordId execute(@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.class_method_signature: SegmentBufferWriter.getGCGeneration()
focal_class.full_signature: @Override @NotNull public GCGeneration getGCGeneration()
focal_class.identifier: getGCGeneration
focal_class.modifiers: @Override @NotNull public
focal_class.parameters: ()
focal_class.return: GCGeneration
focal_class.signature: GCGeneration getGCGeneration()
focal_class.class_method_signature: SegmentBufferWriter.newSegment(SegmentStore store)
focal_class.full_signature: private void newSegment(SegmentStore store)
focal_class.identifier: newSegment
focal_class.modifiers: private
focal_class.parameters: (SegmentStore store)
focal_class.return: void
focal_class.signature: void newSegment(SegmentStore store)
focal_class.class_method_signature: SegmentBufferWriter.writeByte(byte value)
focal_class.full_signature: public void writeByte(byte value)
focal_class.identifier: writeByte
focal_class.modifiers: public
focal_class.parameters: (byte value)
focal_class.return: void
focal_class.signature: void writeByte(byte value)
focal_class.class_method_signature: SegmentBufferWriter.writeShort(short value)
focal_class.full_signature: public void writeShort(short value)
focal_class.identifier: writeShort
focal_class.modifiers: public
focal_class.parameters: (short value)
focal_class.return: void
focal_class.signature: void writeShort(short value)
focal_class.class_method_signature: SegmentBufferWriter.writeInt(int value)
focal_class.full_signature: public void writeInt(int value)
focal_class.identifier: writeInt
focal_class.modifiers: public
focal_class.parameters: (int value)
focal_class.return: void
focal_class.signature: void writeInt(int value)
focal_class.class_method_signature: SegmentBufferWriter.writeLong(long value)
focal_class.full_signature: public void writeLong(long value)
focal_class.identifier: writeLong
focal_class.modifiers: public
focal_class.parameters: (long value)
focal_class.return: void
focal_class.signature: void writeLong(long value)
focal_class.class_method_signature: SegmentBufferWriter.writeRecordId(RecordId recordId)
focal_class.full_signature: public void writeRecordId(RecordId recordId)
focal_class.identifier: writeRecordId
focal_class.modifiers: public
focal_class.parameters: (RecordId recordId)
focal_class.return: void
focal_class.signature: void writeRecordId(RecordId recordId)
focal_class.class_method_signature: SegmentBufferWriter.toShort(int value)
focal_class.full_signature: private static short toShort(int value)
focal_class.identifier: toShort
focal_class.modifiers: private static
focal_class.parameters: (int value)
focal_class.return: short
focal_class.signature: short toShort(int value)
focal_class.class_method_signature: SegmentBufferWriter.writeSegmentIdReference(SegmentId id)
focal_class.full_signature: private int writeSegmentIdReference(SegmentId id)
focal_class.identifier: writeSegmentIdReference
focal_class.modifiers: private
focal_class.parameters: (SegmentId id)
focal_class.return: int
focal_class.signature: int writeSegmentIdReference(SegmentId id)
focal_class.class_method_signature: SegmentBufferWriter.info(Segment segment)
focal_class.full_signature: private static String info(Segment segment)
focal_class.identifier: info
focal_class.modifiers: private static
focal_class.parameters: (Segment segment)
focal_class.return: String
focal_class.signature: String info(Segment segment)
focal_class.class_method_signature: SegmentBufferWriter.writeBytes(byte[] data, int offset, int length)
focal_class.full_signature: public void writeBytes(byte[] data, int offset, int length)
focal_class.identifier: writeBytes
focal_class.modifiers: public
focal_class.parameters: (byte[] data, int offset, int length)
focal_class.return: void
focal_class.signature: void writeBytes(byte[] data, int offset, int length)
focal_class.class_method_signature: SegmentBufferWriter.dumpSegmentBuffer()
focal_class.full_signature: private String dumpSegmentBuffer()
focal_class.identifier: dumpSegmentBuffer
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String dumpSegmentBuffer()
focal_class.class_method_signature: SegmentBufferWriter.flush(@NotNull SegmentStore store)
focal_class.full_signature: @Override public void flush(@NotNull SegmentStore store)
focal_class.identifier: flush
focal_class.modifiers: @Override public
focal_class.parameters: (@NotNull SegmentStore store)
focal_class.return: void
focal_class.signature: void flush(@NotNull SegmentStore store)
focal_class.class_method_signature: SegmentBufferWriter.prepare(RecordType type, int size, Collection<RecordId> ids, SegmentStore store)
focal_class.full_signature: public RecordId prepare(RecordType type, int size, Collection<RecordId> ids, SegmentStore store)
focal_class.identifier: prepare
focal_class.modifiers: public
focal_class.parameters: (RecordType type, int size, Collection<RecordId> ids, SegmentStore store)
focal_class.return: RecordId
focal_class.signature: RecordId prepare(RecordType type, int size, Collection<RecordId> ids, SegmentStore store)
focal_method.body: @Override
      public void flush(@NotNull SegmentStore store) throws IOException {
          if (dirty) {
              int referencedSegmentIdCount = segmentReferences.size();
              BinaryUtils.writeInt(buffer, Segment.REFERENCED_SEGMENT_ID_COUNT_OFFSET, referencedSegmentIdCount);
  
              statistics.segmentIdCount = referencedSegmentIdCount;
  
              int recordNumberCount = recordNumbers.size();
              BinaryUtils.writeInt(buffer, Segment.RECORD_NUMBER_COUNT_OFFSET, recordNumberCount);
  
              int totalLength = align(HEADER_SIZE + referencedSegmentIdCount * SEGMENT_REFERENCE_SIZE + recordNumberCount * RECORD_SIZE + length, 16);
  
              if (totalLength > buffer.length) {
                  LOG.warn("Segment buffer corruption detected\n{}", dumpSegmentBuffer());
                  throw new IllegalStateException(String.format(
                          "Too much data for a segment %s (referencedSegmentIdCount=%d, recordNumberCount=%d, length=%d, totalLength=%d)",
                          segment.getSegmentId(), referencedSegmentIdCount, recordNumberCount, length, totalLength));
              }
  
              statistics.size = length = totalLength;
  
              int pos = HEADER_SIZE;
              if (pos + length <= buffer.length) {
                  // the whole segment fits to the space *after* the referenced
                  // segment identifiers we've already written, so we can safely
                  // copy those bits ahead even if concurrent code is still
                  // reading from that part of the buffer
                  arraycopy(buffer, 0, buffer, buffer.length - length, pos);
                  pos += buffer.length - length;
              } else {
                  // this might leave some empty space between the header and
                  // the record data, but this case only occurs when the
                  // segment is >252kB in size and the maximum overhead is <<4kB,
                  // which is acceptable
                  length = buffer.length;
              }
  
              for (SegmentId segmentId : segmentReferences) {
                  pos = BinaryUtils.writeLong(buffer, pos, segmentId.getMostSignificantBits());
                  pos = BinaryUtils.writeLong(buffer, pos, segmentId.getLeastSignificantBits());
              }
  
              for (Entry entry : recordNumbers) {
                  pos = BinaryUtils.writeInt(buffer, pos, entry.getRecordNumber());
                  pos = BinaryUtils.writeByte(buffer, pos, (byte) entry.getType().ordinal());
                  pos = BinaryUtils.writeInt(buffer, pos, entry.getOffset());
              }
  
              SegmentId segmentId = segment.getSegmentId();
              LOG.debug("Writing data segment: {} ", statistics);
              store.writeSegment(segmentId, buffer, buffer.length - length, length);
              newSegment(store);
          }
      }
focal_method.class_method_signature: SegmentBufferWriter.flush(@NotNull SegmentStore store)
focal_method.full_signature: @Override public void flush(@NotNull SegmentStore store)
focal_method.identifier: flush
focal_method.invocations: size writeInt size writeInt align warn dumpSegmentBuffer format getSegmentId arraycopy writeLong getMostSignificantBits writeLong getLeastSignificantBits writeInt getRecordNumber writeByte ordinal getType writeInt getOffset getSegmentId debug writeSegment newSegment
focal_method.modifiers: @Override public
focal_method.parameters: (@NotNull SegmentStore store)
focal_method.return: void
focal_method.signature: void flush(@NotNull SegmentStore store)