Search in sources :

Example 1 with DiskPartitionDuplicationException

use of org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException in project bookkeeper by apache.

the class BookieInitializationTest method testAllowDiskPartitionDuplicationDisabled.

/**
 * if ALLOW_MULTIPLEDIRS_UNDER_SAME_DISKPARTITION is disabled then Bookie initialization
 * will fail if there are multiple ledger/index/journal dirs are in same partition/filesystem.
 */
@Test
public void testAllowDiskPartitionDuplicationDisabled() throws Exception {
    File tmpDir1 = createTempDir("bookie", "test");
    File tmpDir2 = createTempDir("bookie", "test");
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    int port = PortManager.nextFreePort();
    // multiple ledgerdirs in same diskpartition
    conf.setZkServers(zkUtil.getZooKeeperConnectString()).setZkTimeout(5000);
    conf.setBookiePort(port).setJournalDirName(tmpDir1.getPath()).setLedgerDirNames(new String[] { tmpDir1.getPath(), tmpDir2.getPath() }).setIndexDirName(new String[] { tmpDir1.getPath() });
    conf.setAllowMultipleDirsUnderSameDiskPartition(false);
    BookieServer bs1 = null;
    try {
        bs1 = new BookieServer(conf);
        fail("Bookkeeper should not have started since AllowMultipleDirsUnderSameDiskPartition is not enabled");
    } catch (DiskPartitionDuplicationException dpde) {
    // Expected
    } finally {
        if (bs1 != null) {
            bs1.shutdown();
        }
    }
    tmpDir1 = createTempDir("bookie", "test");
    tmpDir2 = createTempDir("bookie", "test");
    port = PortManager.nextFreePort();
    // multiple indexdirs in same diskpartition
    conf.setZkServers(zkUtil.getZooKeeperConnectString()).setZkTimeout(5000);
    conf.setBookiePort(port).setJournalDirName(tmpDir1.getPath()).setLedgerDirNames(new String[] { tmpDir1.getPath() }).setIndexDirName(new String[] { tmpDir1.getPath(), tmpDir2.getPath() });
    conf.setAllowMultipleDirsUnderSameDiskPartition(false);
    bs1 = null;
    try {
        bs1 = new BookieServer(conf);
        fail("Bookkeeper should not have started since AllowMultipleDirsUnderSameDiskPartition is not enabled");
    } catch (DiskPartitionDuplicationException dpde) {
    // Expected
    } finally {
        if (bs1 != null) {
            bs1.shutdown();
        }
    }
    tmpDir1 = createTempDir("bookie", "test");
    tmpDir2 = createTempDir("bookie", "test");
    port = PortManager.nextFreePort();
    // multiple journaldirs in same diskpartition
    conf.setZkServers(zkUtil.getZooKeeperConnectString()).setZkTimeout(5000);
    conf.setBookiePort(port).setJournalDirsName(new String[] { tmpDir1.getPath(), tmpDir2.getPath() }).setLedgerDirNames(new String[] { tmpDir1.getPath() }).setIndexDirName(new String[] { tmpDir1.getPath() });
    conf.setAllowMultipleDirsUnderSameDiskPartition(false);
    bs1 = null;
    try {
        bs1 = new BookieServer(conf);
        fail("Bookkeeper should not have started since AllowMultipleDirsUnderSameDiskPartition is not enabled");
    } catch (DiskPartitionDuplicationException dpde) {
    // Expected
    } finally {
        if (bs1 != null) {
            bs1.shutdown();
        }
    }
}
Also used : DiskPartitionDuplicationException(org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) Test(org.junit.Test)

Example 2 with DiskPartitionDuplicationException

use of org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException in project bookkeeper by apache.

the class Bookie method checkIfDirsOnSameDiskPartition.

/**
 * Checks if multiple directories are in same diskpartition/filesystem/device.
 * If ALLOW_MULTIPLEDIRS_UNDER_SAME_DISKPARTITION config parameter is not enabled, and
 * if it is found that there are multiple directories in the same DiskPartition then
 * it will throw DiskPartitionDuplicationException.
 *
 * @param dirs dirs to validate
 *
 * @throws IOException
 */
private void checkIfDirsOnSameDiskPartition(List<File> dirs) throws DiskPartitionDuplicationException {
    boolean allowDiskPartitionDuplication = conf.isAllowMultipleDirsUnderSameDiskPartition();
    final MutableBoolean isDuplicationFoundAndNotAllowed = new MutableBoolean(false);
    Map<FileStore, List<File>> fileStoreDirsMap = new HashMap<FileStore, List<File>>();
    for (File dir : dirs) {
        FileStore fileStore;
        try {
            fileStore = Files.getFileStore(dir.toPath());
        } catch (IOException e) {
            LOG.error("Got IOException while trying to FileStore of {}", dir);
            throw new BookieException.DiskPartitionDuplicationException(e);
        }
        if (fileStoreDirsMap.containsKey(fileStore)) {
            fileStoreDirsMap.get(fileStore).add(dir);
        } else {
            List<File> dirsList = new ArrayList<File>();
            dirsList.add(dir);
            fileStoreDirsMap.put(fileStore, dirsList);
        }
    }
    fileStoreDirsMap.forEach((fileStore, dirsList) -> {
        if (dirsList.size() > 1) {
            if (allowDiskPartitionDuplication) {
                LOG.warn("Dirs: {} are in same DiskPartition/FileSystem: {}", dirsList, fileStore);
            } else {
                LOG.error("Dirs: {} are in same DiskPartition/FileSystem: {}", dirsList, fileStore);
                isDuplicationFoundAndNotAllowed.setValue(true);
            }
        }
    });
    if (isDuplicationFoundAndNotAllowed.getValue()) {
        throw new BookieException.DiskPartitionDuplicationException();
    }
}
Also used : DiskPartitionDuplicationException(org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException) HashMap(java.util.HashMap) ConcurrentLongHashMap(org.apache.bookkeeper.util.collections.ConcurrentLongHashMap) DiskPartitionDuplicationException(org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileStore(java.nio.file.FileStore) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with DiskPartitionDuplicationException

use of org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException in project bookkeeper by apache.

the class BookieInitializationTest method testAllowDiskPartitionDuplicationAllowed.

/**
 * if ALLOW_MULTIPLEDIRS_UNDER_SAME_DISKPARTITION is enabled then Bookie initialization
 * should succeed even if there are multiple ledger/index/journal dirs in the same diskpartition/filesystem.
 */
@Test
public void testAllowDiskPartitionDuplicationAllowed() throws Exception {
    File tmpDir1 = createTempDir("bookie", "test");
    File tmpDir2 = createTempDir("bookie", "test");
    File tmpDir3 = createTempDir("bookie", "test");
    File tmpDir4 = createTempDir("bookie", "test");
    File tmpDir5 = createTempDir("bookie", "test");
    File tmpDir6 = createTempDir("bookie", "test");
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    int port = 12555;
    conf.setZkServers(zkUtil.getZooKeeperConnectString()).setZkTimeout(5000);
    conf.setBookiePort(port).setJournalDirsName(new String[] { tmpDir1.getPath(), tmpDir2.getPath() }).setLedgerDirNames(new String[] { tmpDir3.getPath(), tmpDir4.getPath() }).setIndexDirName(new String[] { tmpDir5.getPath(), tmpDir6.getPath() });
    conf.setAllowMultipleDirsUnderSameDiskPartition(true);
    BookieServer bs1 = null;
    try {
        bs1 = new BookieServer(conf);
    } catch (DiskPartitionDuplicationException dpde) {
        fail("Bookkeeper should have started since AllowMultipleDirsUnderSameDiskPartition is enabled");
    } finally {
        if (bs1 != null) {
            bs1.shutdown();
        }
    }
}
Also used : DiskPartitionDuplicationException(org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)3 DiskPartitionDuplicationException (org.apache.bookkeeper.bookie.BookieException.DiskPartitionDuplicationException)3 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2 BookieServer (org.apache.bookkeeper.proto.BookieServer)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 IOException (java.io.IOException)1 FileStore (java.nio.file.FileStore)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentLongHashMap (org.apache.bookkeeper.util.collections.ConcurrentLongHashMap)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1