use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class MarkSweepGarbageCollector method getStats.
/**
* Returns the stats related to GC for all repos
*
* @return a list of GarbageCollectionRepoStats objects
* @throws Exception
*/
@Override
public List<GarbageCollectionRepoStats> getStats() throws Exception {
List<GarbageCollectionRepoStats> stats = newArrayList();
if (SharedDataStoreUtils.isShared(blobStore)) {
// Get all the references available
List<DataRecord> refFiles = ((SharedDataStore) blobStore).getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType());
Map<String, DataRecord> references = Maps.uniqueIndex(refFiles, new Function<DataRecord, String>() {
@Override
public String apply(DataRecord input) {
return SharedStoreRecordType.REFERENCES.getIdFromName(input.getIdentifier().toString());
}
});
// Get all the markers available
List<DataRecord> markerFiles = ((SharedDataStore) blobStore).getAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType());
Map<String, DataRecord> markers = Maps.uniqueIndex(markerFiles, new Function<DataRecord, String>() {
@Override
public String apply(DataRecord input) {
return SharedStoreRecordType.MARKED_START_MARKER.getIdFromName(input.getIdentifier().toString());
}
});
// Get all the repositories registered
List<DataRecord> repoFiles = ((SharedDataStore) blobStore).getAllMetadataRecords(SharedStoreRecordType.REPOSITORY.getType());
for (DataRecord repoRec : repoFiles) {
String id = SharedStoreRecordType.REFERENCES.getIdFromName(repoRec.getIdentifier().toString());
GarbageCollectionRepoStats stat = new GarbageCollectionRepoStats();
stat.setRepositoryId(id);
if (id != null && id.equals(repoId)) {
stat.setLocal(true);
}
if (references.containsKey(id)) {
DataRecord refRec = references.get(id);
stat.setEndTime(refRec.getLastModified());
stat.setLength(refRec.getLength());
if (markers.containsKey(id)) {
stat.setStartTime(markers.get(id).getLastModified());
}
LineNumberReader reader = null;
try {
reader = new LineNumberReader(new InputStreamReader(refRec.getStream()));
while (reader.readLine() != null) {
}
stat.setNumLines(reader.getLineNumber());
} finally {
Closeables.close(reader, true);
}
}
stats.add(stat);
}
}
return stats;
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class S3DataStoreStatsTest method assertSyncedFalse.
private static void assertSyncedFalse(S3DataStoreStats mBean, SharedS3DataStore s3ds, InputStream... streams) throws DataStoreException {
List<DataRecord> recs = Lists.newArrayList();
try {
for (InputStream is : streams) {
recs.add(s3ds.addRecord(is));
IOUtils.closeQuietly(is);
}
assertFalse(mBean.isFileSynced(testNodePathName));
} finally {
delete(s3ds, recs);
}
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class S3DataStoreStatsTest method testIsFileSyncedFileDeletedReturnsFalse.
@Test
public void testIsFileSyncedFileDeletedReturnsFalse() throws Exception {
stats = new S3DataStoreStats();
stats.nodeStore = nodeStore;
stats.s3ds = autoSyncMockS3ds;
DataRecord record = null;
FileInputStream stream = null;
try {
stream = new FileInputStream(testFile);
record = autoSyncMockS3ds.addRecord(stream);
} finally {
IOUtils.closeQuietly(stream);
delete(autoSyncMockS3ds, Lists.<DataRecord>newArrayList(record));
}
assertFalse(stats.isFileSynced(testNodePathName));
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class S3Backend method getAllMetadataRecords.
public List<DataRecord> getAllMetadataRecords(String prefix) {
List<DataRecord> metadataList = new ArrayList<DataRecord>();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(addMetaKeyPrefix(prefix));
ObjectListing prevObjectListing = s3service.listObjects(listObjectsRequest);
for (final S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
metadataList.add(new S3DataRecord(s3service, bucket, stripMetaKeyPrefix(s3ObjSumm.getKey()), s3ObjSumm.getLastModified().getTime(), s3ObjSumm.getSize(), true));
}
} finally {
if (contextClassLoader != null) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
return metadataList;
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class S3Backend method getAllMetadataRecords.
@Override
public List<DataRecord> getAllMetadataRecords(String prefix) {
List<DataRecord> metadataList = new ArrayList<DataRecord>();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(addMetaKeyPrefix(prefix));
ObjectListing prevObjectListing = s3service.listObjects(listObjectsRequest);
for (final S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
metadataList.add(new S3DataRecord(this, s3service, bucket, new DataIdentifier(stripMetaKeyPrefix(s3ObjSumm.getKey())), s3ObjSumm.getLastModified().getTime(), s3ObjSumm.getSize(), true));
}
} finally {
if (contextClassLoader != null) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
return metadataList;
}
Aggregations