use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.
the class StandbyTestUtils method mockSegment.
public static Segment mockSegment(UUID uuid, byte[] buffer) {
SegmentStore store = mock(SegmentStore.class);
SegmentIdProvider idProvider = mock(SegmentIdProvider.class);
SegmentReader reader = mock(SegmentReader.class);
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
SegmentId id = new SegmentId(store, msb, lsb);
ByteBuffer data = ByteBuffer.wrap(buffer);
return new Segment(idProvider, reader, id, data);
}
use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.
the class DefaultStandbyReferencesReader method readReferences.
@Override
public Iterable<String> readReferences(String id) {
UUID uuid = UUID.fromString(id);
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
SegmentId segmentId = store.getSegmentIdProvider().newSegmentId(msb, lsb);
if (store.containsSegment(segmentId)) {
Segment segment = store.readSegment(segmentId);
List<String> references = newArrayList();
for (int i = 0; i < segment.getReferencedSegmentIdCount(); i++) {
references.add(segment.getReferencedSegmentId(i).toString());
}
return references;
}
return null;
}
use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.
the class DebugStore method debugFileStore.
private static void debugFileStore(ReadOnlyFileStore store) {
Map<SegmentId, List<SegmentId>> idmap = Maps.newHashMap();
int dataCount = 0;
long dataSize = 0;
int bulkCount = 0;
long bulkSize = 0;
RecordUsageAnalyser analyser = new RecordUsageAnalyser(store.getReader());
for (SegmentId id : store.getSegmentIds()) {
if (id.isDataSegmentId()) {
Segment segment = id.getSegment();
dataCount++;
dataSize += segment.size();
idmap.put(id, getReferencedSegmentIds(store, segment));
analyseSegment(segment, analyser);
} else if (id.isBulkSegmentId()) {
bulkCount++;
bulkSize += id.getSegment().size();
idmap.put(id, Collections.<SegmentId>emptyList());
}
}
System.out.println("Total size:");
System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
System.out.println(analyser.toString());
Set<SegmentId> garbage = newHashSet(idmap.keySet());
Queue<SegmentId> queue = Queues.newArrayDeque();
queue.add(store.getRevisions().getHead().getSegmentId());
while (!queue.isEmpty()) {
SegmentId id = queue.remove();
if (garbage.remove(id)) {
queue.addAll(idmap.get(id));
}
}
dataCount = 0;
dataSize = 0;
bulkCount = 0;
bulkSize = 0;
for (SegmentId id : garbage) {
if (id.isDataSegmentId()) {
dataCount++;
dataSize += id.getSegment().size();
} else if (id.isBulkSegmentId()) {
bulkCount++;
bulkSize += id.getSegment().size();
}
}
System.out.format("%nAvailable for garbage collection:%n");
System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
}
use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.
the class MemoryStore method writeSegment.
@Override
public void writeSegment(SegmentId id, byte[] data, int offset, int length) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(length);
buffer.put(data, offset, length);
buffer.rewind();
Segment segment = new Segment(tracker, segmentReader, id, buffer);
if (segments.putIfAbsent(id, segment) != null) {
throw new IOException("Segment override: " + id);
}
}
use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.
the class AbstractFileStore method writeSegment.
private void writeSegment(UUID id, byte[] data, TarWriter w) throws IOException {
long msb = id.getMostSignificantBits();
long lsb = id.getLeastSignificantBits();
ByteBuffer buffer = ByteBuffer.wrap(data);
int generation = Segment.getGcGeneration(buffer, id);
w.writeEntry(msb, lsb, data, 0, data.length, generation);
if (SegmentId.isDataSegmentId(lsb)) {
Segment segment = new Segment(tracker, segmentReader, tracker.newSegmentId(msb, lsb), buffer);
populateTarGraph(segment, w);
populateTarBinaryReferences(segment, w);
}
}
Aggregations