Search in sources :

Example 76 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement 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 = newServerConfigurationWithAutoPort();
    /* 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), 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());
        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), tmpDir, null, config1, null)) {
        manager.start();
        manager.waitForTablespace("tblspace1", 10000);
        assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
        assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getDirtypages());
    }
}
Also used : Path(java.nio.file.Path) FileCommitLogManager(herddb.file.FileCommitLogManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) ServerConfiguration(herddb.server.ServerConfiguration) FileDataStorageManager(herddb.file.FileDataStorageManager) RandomString(herddb.utils.RandomString) RawString(herddb.utils.RawString) Test(org.junit.Test)

Example 77 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class CreateTableTest method weThrowExceptionOnInsertingNullInNonNullColumn.

@Test(expected = StatementExecutionException.class)
public void weThrowExceptionOnInsertingNullInNonNullColumn() 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);
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.NOTNULL_STRING).primaryKey("id").build();
        CreateTableStatement st2 = new CreateTableStatement(table);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        TranslatedQuery translated1 = manager.getPlanner().translate("tblspace1", "INSERT INTO t1 (id,name) values(?,?)", Arrays.asList("test", "test1"), true, true, false, -1);
        manager.executePlan(translated1.plan, translated1.context, TransactionContext.NO_TRANSACTION);
        TranslatedQuery translated = manager.getPlanner().translate("tblspace1", "INSERT INTO t1 (id,name) values(?,?)", Arrays.asList("test", null), true, true, false, -1);
        manager.executePlan(translated.plan, translated.context, TransactionContext.NO_TRANSACTION);
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 78 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class CreateTableTest method createTableWithForeignKeys.

@Test
public void createTableWithForeignKeys() 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);
        Table parentTable = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        Table childTable = Table.builder().tablespace("tblspace1").name("t2").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).column("parenttableid", ColumnTypes.NOTNULL_STRING).primaryKey("id").foreingKey(ForeignKeyDef.builder().name("myfk").onDeleteAction(ForeignKeyDef.ACTION_NO_ACTION).onUpdateAction(ForeignKeyDef.ACTION_NO_ACTION).column("parenttableid").parentTableId(parentTable.uuid).parentTableColumn("id").build()).build();
        CreateTableStatement st2 = new CreateTableStatement(parentTable);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        CreateTableStatement st3 = new CreateTableStatement(childTable);
        manager.executeStatement(st3, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        ForeignKeyViolationException err = expectThrows(ForeignKeyViolationException.class, () -> {
            execute(manager, "INSERT INTO tblspace1.t2(id,name,parentTableId) values('a','name','pvalue')", Collections.emptyList());
        });
        assertEquals("myfk", err.getForeignKeyName());
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) ForeignKeyViolationException(herddb.model.ForeignKeyViolationException) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 79 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class CreateTableTest method createTable1.

@Test
public void createTable1() 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);
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        CreateTableStatement st2 = new CreateTableStatement(table);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        CreateTableStatement st2IfNotExists = new CreateTableStatement(table, Collections.emptyList(), true);
        manager.executeStatement(st2IfNotExists, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 80 with CreateTableSpaceStatement

use of herddb.model.commands.CreateTableSpaceStatement in project herddb by diennea.

the class DropTablespaceTest method test.

@Test
public void test() 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 primary key,n1 int,s1 string)", Collections.emptyList());
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(0, count.intValue());
        }
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM systablespaces WHERE tablespace_name=?", Arrays.asList("tblspace1"))) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(1, count.intValue());
        }
        manager.executeStatement(new DropTableSpaceStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM systablespaces WHERE tablespace_name=?", Arrays.asList("tblspace1"))) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(0, count.intValue());
        }
        boolean ok = false;
        for (int i = 0; i < 100; i++) {
            try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
                Thread.sleep(200);
            } catch (herddb.model.StatementExecutionException expected) {
                ok = true;
            }
        }
        assertTrue(ok);
        // create again the table space, all data should be lost
        CreateTableSpaceStatement st1_2 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1_2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);
        execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(0, count.intValue());
        }
    }
}
Also used : DropTableSpaceStatement(herddb.model.commands.DropTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)308 Test (org.junit.Test)295 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)241 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)240 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)236 DataScanner (herddb.model.DataScanner)164 RawString (herddb.utils.RawString)139 Table (herddb.model.Table)132 DBManager (herddb.core.DBManager)126 CreateTableStatement (herddb.model.commands.CreateTableStatement)111 ScanStatement (herddb.model.commands.ScanStatement)78 DataAccessor (herddb.utils.DataAccessor)77 TransactionContext (herddb.model.TransactionContext)69 TranslatedQuery (herddb.sql.TranslatedQuery)69 Path (java.nio.file.Path)67 Bytes (herddb.utils.Bytes)54 List (java.util.List)54 Index (herddb.model.Index)53 GetStatement (herddb.model.commands.GetStatement)53 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)51