Search in sources :

Example 61 with MemoryCommitLogManager

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

the class AlterTableSQLTest method dropColumn.

@Test
public void dropColumn() 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());
        Table table = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable();
        assertEquals(0, table.getColumn("k1").serialPosition);
        assertEquals(1, table.getColumn("n1").serialPosition);
        assertEquals(2, table.getColumn("s1").serialPosition);
        execute(manager, "INSERT INTO tblspace1.tsql (k1,n1,s1) values('a',1,'b')", Collections.emptyList());
        {
            List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
            assertEquals(1, tuples.size());
            assertEquals(3, tuples.get(0).getFieldNames().length);
            assertEquals(RawString.of("b"), tuples.get(0).get("s1"));
        }
        execute(manager, "ALTER TABLE tblspace1.tsql drop column s1", Collections.emptyList());
        table = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable();
        assertEquals(0, table.getColumn("k1").serialPosition);
        assertEquals(1, table.getColumn("n1").serialPosition);
        assertEquals(2, table.columns.length);
        {
            List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
            assertEquals(1, tuples.size());
            assertEquals(2, tuples.get(0).getFieldNames().length);
            try {
                assertEquals(null, tuples.get(0).get("s1"));
                fail("field does not exist anymore");
            } catch (IllegalDataAccessException ok) {
            }
        }
        execute(manager, "ALTER TABLE tblspace1.tsql add column s1 string", Collections.emptyList());
        table = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable();
        assertEquals(0, table.getColumn("k1").serialPosition);
        assertEquals(1, table.getColumn("n1").serialPosition);
        assertEquals(3, table.getColumn("s1").serialPosition);
        {
            List<DataAccessor> tuples = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
            assertEquals(1, tuples.size());
            assertEquals(3, tuples.get(0).getFieldNames().length);
            assertEquals(null, tuples.get(0).get("s1"));
        }
        try {
            execute(manager, "ALTER TABLE tblspace1.tsql drop column k1", Collections.emptyList());
            fail();
        } catch (StatementExecutionException error) {
            assertTrue(error.getMessage().contains("column k1 cannot be dropped because is part of the primary key"));
        }
    }
}
Also used : IllegalDataAccessException(herddb.utils.IllegalDataAccessException) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) List(java.util.List) RawString(herddb.utils.RawString) StatementExecutionException(herddb.model.StatementExecutionException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 62 with MemoryCommitLogManager

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

the class AutoIncrementTest method testAutoIncrementInt.

@Test
public void testAutoIncrementInt() 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 (n1 int primary key auto_increment, s1 string)", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        List<DataAccessor> rows = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
        assertEquals(6, rows.size());
        for (int i = 1; i <= 6; i++) {
            int _i = i;
            assertTrue(rows.stream().filter(t -> t.get("n1").equals(Integer.valueOf(_i))).findAny().isPresent());
        }
        DMLStatementExecutionResult result = executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa"));
        assertEquals(1, result.getUpdateCount());
        assertEquals(Bytes.from_int(7), result.getKey());
    }
}
Also used : Bytes(herddb.utils.Bytes) DataAccessor(herddb.utils.DataAccessor) TestUtils.executeUpdate(herddb.core.TestUtils.executeUpdate) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Arrays(java.util.Arrays) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) TestUtils.scan(herddb.core.TestUtils.scan) TransactionContext(herddb.model.TransactionContext) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) StatementEvaluationContext(herddb.model.StatementEvaluationContext) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) TestUtils.execute(herddb.core.TestUtils.execute) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 63 with MemoryCommitLogManager

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

the class AutoIncrementTest method testAutoIncrementLong.

@Test
public void testAutoIncrementLong() 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 (n1 long primary key auto_increment, s1 string)", Collections.emptyList());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa")).getUpdateCount());
        List<DataAccessor> rows = scan(manager, "SELECT * FROM tblspace1.tsql", Collections.emptyList()).consume();
        assertEquals(6, rows.size());
        for (int i = 1; i <= 6; i++) {
            int _i = i;
            assertTrue(rows.stream().filter(t -> t.get("n1").equals(Long.valueOf(_i))).findAny().isPresent());
        }
        DMLStatementExecutionResult result = executeUpdate(manager, "INSERT INTO tblspace1.tsql(s1) values(?)", Arrays.asList("aa"));
        assertEquals(1, result.getUpdateCount());
        assertEquals(Bytes.from_long(7), result.getKey());
    }
}
Also used : Bytes(herddb.utils.Bytes) DataAccessor(herddb.utils.DataAccessor) TestUtils.executeUpdate(herddb.core.TestUtils.executeUpdate) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Arrays(java.util.Arrays) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) TestUtils.scan(herddb.core.TestUtils.scan) TransactionContext(herddb.model.TransactionContext) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) StatementEvaluationContext(herddb.model.StatementEvaluationContext) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) TestUtils.execute(herddb.core.TestUtils.execute) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 64 with MemoryCommitLogManager

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

the class Server method buildCommitLogManager.

private CommitLogManager buildCommitLogManager() {
    switch(mode) {
        case ServerConfiguration.PROPERTY_MODE_LOCAL:
            return new MemoryCommitLogManager();
        case ServerConfiguration.PROPERTY_MODE_STANDALONE:
            Path logDirectory = this.baseDirectory.resolve(configuration.getString(ServerConfiguration.PROPERTY_LOGDIR, ServerConfiguration.PROPERTY_LOGDIR_DEFAULT));
            return new FileCommitLogManager(logDirectory, 64 * 1024 * 1024);
        case ServerConfiguration.PROPERTY_MODE_CLUSTER:
            BookkeeperCommitLogManager bkmanager = new BookkeeperCommitLogManager((ZookeeperMetadataStorageManager) this.metadataStorageManager, configuration);
            bkmanager.setAckQuorumSize(configuration.getInt(ServerConfiguration.PROPERTY_BOOKKEEPER_ACKQUORUMSIZE, ServerConfiguration.PROPERTY_BOOKKEEPER_ACKQUORUMSIZE_DEFAULT));
            bkmanager.setEnsemble(configuration.getInt(ServerConfiguration.PROPERTY_BOOKKEEPER_ENSEMBLE, ServerConfiguration.PROPERTY_BOOKKEEPER_ENSEMBLE_DEFAULT));
            bkmanager.setWriteQuorumSize(configuration.getInt(ServerConfiguration.PROPERTY_BOOKKEEPER_WRITEQUORUMSIZE, ServerConfiguration.PROPERTY_BOOKKEEPER_WRITEQUORUMSIZE_DEFAULT));
            long ledgersRetentionPeriod = configuration.getLong(ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_RETENTION_PERIOD, ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_RETENTION_PERIOD_DEFAULT);
            bkmanager.setLedgersRetentionPeriod(ledgersRetentionPeriod);
            long checkPointperiod = configuration.getLong(ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD, ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD_DEFAULT);
            if (checkPointperiod > 0 && ledgersRetentionPeriod > 0) {
                long limit = ledgersRetentionPeriod / 2;
                if (checkPointperiod > limit) {
                    throw new RuntimeException(ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD + "=" + checkPointperiod + " must be less then " + ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_RETENTION_PERIOD + "/2=" + limit);
                }
            }
            return bkmanager;
        default:
            throw new RuntimeException();
    }
}
Also used : Path(java.nio.file.Path) FileCommitLogManager(herddb.file.FileCommitLogManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) BookkeeperCommitLogManager(herddb.cluster.BookkeeperCommitLogManager)

Example 65 with MemoryCommitLogManager

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

the class BigTableScanTest method bigTableScan.

@Test
public void bigTableScan() throws Exception {
    int testSize = 5000;
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.setMaxMemoryReference(128 * 1024);
        manager.setMaxLogicalPageSize(32 * 1024);
        manager.setMaxPKUsedMemory(manager.getMaxLogicalPageSize() * 2);
        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);
        for (int i = 0; i < testSize; i++) {
            InsertStatement insert = new InsertStatement(table.tablespace, table.name, RecordSerializer.makeRecord(table, "id", "k" + i, "name", "testname" + i));
            assertEquals(1, manager.executeUpdate(insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
        }
        TableManagerStats stats = manager.getTableSpaceManager(table.tablespace).getTableManager(table.name).getStats();
        assertEquals(testSize, stats.getTablesize());
        assertEquals(2, stats.getLoadedpages());
        manager.checkpoint();
        try (DataScanner scan = manager.scan(new ScanStatement(table.tablespace, table, new FullTableScanPredicate()), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION)) {
            AtomicInteger count = new AtomicInteger();
            scan.forEach(tuple -> {
                count.incrementAndGet();
            });
            assertEquals(testSize, count.get());
        }
        assertEquals(testSize, stats.getTablesize());
    }
}
Also used : Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) InsertStatement(herddb.model.commands.InsertStatement) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) TableManagerStats(herddb.core.stats.TableManagerStats) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) FullTableScanPredicate(herddb.model.FullTableScanPredicate) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) 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