Search in sources :

Example 1 with DataPageDoesNotExistException

use of herddb.storage.DataPageDoesNotExistException in project herddb by diennea.

the class SimpleDMLFileTest method test.

@Test
public void test() throws Exception {
    {
        Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("0"));
        InsertStatement st = new InsertStatement(tableSpace, tableName, record);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    String tableUuid = manager.getTableSpaceManager(tableSpace).getTableManager(tableName).getTable().uuid;
    boolean notexist = false;
    try {
        dataStorageManager.readPage(tableSpaceUUID, tableUuid, 1L);
    } catch (DataPageDoesNotExistException ex) {
        notexist = true;
    } finally {
        assertTrue(notexist);
    }
    assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    manager.checkpoint();
    assertNotNull(dataStorageManager.readPage(tableSpaceUUID, tableUuid, 1L));
    assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    {
        GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertTrue(result.found());
    }
    manager.checkpoint();
    assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    {
        Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("5"));
        UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    // a new page must be allocated
    manager.checkpoint();
    assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    {
        Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("6"));
        UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    {
        Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("7"));
        UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    // only a new page must be allocated, not two more
    manager.checkpoint();
    assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    {
        DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key1"), null);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
        GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertFalse(result.found());
    }
    // a delete does not trigger new pages in this case
    manager.checkpoint();
    assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    {
        assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key2"), Bytes.from_string("50"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
        assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key3"), Bytes.from_string("60"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    manager.checkpoint();
    assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
    {
        DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key2"), null);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    // a new page, containg the key3 record is needed
    manager.checkpoint();
}
Also used : UpdateStatement(herddb.model.commands.UpdateStatement) GetResult(herddb.model.GetResult) GetStatement(herddb.model.commands.GetStatement) Record(herddb.model.Record) DeleteStatement(herddb.model.commands.DeleteStatement) InsertStatement(herddb.model.commands.InsertStatement) DataPageDoesNotExistException(herddb.storage.DataPageDoesNotExistException) Test(org.junit.Test)

Example 2 with DataPageDoesNotExistException

use of herddb.storage.DataPageDoesNotExistException in project herddb by diennea.

the class TableManager method loadPageToMemory.

private DataPage loadPageToMemory(Long pageId, boolean recovery) throws DataStorageManagerException {
    DataPage result = pages.get(pageId);
    if (result != null) {
        pageReplacementPolicy.pageHit(result);
        return result;
    }
    long _start = System.currentTimeMillis();
    long _ioAndLock = 0;
    AtomicBoolean computed = new AtomicBoolean();
    try {
        result = pages.computeIfAbsent(pageId, (id) -> {
            try {
                computed.set(true);
                List<Record> page;
                maxCurrentPagesLoads.acquireUninterruptibly();
                try {
                    page = dataStorageManager.readPage(tableSpaceUUID, table.uuid, pageId);
                } finally {
                    maxCurrentPagesLoads.release();
                }
                loadedPagesCount.increment();
                return buildImmutableDataPage(pageId, page);
            } catch (DataStorageManagerException err) {
                throw new RuntimeException(err);
            }
        });
        if (computed.get()) {
            _ioAndLock = System.currentTimeMillis();
            final Page.Metadata unload = pageReplacementPolicy.add(result);
            if (unload != null) {
                unload.owner.unload(unload.pageId);
            }
        }
    } catch (RuntimeException error) {
        if (error.getCause() != null) {
            Throwable cause = error.getCause();
            if (cause instanceof DataStorageManagerException) {
                if (cause instanceof DataPageDoesNotExistException) {
                    return null;
                }
                throw (DataStorageManagerException) cause;
            }
        }
        throw new DataStorageManagerException(error);
    }
    if (computed.get()) {
        long _stop = System.currentTimeMillis();
        LOGGER.log(Level.FINE, "table " + table.name + "," + "loaded " + result.size() + " records from page " + pageId + " in " + (_stop - _start) + " ms" + ", (" + (_ioAndLock - _start) + " ms read + plock" + ", " + (_stop - _ioAndLock) + " ms unlock)");
    }
    return result;
}
Also used : UpdateStatement(herddb.model.commands.UpdateStatement) Table(herddb.model.Table) TruncateTableStatement(herddb.model.commands.TruncateTableStatement) TupleComparator(herddb.model.TupleComparator) DuplicatePrimaryKeyException(herddb.model.DuplicatePrimaryKeyException) TableStatus(herddb.storage.TableStatus) ServerConfiguration(herddb.server.ServerConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) RecordTooBigException(herddb.model.RecordTooBigException) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) LocalLockManager(herddb.utils.LocalLockManager) DataStorageManagerException(herddb.storage.DataStorageManagerException) Index(herddb.model.Index) DataAccessor(herddb.utils.DataAccessor) LogNotAvailableException(herddb.log.LogNotAvailableException) InsertStatement(herddb.model.commands.InsertStatement) DataScanner(herddb.model.DataScanner) CommitLogResult(herddb.log.CommitLogResult) DDLException(herddb.model.DDLException) RecordFunction(herddb.model.RecordFunction) StatementExecutionException(herddb.model.StatementExecutionException) TableContext(herddb.model.TableContext) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) LogSequenceNumber(herddb.log.LogSequenceNumber) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) RecordSerializer(herddb.codec.RecordSerializer) DataPageMetaData(herddb.core.PageSet.DataPageMetaData) ScanStatement(herddb.model.commands.ScanStatement) List(java.util.List) Stream(java.util.stream.Stream) FullTableScanConsumer(herddb.storage.FullTableScanConsumer) GetStatement(herddb.model.commands.GetStatement) Entry(java.util.Map.Entry) Statement(herddb.model.Statement) Bytes(herddb.utils.Bytes) LongAdder(java.util.concurrent.atomic.LongAdder) Holder(herddb.utils.Holder) LockHandle(herddb.utils.LockHandle) LogEntry(herddb.log.LogEntry) GetResult(herddb.model.GetResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) PrimaryIndexSeek(herddb.index.PrimaryIndexSeek) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Level(java.util.logging.Level) BatchOrderedExecutor(herddb.utils.BatchOrderedExecutor) Transaction(herddb.model.Transaction) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Projection(herddb.model.Projection) EnsureLongIncrementAccumulator(herddb.utils.EnsureLongIncrementAccumulator) LogEntryType(herddb.log.LogEntryType) ScanLimits(herddb.model.ScanLimits) DeleteStatement(herddb.model.commands.DeleteStatement) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Record(herddb.model.Record) Semaphore(java.util.concurrent.Semaphore) DataPageDoesNotExistException(herddb.storage.DataPageDoesNotExistException) LogEntryFactory(herddb.log.LogEntryFactory) StatementExecutionResult(herddb.model.StatementExecutionResult) KeyToPageIndex(herddb.index.KeyToPageIndex) DataStorageManager(herddb.storage.DataStorageManager) ColumnTypes(herddb.model.ColumnTypes) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Lock(java.util.concurrent.locks.Lock) CommitLog(herddb.log.CommitLog) IndexOperation(herddb.index.IndexOperation) Predicate(herddb.model.Predicate) Column(herddb.model.Column) StatementEvaluationContext(herddb.model.StatementEvaluationContext) Comparator(java.util.Comparator) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) StampedLock(java.util.concurrent.locks.StampedLock) TableManagerStats(herddb.core.stats.TableManagerStats) SystemProperties(herddb.utils.SystemProperties) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataStorageManagerException(herddb.storage.DataStorageManagerException) List(java.util.List) ArrayList(java.util.ArrayList) DataPageDoesNotExistException(herddb.storage.DataPageDoesNotExistException)

Example 3 with DataPageDoesNotExistException

use of herddb.storage.DataPageDoesNotExistException in project herddb by diennea.

the class FileDataStorageManager method readPage.

@Override
public List<Record> readPage(String tableSpace, String tableName, Long pageId) throws DataStorageManagerException, DataPageDoesNotExistException {
    long _start = System.currentTimeMillis();
    Path tableDir = getTableDirectory(tableSpace, tableName);
    Path pageFile = getPageFile(tableDir, pageId);
    List<Record> result;
    try {
        result = rawReadDataPage(pageFile);
    } catch (NoSuchFileException nsfe) {
        throw new DataPageDoesNotExistException("No such page: " + tableSpace + "_" + tableName + "." + pageId, nsfe);
    } catch (IOException err) {
        throw new DataStorageManagerException("error reading data page: " + tableSpace + "_" + tableName + "." + pageId, err);
    }
    long _stop = System.currentTimeMillis();
    long delta = _stop - _start;
    LOGGER.log(Level.FINE, "readPage {0}.{1} {2} ms", new Object[] { tableSpace, tableName, delta + "" });
    return result;
}
Also used : Path(java.nio.file.Path) DataStorageManagerException(herddb.storage.DataStorageManagerException) NoSuchFileException(java.nio.file.NoSuchFileException) Record(herddb.model.Record) IOException(java.io.IOException) DataPageDoesNotExistException(herddb.storage.DataPageDoesNotExistException)

Aggregations

Record (herddb.model.Record)3 DataPageDoesNotExistException (herddb.storage.DataPageDoesNotExistException)3 GetResult (herddb.model.GetResult)2 DeleteStatement (herddb.model.commands.DeleteStatement)2 GetStatement (herddb.model.commands.GetStatement)2 InsertStatement (herddb.model.commands.InsertStatement)2 UpdateStatement (herddb.model.commands.UpdateStatement)2 RecordSerializer (herddb.codec.RecordSerializer)1 DataPageMetaData (herddb.core.PageSet.DataPageMetaData)1 TableManagerStats (herddb.core.stats.TableManagerStats)1 IndexOperation (herddb.index.IndexOperation)1 KeyToPageIndex (herddb.index.KeyToPageIndex)1 PrimaryIndexSeek (herddb.index.PrimaryIndexSeek)1 CommitLog (herddb.log.CommitLog)1 CommitLogResult (herddb.log.CommitLogResult)1 LogEntry (herddb.log.LogEntry)1 LogEntryFactory (herddb.log.LogEntryFactory)1 LogEntryType (herddb.log.LogEntryType)1 LogNotAvailableException (herddb.log.LogNotAvailableException)1 LogSequenceNumber (herddb.log.LogSequenceNumber)1