Search in sources :

Example 66 with MemoryCommitLogManager

use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.

the class CheckpointTest method keepDirtyTest.

/**
 * Keep dirty pages even after checkpoint
 */
@Test
public void keepDirtyTest() throws Exception {
    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 MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, 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();
        /* Dirty a page with few data */
        assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=? where k1=?", Arrays.asList("b", "mykey4")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey5", "a", Integer.valueOf(1234))).getUpdateCount());
        manager.checkpoint();
        /* The page is still dirty */
        assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getDirtypages());
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) ServerConfiguration(herddb.server.ServerConfiguration) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RandomString(herddb.utils.RandomString) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 67 with MemoryCommitLogManager

use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.

the class DeleteTest method deleteDeleteWithMulticolumnPKTest.

@Test
public void deleteDeleteWithMulticolumnPKTest() 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(), NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);
        execute(manager, "CREATE TABLE tblspace1.tsql (K1 string ,s1 string,n1 int, primary key(k1,s1))", 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());
        try {
            executeUpdate(manager, "DELETE FROM tblspace1.tsql WHERE badfield=1234", Collections.emptyList());
            fail();
        } catch (StatementExecutionException ok) {
            ok.printStackTrace();
            assertTrue(ok.getCause() instanceof IllegalDataAccessException || ok.getMessage().contains("BADFIELD"));
        }
        assertEquals(4, executeUpdate(manager, "DELETE FROM tblspace1.tsql WHERE N1=1234", Collections.emptyList()).getUpdateCount());
        assertEquals(0, scan(manager, "SELECT * FROM tblspace1.tsql WHERE N1=1234", Collections.emptyList()).consume().size());
    }
}
Also used : IllegalDataAccessException(herddb.utils.IllegalDataAccessException) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) StatementExecutionException(herddb.model.StatementExecutionException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 68 with MemoryCommitLogManager

use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.

the class RawSQLTest method updateSingleRowWithPredicate.

@Test
public void updateSingleRowWithPredicate() 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_MESSAGE (MSG_ID bigint primary key,status int, lastbouncecategory tinyint)", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_MESSAGE(msg_id,status, lastbouncecategory) values(?,?,?)", Arrays.asList(2, 1, null)).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.q1_MESSAGE(msg_id,status, lastbouncecategory) values(?,?,?)", Arrays.asList(3, 1, null)).getUpdateCount());
        try (DataScanner resultSet = scan(manager, "SELECT * FROM tblspace1.q1_MESSAGE", Collections.emptyList())) {
            List<DataAccessor> consume = resultSet.consume();
            for (DataAccessor tuple : consume) {
                System.out.println("tuple1:" + tuple.toMap());
            }
        }
        assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.q1_MESSAGE set status=?, lastbouncecategory=null where MSG_ID=? and (status = 1 or status=5)", Arrays.asList(4, 2)).getUpdateCount());
        try (DataScanner resultSet = scan(manager, "SELECT * FROM tblspace1.q1_MESSAGE", Collections.emptyList())) {
            List<DataAccessor> consume = resultSet.consume();
            for (DataAccessor tuple : consume) {
                System.out.println("tuple2:" + tuple.toMap());
            }
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 69 with MemoryCommitLogManager

use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.

the class RawSQLTest method createDropIndexTest.

@Test
public void createDropIndexTest() 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());
        execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
        try {
            execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
            fail();
        } catch (IndexAlreadyExistsException ok) {
        }
        execute(manager, "DROP INDEX tblspace1.ix1", Collections.emptyList());
        execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
        execute(manager, "CREATE HASH INDEX ix_hash ON tblspace1.tsql(n1)", Collections.emptyList());
        try {
            execute(manager, "CREATE BADTYPE INDEX ix_bad ON tblspace1.tsql(n1)", Collections.emptyList());
            fail();
        } catch (StatementExecutionException ok) {
            assertTrue(ok.getMessage().contains("badtype"));
        }
        try {
            execute(manager, "DROP INDEX tblspace1.ix2", Collections.emptyList());
            fail();
        } catch (IndexDoesNotExistException ok) {
        }
        try {
            execute(manager, "DROP INDEX ix1", Collections.emptyList());
            fail();
        } catch (IndexDoesNotExistException ok) {
        }
        try {
            execute(manager, "CREATE INDEX ix2 ON tsql(n1)", Collections.emptyList());
            fail();
        } catch (TableDoesNotExistException ok) {
        }
        try {
            execute(manager, "CREATE INDEX duplicatecolumn ON tblspace1.tsql(n1,n1)", Collections.emptyList());
            fail();
        } catch (StatementExecutionException ok) {
        }
    }
}
Also used : TableDoesNotExistException(herddb.model.TableDoesNotExistException) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) StatementExecutionException(herddb.model.StatementExecutionException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 70 with MemoryCommitLogManager

use of herddb.mem.MemoryCommitLogManager in project herddb by diennea.

the class RawSQLTest method insertJdbcParametersTest.

@Test
public void insertJdbcParametersTest() 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());
        {
            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(n1,k1) values(?,?)", Arrays.asList(Integer.valueOf(1234), "mykey2")).getUpdateCount());
        }
        {
            assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(n1,k1,s1) values(?,?,?)", Arrays.asList(Integer.valueOf(1234), "mykey3", "string2")).getUpdateCount());
        }
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)110 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)109 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)108 Test (org.junit.Test)105 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)103 DataScanner (herddb.model.DataScanner)71 RawString (herddb.utils.RawString)57 DataAccessor (herddb.utils.DataAccessor)37 ScanStatement (herddb.model.commands.ScanStatement)30 TranslatedQuery (herddb.sql.TranslatedQuery)27 Table (herddb.model.Table)26 List (java.util.List)26 CreateTableStatement (herddb.model.commands.CreateTableStatement)23 Index (herddb.model.Index)17 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)17 TransactionContext (herddb.model.TransactionContext)16 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)14 DBManager (herddb.core.DBManager)10 StatementExecutionException (herddb.model.StatementExecutionException)10 SQLPlanner (herddb.sql.SQLPlanner)10