use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class TableManager method executeStatementAsync.
@Override
public CompletableFuture<StatementExecutionResult> executeStatementAsync(Statement statement, Transaction transaction, StatementEvaluationContext context) {
CompletableFuture<StatementExecutionResult> res;
long lockStamp = checkpointLock.readLock();
if (statement instanceof UpdateStatement) {
UpdateStatement update = (UpdateStatement) statement;
res = executeUpdateAsync(update, transaction, context);
} else if (statement instanceof InsertStatement) {
InsertStatement insert = (InsertStatement) statement;
res = executeInsertAsync(insert, transaction, context);
} else if (statement instanceof GetStatement) {
GetStatement get = (GetStatement) statement;
res = executeGetAsync(get, transaction, context);
} else if (statement instanceof DeleteStatement) {
DeleteStatement delete = (DeleteStatement) statement;
res = executeDeleteAsync(delete, transaction, context);
} else if (statement instanceof TruncateTableStatement) {
try {
TruncateTableStatement truncate = (TruncateTableStatement) statement;
res = CompletableFuture.completedFuture(executeTruncate(truncate, transaction, context));
} catch (StatementExecutionException err) {
LOGGER.log(Level.SEVERE, "Truncate table failed", err);
res = Futures.exception(err);
}
} else if (statement instanceof TableConsistencyCheckStatement) {
DBManager manager = this.tableSpaceManager.getDbmanager();
res = CompletableFuture.completedFuture(manager.createTableCheckSum((TableConsistencyCheckStatement) statement, context));
} else {
res = Futures.exception(new StatementExecutionException("not implemented " + statement.getClass()));
}
res = res.whenComplete((r, error) -> {
checkpointLock.unlockRead(lockStamp);
});
if (statement instanceof TruncateTableStatement) {
res = res.whenComplete((r, error) -> {
if (error == null) {
try {
flush();
} catch (DataStorageManagerException err) {
throw new HerdDBInternalException(new StatementExecutionException("internal data error: " + err, err));
}
}
});
}
return res;
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class TableManager method rebuildNextPrimaryKeyValue.
private void rebuildNextPrimaryKeyValue() throws DataStorageManagerException {
LOGGER.log(Level.INFO, "rebuildNextPrimaryKeyValue");
try {
Stream<Entry<Bytes, Long>> scanner = keyToPage.scanner(null, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), tableContext, null);
scanner.forEach((Entry<Bytes, Long> t) -> {
Bytes key = t.getKey();
long pk_logical_value;
if (table.getColumn(table.primaryKey[0]).type == ColumnTypes.INTEGER || table.getColumn(table.primaryKey[0]).type == ColumnTypes.NOTNULL_INTEGER) {
pk_logical_value = key.to_int();
} else {
pk_logical_value = key.to_long();
}
nextPrimaryKeyValue.accumulateAndGet(pk_logical_value + 1, EnsureLongIncrementAccumulator.INSTANCE);
});
LOGGER.log(Level.INFO, "rebuildNextPrimaryKeyValue, newPkValue : " + nextPrimaryKeyValue.get());
} catch (StatementExecutionException impossible) {
throw new DataStorageManagerException(impossible);
}
}
use of herddb.storage.DataStorageManagerException 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;
BooleanHolder computed = new BooleanHolder(false);
try {
result = pages.computeIfAbsent(pageId, (id) -> {
try {
computed.value = 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.value) {
_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.value && LOGGER.isLoggable(Level.FINE)) {
long _stop = System.currentTimeMillis();
LOGGER.log(Level.FINE, "table {0}.{1}, loaded {2} records from page {3} in {4} ms, ({5} ms read + plock, {6} ms unlock)", new Object[] { table.tablespace, table.name, result.size(), pageId, (_stop - _start), (_ioAndLock - _start), (_stop - _ioAndLock) });
}
return result;
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method readLogSequenceNumberFromCheckpointInfoFile.
private static LogSequenceNumber readLogSequenceNumberFromCheckpointInfoFile(String tableSpace, Path checkPointFile) throws DataStorageManagerException, IOException {
try (InputStream input = new BufferedInputStream(Files.newInputStream(checkPointFile, StandardOpenOption.READ), 4 * 1024 * 1024);
ExtendedDataInputStream din = new ExtendedDataInputStream(input)) {
// version
long version = din.readVLong();
// flags for future implementations
long flags = din.readVLong();
if (version != 1 || flags != 0) {
throw new IOException("corrupted checkpoint file");
}
String readname = din.readUTF();
if (!readname.equals(tableSpace)) {
throw new DataStorageManagerException("file " + checkPointFile.toAbsolutePath() + " is not for spablespace " + tableSpace);
}
long ledgerId = din.readZLong();
long offset = din.readZLong();
return new LogSequenceNumber(ledgerId, offset);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method readLogSequenceNumberFromIndexMetadataFile.
private static LogSequenceNumber readLogSequenceNumberFromIndexMetadataFile(String tableSpace, Path file) throws DataStorageManagerException {
try (InputStream input = new BufferedInputStream(Files.newInputStream(file, StandardOpenOption.READ), 4 * 1024 * 1024);
ExtendedDataInputStream din = new ExtendedDataInputStream(input)) {
// version
long version = din.readVLong();
// flags for future implementations
long flags = din.readVLong();
if (version != 1 || flags != 0) {
throw new DataStorageManagerException("corrupted index list file " + file.toAbsolutePath());
}
String readname = din.readUTF();
if (!readname.equals(tableSpace)) {
throw new DataStorageManagerException("file " + file.toAbsolutePath() + " is not for spablespace " + tableSpace);
}
long ledgerId = din.readZLong();
long offset = din.readZLong();
return new LogSequenceNumber(ledgerId, offset);
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
Aggregations