use of herddb.model.DataScanner in project herddb by diennea.
the class BootFollowerTest method testLeaderOnlineLogAvailable.
@Test
public void testLeaderOnlineLogAvailable() throws Exception {
ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
// disabled
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.INTEGER).primaryKey("c").build();
Index index = Index.builder().onTable(table).type(Index.TYPE_BRIN).column("s", ColumnTypes.STRING).build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeStatement(new CreateIndexStatement(index), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1, "s", "1")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2, "s", "2")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3, "s", "3")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4, "s", "4")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
DMLStatementExecutionResult executeUpdateTransaction = server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 5, "s", "5")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.AUTOTRANSACTION_TRANSACTION);
server_1.getManager().executeStatement(new CommitTransactionStatement(TableSpace.DEFAULT, executeUpdateTransaction.transactionId), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
// force BK LAC
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 6, "s", "6")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
try (Server server_2 = new Server(serverconfig_2)) {
server_2.getManager().setActivatorPauseStatus(true);
server_2.start();
assertTrue(server_2.getManager().isTableSpaceLocallyRecoverable(server_2.getMetadataStorageManager().describeTableSpace(TableSpace.DEFAULT)));
server_2.getManager().setActivatorPauseStatus(false);
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
// wait for data to arrive on server_2
for (int i = 0; i < 100; i++) {
GetResult found = server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(5), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
if (found.found()) {
break;
}
Thread.sleep(100);
}
for (int i = 1; i <= 5; i++) {
System.out.println("checking key c=" + i);
assertTrue(server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(i), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
}
TranslatedQuery translated = server_1.getManager().getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM " + TableSpace.DEFAULT + ".t1 WHERE s=1", Collections.emptyList(), true, true, false, -1);
ScanStatement statement = translated.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(statement.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
try (DataScanner scan = server_1.getManager().scan(statement, translated.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(1, scan.consume().size());
}
}
}
}
use of herddb.model.DataScanner 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.DataScanner 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.DataScanner in project herddb by diennea.
the class SysnodesTest method listNodesTest.
@Test
public void listNodesTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager(nodeId, new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
try (DataScanner scan = scan(manager, "SELECT * FROM SYSNODES", Collections.emptyList())) {
List<DataAccessor> tuples = scan.consume();
assertEquals(1, tuples.size());
for (DataAccessor t : tuples) {
System.out.println("node: " + t.toMap());
assertNotNull(t.get("nodeid"));
assertNotNull(t.get("address"));
}
}
}
}
use of herddb.model.DataScanner in project herddb by diennea.
the class SysnodesTest method listNodesFileManagerTest.
@Test
public void listNodesFileManagerTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager(nodeId, new FileMetadataStorageManager(tmpFolder.getRoot().toPath()), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
try (DataScanner scan = scan(manager, "SELECT * FROM SYSNODES", Collections.emptyList())) {
List<DataAccessor> tuples = scan.consume();
assertEquals(1, tuples.size());
for (DataAccessor t : tuples) {
System.out.println("node: " + t.toMap());
assertNotNull(t.get("nodeid"));
assertNotNull(t.get("address"));
}
}
}
}
Aggregations