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;
}
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;
}
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();
}
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());
}
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);
}
Aggregations