Search in sources :

Example 16 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class FileBlobStore method renameTo.

@Override
public VolumeMailboxBlob renameTo(StagedBlob src, Mailbox destMbox, int destItemId, int destRevision) throws IOException, ServiceException {
    Volume volume = MANAGER.getCurrentMessageVolume();
    VolumeBlob blob = ((VolumeStagedBlob) src).getLocalBlob();
    File srcFile = blob.getFile();
    String srcPath = srcFile.getAbsolutePath();
    if (!srcFile.exists()) {
        throw new IOException(srcFile.getPath() + " does not exist.");
    }
    File destFile = getMailboxBlobFile(destMbox, destItemId, destRevision, volume.getId(), false);
    String destPath = destFile.getAbsolutePath();
    // Prevent stale cache read.
    BlobInputStream.getFileDescriptorCache().remove(destPath);
    ensureParentDirExists(destFile);
    if (ZimbraLog.store.isDebugEnabled()) {
        long srcSize = srcFile.length();
        long srcRawSize = blob.getRawSize();
        ZimbraLog.store.debug("Renaming %s (size=%d, raw size=%d) to %s for mailbox %d, id %d.", srcPath, srcSize, srcRawSize, destPath, destMbox.getId(), destItemId);
    }
    short srcVolumeId = blob.getVolumeId();
    if (srcVolumeId == volume.getId()) {
        boolean renamed = srcFile.renameTo(destFile);
        if (SystemUtil.ON_WINDOWS) {
            // the destination and try the rename again
            if (!renamed && destFile.exists()) {
                destFile.delete();
                renamed = srcFile.renameTo(destFile);
            }
        }
        if (!renamed)
            throw new IOException("Unable to rename " + srcPath + " to " + destPath);
    } else {
        // Can't rename across volumes.  Copy then delete instead.
        FileUtil.copy(srcFile, destFile, !DebugConfig.disableMessageStoreFsync);
        srcFile.delete();
    }
    VolumeBlob vblob = (VolumeBlob) new VolumeBlob(destFile, volume.getId()).copyCachedDataFrom(blob);
    return new VolumeMailboxBlob(destMbox, destItemId, destRevision, volume.getLocator(), vblob);
}
Also used : Volume(com.zimbra.cs.volume.Volume) IOException(java.io.IOException) File(java.io.File)

Example 17 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class CreateVolume method redo.

@Override
public void redo() throws Exception {
    VolumeManager mgr = VolumeManager.getInstance();
    try {
        Volume vol = mgr.getVolume(id);
        if (vol != null) {
            mLog.info("Volume already exists id=%d", id);
            return;
        }
    } catch (VolumeServiceException e) {
        if (e.getCode() != VolumeServiceException.NO_SUCH_VOLUME) {
            throw e;
        }
    }
    try {
        Volume volume = Volume.builder().setId(id).setType(type).setName(name).setPath(rootPath, false).setMboxGroupBits(mboxGroupBits).setMboxBit(mboxBits).setFileGroupBits(fileGroupBits).setFileBits(fileBits).setCompressBlobs(compressBlobs).setCompressionThreshold(compressionThreshold).build();
        mgr.create(volume, getUnloggedReplay());
    } catch (VolumeServiceException e) {
        if (e.getCode() == VolumeServiceException.ALREADY_EXISTS) {
            mLog.info("Volume already exists id=%d", id);
        } else {
            throw e;
        }
    }
}
Also used : VolumeServiceException(com.zimbra.cs.volume.VolumeServiceException) VolumeManager(com.zimbra.cs.volume.VolumeManager) Volume(com.zimbra.cs.volume.Volume)

Example 18 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class CreateVolume method handle.

private CreateVolumeResponse handle(CreateVolumeRequest req, Map<String, Object> ctx) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(ctx);
    checkRight(zsc, ctx, Provisioning.getInstance().getLocalServer(), Admin.R_manageVolume);
    Volume vol = VolumeManager.getInstance().create(toVolume(req.getVolume()));
    return new CreateVolumeResponse(vol.toJAXB());
}
Also used : Volume(com.zimbra.cs.volume.Volume) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CreateVolumeResponse(com.zimbra.soap.admin.message.CreateVolumeResponse)

Example 19 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method testUniqueBlobDigests.

@Test
public void testUniqueBlobDigests() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 5; i++) {
        mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
        mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
    }
    Iterable<MailboxBlobInfo> allBlobs = null;
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
    for (MailboxBlobInfo info : allBlobs) {
        DbVolumeBlobs.addBlobReference(conn, info);
    }
    SpoolingCache<String> digests = DbVolumeBlobs.getUniqueDigests(conn, vol);
    Assert.assertEquals(5, digests.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Test(org.junit.Test)

Example 20 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method testDuplicateRow.

@Test
public void testDuplicateRow() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    MailboxBlobInfo blobInfo = new MailboxBlobInfo(null, mbox.getId(), msg.getId(), msg.getSavedSequence(), String.valueOf(vol.getId()), null);
    DbVolumeBlobs.addBlobReference(conn, blobInfo);
    try {
        DbVolumeBlobs.addBlobReference(conn, blobInfo);
        Assert.fail("expected exception");
    } catch (ServiceException e) {
    // expected
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ServiceException(com.zimbra.common.service.ServiceException) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Test(org.junit.Test)

Aggregations

Volume (com.zimbra.cs.volume.Volume)36 Mailbox (com.zimbra.cs.mailbox.Mailbox)17 Test (org.junit.Test)14 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)11 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)11 Message (com.zimbra.cs.mailbox.Message)10 BlobReference (com.zimbra.cs.store.file.BlobReference)9 MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)7 VolumeManager (com.zimbra.cs.volume.VolumeManager)7 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)7 File (java.io.File)5 HashMap (java.util.HashMap)5 StoreManager (com.zimbra.cs.store.StoreManager)3 FileBlobStore (com.zimbra.cs.store.file.FileBlobStore)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)2 Document (com.zimbra.cs.mailbox.Document)2 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)2