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