Search in sources :

Example 6 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.

the class DataStoreBlobStore method countDeleteChunks.

@Override
public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception {
    int count = 0;
    if (delegate instanceof MultiDataStoreAware) {
        List<String> deleted = Lists.newArrayListWithExpectedSize(512);
        for (String chunkId : chunkIds) {
            String blobId = extractBlobId(chunkId);
            DataIdentifier identifier = new DataIdentifier(blobId);
            DataRecord dataRecord = getRecordForId(identifier);
            boolean success = (maxLastModifiedTime <= 0) || dataRecord.getLastModified() <= maxLastModifiedTime;
            log.trace("Deleting blob [{}] with last modified date [{}] : [{}]", blobId, dataRecord.getLastModified(), success);
            if (success) {
                ((MultiDataStoreAware) delegate).deleteRecord(identifier);
                deleted.add(blobId);
                count++;
                if (count % 512 == 0) {
                    log.info("Deleted blobs {}", deleted);
                    deleted.clear();
                }
            }
        }
        if (!deleted.isEmpty()) {
            log.info("Deleted blobs {}", deleted);
        }
    }
    return count;
}
Also used : MultiDataStoreAware(org.apache.jackrabbit.core.data.MultiDataStoreAware) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 7 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.

the class DataStoreBlobStore method getDataRecord.

protected DataRecord getDataRecord(String blobId) throws DataStoreException {
    DataRecord id;
    if (InMemoryDataRecord.isInstance(blobId)) {
        id = InMemoryDataRecord.getInstance(blobId);
    } else {
        id = delegate.getRecord(new DataIdentifier(blobId));
    }
    checkNotNull(id, "No DataRecord found for blobId [%s]", blobId);
    return id;
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 8 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit by apache.

the class VFSBackend method getAllIdentifiers.

/**
     * {@inheritDoc}
     */
@Override
public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException {
    List<DataIdentifier> identifiers = new LinkedList<DataIdentifier>();
    try {
        for (FileObject fileObject : VFSUtils.getChildFolders(getBaseFolderObject())) {
            // skip top-level files
            pushIdentifiersRecursively(identifiers, fileObject);
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("Object identifiers not resolved.", e);
    }
    LOG.debug("Found " + identifiers.size() + " identifiers.");
    return identifiers.iterator();
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList)

Example 9 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.

the class AbstractDataStoreTest method doGetAllIdentifiersTest.

/**
     * Test {@link DataStore#getAllIdentifiers()} and asserts all identifiers
     * are returned.
     */
protected void doGetAllIdentifiersTest() throws Exception {
    List<DataIdentifier> list = new ArrayList<DataIdentifier>();
    Random random = randomGen;
    byte[] data = new byte[dataLength];
    random.nextBytes(data);
    DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
    list.add(rec.getIdentifier());
    data = new byte[dataLength];
    random.nextBytes(data);
    rec = ds.addRecord(new ByteArrayInputStream(data));
    list.add(rec.getIdentifier());
    data = new byte[dataLength];
    random.nextBytes(data);
    rec = ds.addRecord(new ByteArrayInputStream(data));
    list.add(rec.getIdentifier());
    Iterator<DataIdentifier> itr = Sets.newHashSet(ds.getAllIdentifiers()).iterator();
    while (itr.hasNext()) {
        assertTrue("record found on list", list.remove(itr.next()));
    }
    Assert.assertEquals(0, list.size());
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 10 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.

the class OakFileDataStoreTest method testGetAllIdentifiers.

private void testGetAllIdentifiers(String path, String unnormalizedPath) throws Exception {
    File testDir = new File(path);
    FileUtils.touch(new File(testDir, "ab/cd/ef/abcdef"));
    FileUtils.touch(new File(testDir, "bc/de/fg/bcdefg"));
    FileUtils.touch(new File(testDir, "cd/ef/gh/cdefgh"));
    FileUtils.touch(new File(testDir, "c"));
    FileDataStore fds = new OakFileDataStore();
    fds.setPath(unnormalizedPath);
    fds.init(null);
    Iterator<DataIdentifier> dis = fds.getAllIdentifiers();
    Set<String> fileNames = Sets.newHashSet(Iterators.transform(dis, new Function<DataIdentifier, String>() {

        @Override
        public String apply(@Nullable DataIdentifier input) {
            return input.toString();
        }
    }));
    Set<String> expectedNames = Sets.newHashSet("abcdef", "bcdefg", "cdefgh");
    assertEquals(expectedNames, fileNames);
    FileUtils.cleanDirectory(testDir);
}
Also used : Function(com.google.common.base.Function) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) File(java.io.File) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) Nullable(javax.annotation.Nullable)

Aggregations

DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)60 Test (org.junit.Test)31 DataRecord (org.apache.jackrabbit.core.data.DataRecord)30 File (java.io.File)22 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)13 FileInputStream (java.io.FileInputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ArrayList (java.util.ArrayList)8 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)5 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 RepositoryException (javax.jcr.RepositoryException)4 Function (com.google.common.base.Function)3 StorageException (com.microsoft.azure.storage.StorageException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3