use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class TritonBlobStoreManagerTest method sisEmpty.
@Test
public void sisEmpty() throws Exception {
TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
byte[] bytes = new byte[0];
Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
// blob has not yet been finalized, so it shouldn't exist in remote system yet
byte[] hash = sm.getHash(blob);
Assert.assertNotNull("empty blob always exists", sm.getSisBlob(hash));
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
// blob uploaded, now sis should return true and increment ref count
Blob sisBlob = sm.getSisBlob(hash);
Assert.assertNotNull("object created", sisBlob);
Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class TritonBlobStoreManagerTest method sis.
@Test
public void sis() throws Exception {
TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
Random rand = new Random();
byte[] bytes = new byte[10000];
rand.nextBytes(bytes);
Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
// blob has not yet been finalized, so it shouldn't exist in remote system yet
byte[] hash = sm.getHash(blob);
Assert.assertNull("object not yet created", sm.getSisBlob(hash));
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
// blob uploaded, now sis should return true and increment ref count
Blob sisBlob = sm.getSisBlob(hash);
Assert.assertNotNull("object created", sisBlob);
Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
// delete once, should still exist;
sm.delete(mblob);
Assert.assertNotNull("object still ref'd", sm.getSisBlob(hash));
// delete twice (once for original, once since we just did a sisCheck above)
sm.delete(mblob);
sm.delete(mblob);
Assert.assertNull("object deleted", sm.getSisBlob(hash));
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class DbMailItem method accumulateLeafRevisions.
static void accumulateLeafRevisions(PendingDelete info, Mailbox mbox, List<Integer> versioned) throws ServiceException {
if (versioned == null || versioned.size() == 0) {
return;
}
boolean dumpsterEnabled = mbox.dumpsterEnabled();
boolean useDumpsterForSpam = mbox.useDumpsterForSpam();
DbConnection conn = mbox.getOperationConnection();
StoreManager sm = StoreManager.getInstance();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement("SELECT mi.id, mi.folder_id, rev.size, rev.mod_content, rev.locator, rev.blob_digest " + " FROM " + getMailItemTableName(mbox, "mi") + ", " + getRevisionTableName(mbox, "rev") + " WHERE mi.id = rev.item_id AND " + DbUtil.whereIn("mi.id", versioned.size()) + (DebugConfig.disableMailboxGroups ? "" : " AND mi.mailbox_id = ? AND mi.mailbox_id = rev.mailbox_id"));
int pos = 1;
for (int vid : versioned) {
stmt.setInt(pos++, vid);
}
pos = setMailboxId(stmt, mbox, pos);
rs = stmt.executeQuery();
while (rs.next()) {
Integer folderId = rs.getInt(2);
LocationCount count = info.folderCounts.get(folderId);
if (count == null) {
info.folderCounts.put(folderId, new LocationCount(0, 0, rs.getLong(3)));
} else {
count.increment(0, 0, rs.getLong(3));
}
int fid = folderId != null ? folderId.intValue() : -1;
if (!dumpsterEnabled || fid == Mailbox.ID_FOLDER_DRAFTS || (fid == Mailbox.ID_FOLDER_SPAM && !useDumpsterForSpam)) {
String blobDigest = rs.getString(6);
if (blobDigest != null) {
info.blobDigests.add(blobDigest);
try {
MailboxBlob mblob = sm.getMailboxBlob(mbox, rs.getInt(1), rs.getInt(4), rs.getString(5), false);
if (mblob == null) {
ZimbraLog.mailbox.error("missing blob for id: %d, change: %s", rs.getInt(1), rs.getInt(4));
} else {
info.blobs.add(mblob);
}
} catch (Exception e1) {
}
}
}
long revisionSize = rs.getLong(3);
info.size += revisionSize;
}
} catch (SQLException e) {
throw ServiceException.FAILURE("getting version deletion info for items: " + versioned, e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class Mailbox method createContact.
public Contact createContact(OperationContext octxt, ParsedContact pc, int folderId, String[] tags) throws ServiceException {
StoreManager sm = StoreManager.getInstance();
StagedBlob staged = null;
if (pc.hasAttachment()) {
// write the contact content directly to the mailbox's blob staging area
InputStream is = null;
try {
staged = sm.stage(is = pc.getContentStream(), (int) pc.getSize(), this);
} catch (IOException ioe) {
throw ServiceException.FAILURE("could not save contact blob", ioe);
} finally {
ByteUtil.closeStream(is);
}
}
CreateContact redoRecorder = new CreateContact(mId, folderId, pc, tags);
boolean success = false;
try {
beginTransaction("createContact", octxt, redoRecorder);
CreateContact redoPlayer = (CreateContact) currentChange().getRedoPlayer();
boolean isRedo = redoPlayer != null;
Tag.NormalizedTags ntags = new Tag.NormalizedTags(this, tags);
int contactId = getNextItemId(isRedo ? redoPlayer.getContactId() : ID_AUTO_INCREMENT);
MailboxBlob mblob = null;
if (pc.hasAttachment()) {
try {
mblob = sm.renameTo(staged, this, contactId, getOperationChangeID());
markOtherItemDirty(mblob);
} catch (IOException ioe) {
throw ServiceException.FAILURE("could not save contact blob", ioe);
}
}
int flags = 0;
Contact con = Contact.create(contactId, getFolderById(folderId), mblob, pc, flags, ntags, null);
redoRecorder.setContactId(contactId);
index.add(con);
success = true;
return con;
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class Mailbox method createChat.
public Chat createChat(OperationContext octxt, ParsedMessage pm, int folderId, int flags, String[] tags) throws IOException, ServiceException {
if (pm == null) {
throw ServiceException.INVALID_REQUEST("null ParsedMessage when adding chat to mailbox " + mId, null);
}
// write the chat content directly to the mailbox's blob staging area
StoreManager sm = StoreManager.getInstance();
StagedBlob staged;
InputStream is = pm.getRawInputStream();
try {
staged = sm.stage(is, this);
} finally {
ByteUtil.closeStream(is);
}
String digest = staged.getDigest();
int size = (int) staged.getSize();
CreateChat redoRecorder = new CreateChat(mId, digest, size, folderId, flags, tags);
boolean success = false;
try {
beginTransaction("createChat", octxt, redoRecorder);
Tag.NormalizedTags ntags = new Tag.NormalizedTags(this, tags);
CreateChat redoPlayer = (octxt == null ? null : (CreateChat) octxt.getPlayer());
redoRecorder.setMessageBodyInfo(new ParsedMessageDataSource(pm), size);
int itemId = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getMessageId());
Chat chat = Chat.create(itemId, getFolderById(folderId), pm, staged, false, flags, ntags);
redoRecorder.setMessageId(chat.getId());
MailboxBlob mblob = sm.link(staged, this, itemId, getOperationChangeID());
markOtherItemDirty(mblob);
// when we created the Chat, we used the staged locator/size/digest;
// make sure that data actually matches the final blob in the store
chat.updateBlobData(mblob);
index.add(chat);
success = true;
return chat;
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
Aggregations