Search in sources :

Example 11 with Volume

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

the class TestDocumentServer method testCompressedVolume.

/**
     * Confirms that saving a document to a compressed volume works correctly (bug 48363).
     */
@Test
public void testCompressedVolume() throws Exception {
    // Normally the instant parsing is enabled for ZCS and disabled for Octopus.
    if (LC.documents_disable_instant_parsing.booleanValue() == true)
        return;
    VolumeManager mgr = VolumeManager.getInstance();
    Volume current = mgr.getCurrentMessageVolume();
    mgr.update(Volume.builder(current).setCompressBlobs(true).setCompressionThreshold(1).build());
    String content = "<wiklet class='TOC' format=\"template\" bodyTemplate=\"_TocBodyTemplate\" itemTemplate=\"_TocItemTemplate\">abc</wiklet>";
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    WikiItem wiki = mbox.createWiki(null, Mailbox.ID_FOLDER_BRIEFCASE, NAME_PREFIX + "-testCompressedVolume", "Unit Test", null, new ByteArrayInputStream(content.getBytes()));
    Assert.assertEquals("abc", wiki.getFragment());
}
Also used : VolumeManager(com.zimbra.cs.volume.VolumeManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) ByteArrayInputStream(java.io.ByteArrayInputStream) WikiItem(com.zimbra.cs.mailbox.WikiItem) Test(org.junit.Test)

Example 12 with Volume

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

the class BlobConsistencyChecker method check.

public Results check(Collection<Short> volumeIds, int mboxId, boolean checkSize, boolean reportUsedBlobs) throws ServiceException {
    StoreManager sm = StoreManager.getInstance();
    if (!(sm instanceof FileBlobStore)) {
        throw ServiceException.INVALID_REQUEST(sm.getClass().getSimpleName() + " is not supported", null);
    }
    mailboxId = mboxId;
    this.checkSize = checkSize;
    this.reportUsedBlobs = reportUsedBlobs;
    results = new Results();
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailboxId);
    DbConnection conn = null;
    try {
        conn = DbPool.getConnection();
        for (short volumeId : volumeIds) {
            Volume vol = VolumeManager.getInstance().getVolume(volumeId);
            if (vol.getType() == Volume.TYPE_INDEX) {
                log.warn("Skipping index volume %d.  Only message volumes are supported.", vol.getId());
                continue;
            }
            int numGroups = 1 << vol.getFileGroupBits();
            int filesPerGroup = 1 << vol.getFileBits();
            // Maximum id for the entire mailbox
            int mailboxMaxId = DbBlobConsistency.getMaxId(conn, mbox);
            // Iterate group directories one at a time, looking up all item id's
            // that have blobs in each directory.  Each group can have multiple blocks
            // of id's if we wrap from group 255 back to group 0.
            // Minimum id for the current block
            int minId = 0;
            // Current group number
            int group = 0;
            int maxId = 0;
            while (minId <= mailboxMaxId && group < numGroups) {
                // We used Multimap to make sure we store multiple BlobInfo objects for the same itemId
                // multiple BlobInfo objects are created when there are multiple revisions of the same file
                Multimap<Integer, BlobInfo> blobsById = HashMultimap.create();
                String blobDir = vol.getBlobDir(mbox.getId(), minId);
                while (minId <= mailboxMaxId) {
                    // Maximum id for the current block
                    maxId = minId + filesPerGroup - 1;
                    for (BlobInfo blob : DbBlobConsistency.getBlobInfo(conn, mbox, minId, maxId, volumeId)) {
                        blobsById.put(blob.itemId, blob);
                    }
                    minId += (numGroups * filesPerGroup);
                }
                try {
                    check(volumeId, blobDir, blobsById);
                } catch (IOException e) {
                    throw ServiceException.FAILURE("Unable to check " + blobDir, e);
                }
                group++;
                // Set minId to the smallest id in the next group
                minId = group * filesPerGroup;
            }
        }
    } finally {
        DbPool.quietClose(conn);
    }
    return results;
}
Also used : IOException(java.io.IOException) DbConnection(com.zimbra.cs.db.DbPool.DbConnection) StoreManager(com.zimbra.cs.store.StoreManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume)

Example 13 with Volume

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

the class BlobDeduper method updateMetadata.

private Volume updateMetadata(short volumeId, VolumeMetadata metadata) throws ServiceException {
    VolumeManager mgr = VolumeManager.getInstance();
    Volume.Builder builder = Volume.builder(mgr.getVolume(volumeId));
    builder.setMetadata(metadata);
    return mgr.update(builder.build());
}
Also used : VolumeManager(com.zimbra.cs.volume.VolumeManager) Volume(com.zimbra.cs.volume.Volume)

Example 14 with Volume

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

the class FileBlobStore method getBlobPath.

public static String getBlobPath(int mboxId, int itemId, int revision, short volumeId) throws ServiceException {
    Volume vol = MANAGER.getVolume(volumeId);
    String path = vol.getBlobDir(mboxId, itemId);
    int buflen = path.length() + 15 + (revision < 0 ? 0 : 11);
    StringBuilder sb = new StringBuilder(buflen);
    sb.append(path).append(File.separator);
    appendFilename(sb, itemId, revision);
    return sb.toString();
}
Also used : Volume(com.zimbra.cs.volume.Volume)

Example 15 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)

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