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"));
}
}
}
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());
}
}
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());
}
}
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();
}
}
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());
}
}
Aggregations