use of herddb.server.ServerConfiguration in project herddb by diennea.
the class BaseBench method makeServerConfiguration.
protected void makeServerConfiguration() throws IOException {
serverConfiguration = new ServerConfiguration(folder.newFolder().toPath());
serverConfiguration.set(ServerConfiguration.PROPERTY_PORT, 7002);
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class ReplicatedLogtestcase method startDBManager.
protected DBManager startDBManager(String nodeId) throws Exception {
File nodeDirectory = new File(folder.getRoot(), nodeId + "");
nodeDirectory.mkdirs();
Path path = nodeDirectory.toPath();
ZookeeperMetadataStorageManager metadataStorageManager = new ZookeeperMetadataStorageManager(testEnv.getAddress(), testEnv.getTimeout(), "/tests");
BookkeeperCommitLogManager commitLogManager = new BookkeeperCommitLogManager(metadataStorageManager, new ServerConfiguration());
FileDataStorageManager dataStorageManager = new FileDataStorageManager(path);
System.setErr(System.out);
DBManager manager = new DBManager(nodeId, metadataStorageManager, dataStorageManager, commitLogManager, folder.newFolder().toPath(), null);
manager.start();
return manager;
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class CheckpointTest method restartTest.
/**
* Reload dirty pages on restart
*/
@Test
public void restartTest() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Path tmpDir = folder.newFolder("tmpDir").toPath();
String nodeId = "localhost";
ServerConfiguration config1 = new ServerConfiguration();
/* Disable page compaction (avoid compaction of dirty page) */
config1.set(ServerConfiguration.PROPERTY_FILL_PAGE_THRESHOLD, 0.0D);
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmpDir, null, config1)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (K1 string ,s1 string,n1 int, primary key(k1))", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey", "a", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey2", "a", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey3", "a", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey4", "a", Integer.valueOf(1234))).getUpdateCount());
manager.checkpoint();
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=? where k1=?", Arrays.asList("b", "mykey4")).getUpdateCount());
manager.checkpoint();
assertEquals(3, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getDirtypages());
}
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmpDir, null, config1)) {
manager.start();
manager.waitForTablespace("tblspace1", 10000);
assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getDirtypages());
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class CheckpointTest method rebuildSmallPages.
/**
* Rebuild all small pages
*/
@Test
public void rebuildSmallPages() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Path tmpDir = folder.newFolder("tmpDir").toPath();
String nodeId = "localhost";
ServerConfiguration config1 = new ServerConfiguration();
config1.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 1024L);
int records = 1000;
int keylen = 25;
int strlen = 50;
int originalPages;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmpDir, null, config1)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string, s1 string, n1 int, primary key(k1))", Collections.emptyList());
for (int i = 0; i < records; ++i) {
executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList(RandomString.getInstance().nextString(keylen), RandomString.getInstance().nextString(strlen), Integer.valueOf(i)));
}
manager.checkpoint();
String uuid = manager.getMetadataStorageManager().describeTableSpace("tblspace1").uuid;
String tableUuid = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().uuid;
originalPages = manager.getDataStorageManager().getActualNumberOfPages(uuid, tableUuid);
assertTrue(originalPages > 10);
}
ServerConfiguration config2 = new ServerConfiguration();
config2.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 2048L);
config2.set(ServerConfiguration.PROPERTY_COMPACTION_DURATION, -1L);
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmpDir, null, config2)) {
manager.start();
assertTrue(manager.waitForTablespace("tblspace1", 20000));
manager.checkpoint();
String tableUuid = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().uuid;
String uuid = manager.getMetadataStorageManager().describeTableSpace("tblspace1").uuid;
int pages = manager.getDataStorageManager().getActualNumberOfPages(uuid, tableUuid);
/* There are at least half pages! */
assertTrue(pages <= (originalPages / 2) + (originalPages % 2));
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class AdvancedInsertSyntaxTest method testInsertFromSelect.
@Test
public void testInsertFromSelect() throws Exception {
try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
server.start();
server.waitForStandaloneBoot();
try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
try (BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client);
Connection con = dataSource.getConnection();
Statement create = con.createStatement();
PreparedStatement statement = con.prepareStatement("INSERT INTO mytable (name) values(?)")) {
create.execute("CREATE TABLE mytable (n1 int primary key auto_increment, name string)");
create.execute("CREATE TABLE mytable2 (n1 int primary key auto_increment, name string)");
{
for (int i = 0; i < 100; i++) {
statement.setString(1, "v" + i);
statement.addBatch();
}
int[] results = statement.executeBatch();
for (int i = 0; i < 100; i++) {
assertEquals(1, results[i]);
}
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable ORDER BY n1")) {
int count = 0;
while (rs.next()) {
assertEquals("v" + count, rs.getString("name"));
assertEquals(count + 1, rs.getInt("n1"));
count++;
}
assertEquals(100, count);
}
}
statement.executeUpdate("INSERT INTO mytable2(n1,name) SELECT n1, name from mytable order by name desc");
try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable2")) {
assertTrue(rs.next());
assertEquals(100, rs.getInt(1));
}
// leverage auto_increment
statement.executeUpdate("INSERT INTO mytable2(name) SELECT name from mytable order by name desc");
try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable2")) {
assertTrue(rs.next());
assertEquals(200, rs.getInt(1));
}
try (ResultSet rs = statement.executeQuery("SELECT n1 FROM mytable2 order by n1")) {
Set<Integer> ids = new HashSet<>();
while (rs.next()) {
int id = rs.getInt(1);
assertTrue(ids.add(id));
}
assertEquals(200, ids.size());
}
}
}
}
}
Aggregations