Search in sources :

Example 1 with BRINIndexManager

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());
        }
    }
}
Also used : Path(java.nio.file.Path) Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) CreateIndexStatement(herddb.model.commands.CreateIndexStatement) BRINIndexManager(herddb.index.brin.BRINIndexManager) Index(herddb.model.Index) FileCommitLogManager(herddb.file.FileCommitLogManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) FileDataStorageManager(herddb.file.FileDataStorageManager) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 2 with BRINIndexManager

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;
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MemoryHashIndexManager(herddb.index.MemoryHashIndexManager) BRINIndexManager(herddb.index.brin.BRINIndexManager)

Aggregations

BRINIndexManager (herddb.index.brin.BRINIndexManager)2 FileCommitLogManager (herddb.file.FileCommitLogManager)1 FileDataStorageManager (herddb.file.FileDataStorageManager)1 FileMetadataStorageManager (herddb.file.FileMetadataStorageManager)1 MemoryHashIndexManager (herddb.index.MemoryHashIndexManager)1 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)1 DataScanner (herddb.model.DataScanner)1 Index (herddb.model.Index)1 Table (herddb.model.Table)1 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)1 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)1 CreateTableStatement (herddb.model.commands.CreateTableStatement)1 ScanStatement (herddb.model.commands.ScanStatement)1 TranslatedQuery (herddb.sql.TranslatedQuery)1 DataStorageManagerException (herddb.storage.DataStorageManagerException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.Test)1