use of herddb.core.AbstractTableManager in project herddb by diennea.
the class CalcitePlanner method getRootSchema.
private SchemaPlus getRootSchema() {
if (rootSchema != null) {
return rootSchema;
}
final SchemaPlus _rootSchema = Frameworks.createRootSchema(true);
for (String tableSpace : manager.getLocalTableSpaces()) {
TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
SchemaPlus schema = _rootSchema.add(tableSpace, new AbstractSchema());
List<Table> tables = tableSpaceManager.getAllTablesForPlanner();
for (Table table : tables) {
AbstractTableManager tableManager = tableSpaceManager.getTableManager(table.name);
TableImpl tableDef = new TableImpl(tableManager);
schema.add(table.name, tableDef);
}
}
rootSchema = _rootSchema;
return _rootSchema;
}
use of herddb.core.AbstractTableManager in project herddb by diennea.
the class SimpleFollowerTest method testLeaderOnlineLogAvailableMultipleVersionsActivePages.
@Test
public void testLeaderOnlineLogAvailableMultipleVersionsActivePages() throws Exception {
ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 1000);
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);
serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
// delete ledgers soon
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_RETENTION_PERIOD, 1);
serverconfig_1.set(ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD, 0);
// disabled
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
/*
* Disable page compaction (avoid compaction of dirty page)
*/
serverconfig_1.set(ServerConfiguration.PROPERTY_FILL_PAGE_THRESHOLD, 0.0D);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BOOT_FORCE_DOWNLOAD_SNAPSHOT, true).set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.STRING).primaryKey("c").build();
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
TableSpaceManager tableSpaceManager = server_1.getManager().getTableSpaceManager(TableSpace.DEFAULT);
AbstractTableManager tableManager = tableSpaceManager.getTableManager("t1");
// fill table
long tx = herddb.core.TestUtils.beginTransaction(server_1.getManager(), TableSpace.DEFAULT);
for (int i = 0; i < 1000; i++) {
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i, "s", "1")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
}
herddb.core.TestUtils.commitTransaction(server_1.getManager(), TableSpace.DEFAULT, tx);
// when we send the dump to the follower we must send only the latest version of the record
for (int i = 0; i < 10; i++) {
tableManager.flush();
server_1.getManager().executeUpdate(new UpdateStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1, "s", "2" + i), null), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
}
BooleanHolder foundDuplicate = new BooleanHolder(false);
server_1.getManager().getDataStorageManager().fullTableScan(tableSpaceManager.getTableSpaceUUID(), tableManager.getTable().uuid, new FullTableScanConsumer() {
Map<Bytes, Long> recordPage = new HashMap<>();
@Override
public void acceptPage(long pageId, List<Record> records) {
for (Record record : records) {
Long prev = recordPage.put(record.key, pageId);
if (prev != null) {
foundDuplicate.value = true;
}
}
}
});
assertTrue(foundDuplicate.value);
// data will be downloaded from the server_1 (PROPERTY_BOOT_FORCE_DOWNLOAD_SNAPSHOT)
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertTrue(server_2.getManager().isTableSpaceLocallyRecoverable(server_1.getMetadataStorageManager().describeTableSpace(TableSpace.DEFAULT)));
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));
}
}
}
use of herddb.core.AbstractTableManager in project herddb by diennea.
the class ShowCreateTableCalculatorTest method test.
@Test
public void test() {
Table t = Table.builder().uuid("1234").column("k1", ColumnTypes.INTEGER).column("s1", ColumnTypes.STRING).primaryKey("k1").tablespace("ts1").name("test3").build();
AbstractTableManager tm = new MockTableManager(t, new ArrayList<>());
assertTrue(ShowCreateTableCalculator.calculate(false, "test3", "ts1", tm).equals("CREATE TABLE ts1.test3(k1 integer,s1 string,PRIMARY KEY(k1))"));
t = Table.builder().uuid("1234").column("k1", ColumnTypes.INTEGER).column("s1", ColumnTypes.STRING).column("s2", ColumnTypes.NOTNULL_STRING).primaryKey("k1", true).primaryKey("s2").tablespace("ts1").name("test3").build();
tm = new MockTableManager(t, new ArrayList<>());
assertTrue(ShowCreateTableCalculator.calculate(false, "test3", "ts1", tm).equals("CREATE TABLE ts1.test3(k1 integer auto_increment,s1 string,s2 string not null,PRIMARY KEY(k1,s2))"));
t = Table.builder().uuid("1234").column("k1", ColumnTypes.INTEGER).column("s1", ColumnTypes.NOTNULL_STRING).column("l1", ColumnTypes.NOTNULL_LONG).column("i1", ColumnTypes.NOTNULL_INTEGER).primaryKey("k1", true).tablespace("ts1").name("test3").build();
tm = new MockTableManager(t, new ArrayList<>());
assertTrue(ShowCreateTableCalculator.calculate(false, "test3", "ts1", tm).equals("CREATE TABLE ts1.test3(k1 integer auto_increment,s1 string not null,l1 long not null,i1 integer not null,PRIMARY KEY(k1))"));
t = Table.builder().uuid("1234").column("ID", ColumnTypes.INTEGER).column("s1", ColumnTypes.NOTNULL_STRING).column("l1", ColumnTypes.NOTNULL_LONG).column("i1", ColumnTypes.NOTNULL_INTEGER).primaryKey("ID", true).tablespace("ts1").name("test4").build();
tm = new MockTableManager(t, new ArrayList<>());
assertTrue(ShowCreateTableCalculator.calculate(false, "test4", "ts1", tm).equals("CREATE TABLE ts1.test4(id integer auto_increment,s1 string not null,l1 long not null,i1 integer not null,PRIMARY KEY(id))"));
}
use of herddb.core.AbstractTableManager in project herddb by diennea.
the class SystablestatsTableManager method buildVirtualRecordList.
@Override
protected Iterable<Record> buildVirtualRecordList() {
List<Table> tables = tableSpaceManager.getAllCommittedTables();
List<Record> result = new ArrayList<>();
for (Table r : tables) {
AbstractTableManager tableManager = tableSpaceManager.getTableManager(r.name);
if (tableManager != null && !tableManager.isSystemTable()) {
TableManagerStats stats = tableManager.getStats();
result.add(RecordSerializer.makeRecord(table, "tablespace", r.tablespace, "table_name", r.name, "systemtable", r.name.startsWith("sys") ? "true" : "false", "tablesize", stats.getTablesize(), "loadedpages", stats.getLoadedpages(), "loadedpagescount", stats.getLoadedPagesCount(), "unloadedpagescount", stats.getUnloadedPagesCount(), "dirtypages", stats.getDirtypages(), "dirtyrecords", stats.getDirtyrecords(), "maxlogicalpagesize", stats.getMaxLogicalPageSize(), "keysmemory", stats.getKeysUsedMemory(), "buffersmemory", stats.getBuffersUsedMemory()));
}
}
return result;
}
use of herddb.core.AbstractTableManager in project herddb by diennea.
the class SQLPlanner method buildCreateIndexStatement.
private Statement buildCreateIndexStatement(String defaultTableSpace, CreateIndex s) throws StatementExecutionException {
try {
String tableSpace = s.getTable().getSchemaName();
if (tableSpace == null) {
tableSpace = defaultTableSpace;
}
String tableName = s.getTable().getName();
String indexName = s.getIndex().getName().toLowerCase();
String indexType = convertIndexType(s.getIndex().getType());
herddb.model.Index.Builder builder = herddb.model.Index.builder().name(indexName).uuid(UUID.randomUUID().toString()).type(indexType).table(tableName).tablespace(tableSpace);
AbstractTableManager tableDefinition = manager.getTableSpaceManager(tableSpace).getTableManager(tableName);
if (tableDefinition == null) {
throw new TableDoesNotExistException("no such table " + tableName + " in tablespace " + tableSpace);
}
for (String columnName : s.getIndex().getColumnsNames()) {
columnName = columnName.toLowerCase();
Column column = tableDefinition.getTable().getColumn(columnName);
if (column == null) {
throw new StatementExecutionException("no such column " + columnName + " on table " + tableName + " in tablespace " + tableSpace);
}
builder.column(column.name, column.type);
}
CreateIndexStatement statement = new CreateIndexStatement(builder.build());
return statement;
} catch (IllegalArgumentException err) {
throw new StatementExecutionException("bad index definition: " + err.getMessage(), err);
}
}
Aggregations