use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.
the class RestartTestBase method recoverAfterrPartialCheckpoint.
@Test
public void recoverAfterrPartialCheckpoint() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Path tmoDir = folder.newFolder("tmoDir").toPath();
String nodeId = "localhost";
Table table1;
Table table2;
try (DBManager manager = buildDBManager(nodeId, metadataPath, dataPath, logsPath, tmoDir)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(manager.waitForTablespace("tblspace1", 10000));
table1 = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.INTEGER).column("name", ColumnTypes.STRING).primaryKey("id").build();
table2 = Table.builder().tablespace("tblspace1").name("t2").column("id", ColumnTypes.INTEGER).column("name", ColumnTypes.STRING).primaryKey("id").build();
manager.executeStatement(new CreateTableStatement(table1), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.executeStatement(new CreateTableStatement(table2), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id) values(1)", Collections.emptyList());
TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t2(id) values(1)", Collections.emptyList());
TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t2(id) values(2)", Collections.emptyList());
TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t2(id) values(3)", Collections.emptyList());
assertTrue(manager.get(new GetStatement("tblspace1", table1.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(2), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(3), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
manager.getTableSpaceManager("tblspace1").setAfterTableCheckPointAction(new Runnable() {
@Override
public void run() {
throw new RuntimeException("error!");
}
});
try {
manager.checkpoint();
fail();
} catch (RuntimeException err) {
err.printStackTrace();
assertEquals("error!", err.getMessage());
}
assertTrue(manager.get(new GetStatement("tblspace1", table1.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(2), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(3), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
}
try (DBManager manager = buildDBManager(nodeId, metadataPath, dataPath, logsPath, tmoDir)) {
manager.start();
assertTrue(manager.waitForBootOfLocalTablespaces(10000));
assertTrue(manager.get(new GetStatement("tblspace1", table1.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(2), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(3), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
manager.checkpoint();
assertTrue(manager.get(new GetStatement("tblspace1", table1.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(2), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager.get(new GetStatement("tblspace1", table2.name, Bytes.from_int(3), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
}
}
use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.
the class SimpleIndexAccessTest method multipleColumnPrimaryKeyPrefixScanWithAliasTest.
@Test
public void multipleColumnPrimaryKeyPrefixScanWithAliasTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.q1_HISTORY (\n" + " MSG_ID BIGINT NOT NULL,\n" + " SID TINYINT NOT NULL, \n" + " STATUS INT NOT NULL,\n" + " TIMESTAMP TIMESTAMP,\n" + " STATUSLINE VARCHAR(2000) NULL,\n" + " IDBOUNCECATEGORY SMALLINT NULL,\n" + " PRIMARY KEY (MSG_ID, SID)\n" + ") ;", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(1,1,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(1,2,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(1,3,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(2,1,1)", Collections.emptyList()).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_HISTORY(MSG_ID,SID,STATUS) values(2,2,1)", Collections.emptyList()).getUpdateCount());
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "" + "SELECT H.SID, H.STATUS, H.`TIMESTAMP`, H.STATUSLINE, H.IDBOUNCECATEGORY " + "FROM tblspace1.q1_HISTORY AS H " + "WHERE H.MSG_ID=?", Arrays.asList(1), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate().getIndexOperation() instanceof PrimaryIndexPrefixScan);
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(3, scan1.consume().size());
}
}
}
}
use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.
the class SimpleIndexAccessTest method whereOnPkScanTest.
@Test
public void whereOnPkScanTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string," + "n1 int primary key," + "s1 string " + ")", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(1235))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(1236))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey4", Integer.valueOf(1237))).getUpdateCount());
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where n1 >= ?", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertTrue(sqlPred.getPrimaryKeyFilter() != null);
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = ((ScanResult) manager.executePlan(translate.plan, translate.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
assertEquals(3, scan1.consume().size());
}
}
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where n1 >= 30", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertTrue(sqlPred.getPrimaryKeyFilter() != null);
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(4, scan1.consume().size());
}
}
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql" + " where n1 >= 30 and n1 >= 1235", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertTrue(sqlPred.getPrimaryKeyFilter() != null);
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(3, scan1.consume().size());
}
}
{
TranslatedQuery translate = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey," + "'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where n1 >= 10000 or n1 >= ?", Arrays.asList(1235), true, true, false, -1);
ScanStatement scan = translate.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate() instanceof SQLRecordPredicate);
SQLRecordPredicate sqlPred = (SQLRecordPredicate) scan.getPredicate();
assertNull(sqlPred.getPrimaryKeyFilter());
System.out.println("pkFilter:" + sqlPred.getPrimaryKeyFilter());
try (DataScanner scan1 = manager.scan(scan, translate.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(3, scan1.consume().size());
}
}
}
}
use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.
the class SimpleReplicationTest method test.
@Test
public void test() throws Exception {
final String tableName = "table1";
final String tableSpaceName = "t2";
try (DBManager manager1 = startDBManager("node1")) {
manager1.executeStatement(new CreateTableSpaceStatement(tableSpaceName, new HashSet<>(Arrays.asList("node1", "node2")), "node1", 1, 0, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(manager1.waitForTablespace(tableSpaceName, 10000, true));
try (DBManager manager2 = startDBManager("node2")) {
assertTrue(manager2.waitForTablespace(tableSpaceName, 10000, false));
manager1.executeStatement(new CreateTableStatement(Table.builder().tablespace(tableSpaceName).name(tableName).primaryKey("key").column("key", ColumnTypes.STRING).build()), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(manager1.waitForTable(tableSpaceName, tableName, 10000, true));
manager1.executeStatement(new InsertStatement(tableSpaceName, tableName, new Record(Bytes.from_string("one"), Bytes.from_string("two"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
// write a second entry on the ledger, to speed up the ack from the bookie
manager1.executeStatement(new InsertStatement(tableSpaceName, tableName, new Record(Bytes.from_string("second"), Bytes.from_string("two"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(manager1.get(new GetStatement(tableSpaceName, tableName, Bytes.from_string("one"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
assertTrue(manager2.waitForTable(tableSpaceName, tableName, 10000, false));
manager2.setErrorIfNotLeader(false);
for (int i = 0; i < 100; i++) {
boolean ok = manager2.get(new GetStatement(tableSpaceName, tableName, Bytes.from_string("one"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found();
if (ok) {
break;
}
Thread.sleep(100);
}
assertTrue(manager2.get(new GetStatement(tableSpaceName, tableName, Bytes.from_string("one"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
}
}
}
use of herddb.model.commands.CreateTableSpaceStatement 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 = newServerConfigurationWithAutoPort();
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), tmpDir, null, config1, null)) {
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 = newServerConfigurationWithAutoPort();
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), tmpDir, null, config2, null)) {
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));
}
}
Aggregations