Search in sources :

Example 46 with DataRecord

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) DataRecord(org.apache.jackrabbit.core.data.DataRecord) LineNumberReader(java.io.LineNumberReader)

Example 47 with DataRecord

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 48 with DataRecord

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));
}
Also used : DataRecord(org.apache.jackrabbit.core.data.DataRecord) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 49 with DataRecord

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;
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) ArrayList(java.util.ArrayList) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 50 with DataRecord

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;
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ArrayList(java.util.ArrayList) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) AbstractDataRecord(org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Aggregations

DataRecord (org.apache.jackrabbit.core.data.DataRecord)76 Test (org.junit.Test)43 ByteArrayInputStream (java.io.ByteArrayInputStream)34 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)30 File (java.io.File)24 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)19 FileInputStream (java.io.FileInputStream)16 Random (java.util.Random)12 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)6 IOException (java.io.IOException)4 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)4 Function (com.google.common.base.Function)3 SequenceInputStream (java.io.SequenceInputStream)3 RepositoryException (javax.jcr.RepositoryException)3 DataStore (org.apache.jackrabbit.core.data.DataStore)3 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2