use of herddb.index.brin.BRINIndexManager in project herddb by diennea.
the class SimpleBrinIndexRecoveryTest method createRecoveryIndex_withrepeatedkey.
@Test
public void createRecoveryIndex_withrepeatedkey() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Path tmoDir = folder.newFolder("tmoDir").toPath();
int id = 0;
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmoDir, 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);
assertTrue(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);
Index index = Index.builder().onTable(table).type(Index.TYPE_BRIN).column("name", ColumnTypes.STRING).build();
CreateIndexStatement st3 = new CreateIndexStatement(index);
manager.executeStatement(st3, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
BRINIndexManager brin = (BRINIndexManager) manager.getTableSpaceManager(table.tablespace).getIndexesOnTable(table.name).get(index.name);
while (brin.getNumBlocks() < 2) {
id++;
TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,name) values('" + id + "','my_repeatad_key')", Collections.emptyList(), TransactionContext.NO_TRANSACTION);
}
// some data on disk
manager.checkpoint();
// some data to be recovered from log
while (brin.getNumBlocks() < 3) {
id++;
TestUtils.executeUpdate(manager, "INSERT INTO tblspace1.t1(id,name) values('" + id + "','my_repeatad_key')", Collections.emptyList(), TransactionContext.NO_TRANSACTION);
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.t1", Collections.emptyList())) {
assertEquals(id, scan1.consume().size());
}
}
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmoDir, null)) {
manager.start();
assertTrue(manager.waitForBootOfLocalTablespaces(10000));
TranslatedQuery translated = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.t1 WHERE name='my_repeatad_key'", Collections.emptyList(), true, true, false, -1);
ScanStatement scan = translated.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(scan.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
try (DataScanner scan1 = manager.scan(scan, translated.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(id, scan1.consume().size());
}
}
}
use of herddb.index.brin.BRINIndexManager in project herddb by diennea.
the class TableSpaceManager method bootIndex.
private AbstractIndexManager bootIndex(Index index, AbstractTableManager tableManager, long transaction, boolean rebuild) throws DataStorageManagerException {
long _start = System.currentTimeMillis();
LOGGER.log(Level.SEVERE, "bootIndex {0} {1}.{2}.{3} uuid {4}", new Object[] { nodeId, tableSpaceName, index.table, index.name, index.uuid });
if (indexes.containsKey(index.name)) {
throw new DataStorageManagerException("Index" + index.name + " already present in tableSpace " + tableSpaceName);
}
AbstractIndexManager indexManager;
switch(index.type) {
case Index.TYPE_HASH:
indexManager = new MemoryHashIndexManager(index, tableManager, log, dataStorageManager, this, tableSpaceUUID, transaction);
break;
case Index.TYPE_BRIN:
indexManager = new BRINIndexManager(index, dbmanager.getMemoryManager(), tableManager, log, dataStorageManager, this, tableSpaceUUID, transaction);
break;
default:
throw new DataStorageManagerException("invalid index type " + index.type);
}
indexes.put(index.name, indexManager);
// this must be mutable (see DROP INDEX)
Map<String, AbstractIndexManager> newMap = new HashMap<>();
newMap.put(index.name, indexManager);
indexesByTable.merge(index.table, newMap, (a, b) -> {
Map<String, AbstractIndexManager> map = new HashMap<>(a);
map.putAll(b);
return map;
});
indexManager.start(tableManager.getBootSequenceNumber());
long _stop = System.currentTimeMillis();
LOGGER.log(Level.SEVERE, "bootIndex {0} {1}.{2} time {3} ms", new Object[] { nodeId, tableSpaceName, index.name, (_stop - _start) + "" });
if (rebuild) {
indexManager.rebuild();
LOGGER.log(Level.SEVERE, "bootIndex - rebuild {0} {1}.{2} time {3} ms", new Object[] { nodeId, tableSpaceName, index.name, (System.currentTimeMillis() - _stop) + "" });
}
dbmanager.getPlanner().clearCache();
return indexManager;
}
Aggregations