Search in sources :

Example 66 with DataScanner

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());
            }
        }
    }
}
Also used : AlterTableSpaceStatement(herddb.model.commands.AlterTableSpaceStatement) Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) Server(herddb.server.Server) GetResult(herddb.model.GetResult) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) ServerConfiguration(herddb.server.ServerConfiguration) CreateTableStatement(herddb.model.commands.CreateTableStatement) CreateIndexStatement(herddb.model.commands.CreateIndexStatement) Index(herddb.model.Index) InsertStatement(herddb.model.commands.InsertStatement) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) DataScanner(herddb.model.DataScanner) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) GetStatement(herddb.model.commands.GetStatement) HashSet(java.util.HashSet) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 67 with DataScanner

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());
            }
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) TranslatedQuery(herddb.sql.TranslatedQuery) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) PrimaryIndexPrefixScan(herddb.index.PrimaryIndexPrefixScan) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 68 with DataScanner

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());
            }
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) TranslatedQuery(herddb.sql.TranslatedQuery) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) SQLRecordPredicate(herddb.sql.SQLRecordPredicate) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 69 with DataScanner

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"));
            }
        }
    }
}
Also used : DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 70 with DataScanner

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"));
            }
        }
    }
}
Also used : DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) Test(org.junit.Test)

Aggregations

DataScanner (herddb.model.DataScanner)247 Test (org.junit.Test)195 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)163 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)155 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)155 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)151 DataAccessor (herddb.utils.DataAccessor)116 Table (herddb.model.Table)101 ScanStatement (herddb.model.commands.ScanStatement)100 RawString (herddb.utils.RawString)91 DBManager (herddb.core.DBManager)90 CreateTableStatement (herddb.model.commands.CreateTableStatement)81 TranslatedQuery (herddb.sql.TranslatedQuery)79 Index (herddb.model.Index)66 TransactionContext (herddb.model.TransactionContext)59 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)59 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)51 StatementExecutionException (herddb.model.StatementExecutionException)47 List (java.util.List)47 InsertStatement (herddb.model.commands.InsertStatement)40