use of org.apache.jackrabbit.oak.segment.SegmentId 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.SegmentId in project jackrabbit-oak by apache.
the class DebugSegments method debugSegment.
private static void debugSegment(ReadOnlyFileStore store, String segment) {
Matcher matcher = SEGMENT_REGEX.matcher(segment);
if (!matcher.matches()) {
System.err.println("Unknown argument: " + segment);
return;
}
if (matcher.group(1) != null) {
UUID uuid = UUID.fromString(matcher.group(1));
SegmentId id = store.getSegmentIdProvider().newSegmentId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
System.out.println(id.getSegment());
return;
}
RecordId id1 = store.getRevisions().getHead();
RecordId id2 = null;
if (matcher.group(2) != null) {
id1 = fromString(store.getSegmentIdProvider(), matcher.group(3));
if (matcher.group(4) != null) {
id2 = fromString(store.getSegmentIdProvider(), matcher.group(5));
}
}
String path = "/";
if (matcher.group(6) != null) {
path = matcher.group(6);
}
if (id2 == null) {
NodeState node = store.getReader().readNode(id1);
System.out.println("/ (" + id1 + ") -> " + node);
for (String name : PathUtils.elements(path)) {
node = node.getChildNode(name);
RecordId nid = null;
if (node instanceof SegmentNodeState) {
nid = ((SegmentNodeState) node).getRecordId();
}
System.out.println(" " + name + " (" + nid + ") -> " + node);
}
return;
}
NodeState node1 = store.getReader().readNode(id1);
NodeState node2 = store.getReader().readNode(id2);
for (String name : PathUtils.elements(path)) {
node1 = node1.getChildNode(name);
node2 = node2.getChildNode(name);
}
System.out.println(JsopBuilder.prettyPrint(JsopDiff.diffToJsop(node1, node2)));
}
use of org.apache.jackrabbit.oak.segment.SegmentId 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.SegmentId in project jackrabbit-oak by apache.
the class ReadOnlyFileStore method getSegmentIds.
public Iterable<SegmentId> getSegmentIds() {
List<SegmentId> ids = new ArrayList<>();
for (UUID id : tarFiles.getSegmentIds()) {
long msb = id.getMostSignificantBits();
long lsb = id.getLeastSignificantBits();
ids.add(tracker.newSegmentId(msb, lsb));
}
return ids;
}
use of org.apache.jackrabbit.oak.segment.SegmentId in project jackrabbit-oak by apache.
the class StandbyClientSyncExecution method copySegmentFromPrimary.
private void copySegmentFromPrimary(StandbyClient client, UUID uuid) throws Exception {
byte[] data = client.getSegment(uuid.toString());
if (data == null) {
throw new IllegalStateException("Unable to read segment " + uuid);
}
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
SegmentId segmentId = idProvider.newSegmentId(msb, lsb);
store.writeSegment(segmentId, data, 0, data.length);
}
Aggregations