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