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