use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.
the class BlobMigrator method migrateMultiProperty.
private PropertyState migrateMultiProperty(PropertyState propertyState) throws IOException {
Iterable<Blob> oldBlobs = propertyState.getValue(Type.BINARIES);
List<Blob> newBlobs = new ArrayList<Blob>();
PropertyBuilder<Blob> builder = new PropertyBuilder<Blob>(Type.BINARY);
builder.assignFrom(propertyState);
boolean blobUpdated = false;
for (Blob oldBlob : oldBlobs) {
String blobId = getIdentity(oldBlob);
if (blobStore.isMigrated(blobId)) {
newBlobs.add(new BlobStoreBlob(blobStore, blobId));
} else {
String newBlobId = blobStore.writeBlob(oldBlob.getNewStream());
Blob newBlob = new BlobStoreBlob(blobStore, newBlobId);
newBlobs.add(newBlob);
blobUpdated = true;
}
}
if (blobUpdated) {
builder.setValues(newBlobs);
return builder.getPropertyState();
} else {
return null;
}
}
use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.
the class BlobMigrator method migrateProperty.
private PropertyState migrateProperty(PropertyState propertyState) throws IOException {
Blob oldBlob = propertyState.getValue(Type.BINARY);
String blobId = getIdentity(oldBlob);
if (blobStore.isMigrated(blobId)) {
return null;
}
String newBlobId = blobStore.writeBlob(oldBlob.getNewStream());
Blob newBlob = new BlobStoreBlob(blobStore, newBlobId);
PropertyBuilder<Blob> builder = new PropertyBuilder<Blob>(Type.BINARY);
builder.assignFrom(propertyState);
builder.setValue(newBlob);
return builder.getPropertyState();
}
use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.
the class BlobTest method testBlobSerialization.
@Test
public void testBlobSerialization() throws Exception {
TestBlobStore blobStore = new TestBlobStore();
DocumentMK mk = builderProvider.newBuilder().setBlobStore(blobStore).open();
BlobSerializer blobSerializer = mk.getNodeStore().getBlobSerializer();
Blob blob = new BlobStoreBlob(blobStore, "foo");
assertEquals("foo", blobSerializer.serialize(blob));
assertEquals(0, blobStore.writeCount);
blob = new ArrayBasedBlob("foo".getBytes());
blobSerializer.serialize(blob);
assertEquals(1, blobStore.writeCount);
byte[] bytes = "foo".getBytes();
String blobId = blobStore.writeBlob(new ByteArrayInputStream(bytes));
String reference = blobStore.getReference(blobId);
blob = new ReferencedBlob("foo".getBytes(), reference);
blobStore.writeCount = 0;
blobSerializer.serialize(blob);
// Using reference so no reference should be written
assertEquals(0, blobStore.writeCount);
}
use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.
the class DocumentBlobReferenceRetriever method collectReferences.
@Override
public void collectReferences(ReferenceCollector collector) {
int referencesFound = 0;
Iterator<ReferencedBlob> blobIterator = null;
try {
blobIterator = nodeStore.getReferencedBlobsIterator();
while (blobIterator.hasNext()) {
ReferencedBlob refBlob = blobIterator.next();
Blob blob = refBlob.getBlob();
referencesFound++;
if (blob instanceof BlobStoreBlob) {
collector.addReference(((BlobStoreBlob) blob).getBlobId(), refBlob.getId());
} else {
// TODO Should not rely on toString. Instead obtain
// secure reference and convert that to blobId using
// blobStore
collector.addReference(blob.toString(), refBlob.getId());
}
}
} finally {
Utils.closeIfCloseable(blobIterator);
}
log.debug("Total blob references found (including chunk resolution) [{}]", referencesFound);
}
use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.
the class OakDirectoryTestBase method dontMarkInlinedBlobsFromDataStoreAsDeleted.
// OAK-7066
@Test
public void dontMarkInlinedBlobsFromDataStoreAsDeleted() throws Exception {
IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
final Set<String> deletedFiles = newHashSet();
FileDataStore fds = new FileDataStore();
fds.setMinRecordLength(48);
fds.init(new File(tempFolder.getRoot(), "fdsRoot").getAbsolutePath());
DataStoreBlobStore dsbs = new DataStoreBlobStore(fds);
BlobFactory factory = in -> new BlobStoreBlob(dsbs, dsbs.writeBlob(in));
OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {
@Override
public void deleted(String blobId, Iterable<String> ids) {
deletedFiles.add(Iterables.getLast(ids));
}
@Override
public void commitProgress(IndexProgress indexProgress) {
}
@Override
public boolean isMarkingForActiveDeletionUnsafe() {
return false;
}
}).build();
writeFile(dir, "file1", 25);
writeFile(dir, "file2", 50);
dir.deleteFile("file1");
dir.deleteFile("file2");
dir.close();
assertFalse("file1 must be reported as deleted", deletedFiles.contains("file1"));
assertTrue("file2 must be reported as deleted", deletedFiles.contains("file2"));
}
Aggregations