use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class MemoryDataStorageManager method getTableStatus.
@Override
public TableStatus getTableStatus(String tableSpace, String tableName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
final String checkPoint = checkpointName(tableSpace, tableName, sequenceNumber);
byte[] data = tableStatuses.get(checkPoint);
if (data == null) {
throw new DataStorageManagerException("no such tablee checkpoint: " + checkPoint);
}
try {
try (InputStream input = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
return TableStatus.deserialize(dataIn);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class MemoryDataStorageManager method writeIndexPage.
@Override
public void writeIndexPage(String tableSpace, String indexName, long pageId, DataWriter writer) throws DataStorageManagerException {
Bytes page_wrapper;
try (ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
ExtendedDataOutputStream eout = new ExtendedDataOutputStream(out)) {
writer.write(eout);
eout.flush();
page_wrapper = Bytes.from_array(out.toByteArray());
} catch (IOException ex) {
throw new DataStorageManagerException(ex);
}
indexpages.put(tableSpace + "." + indexName + "_" + pageId, page_wrapper);
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class MemoryDataStorageManager method getIndexStatus.
@Override
public IndexStatus getIndexStatus(String tableSpace, String indexName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
final String checkPoint = checkpointName(tableSpace, indexName, sequenceNumber);
byte[] data = indexStatuses.get(checkPoint);
if (data == null) {
throw new DataStorageManagerException("no such index checkpoint: " + checkPoint);
}
try {
try (InputStream input = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
return IndexStatus.deserialize(dataIn);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class MemoryDataStorageManager method tableCheckpoint.
@Override
public List<PostCheckpointAction> tableCheckpoint(String tableSpace, String tableName, TableStatus tableStatus, boolean pin) throws DataStorageManagerException {
/* Checkpoint pinning */
final Map<Long, Integer> pins = pinTableAndGetPages(tableSpace, tableName, tableStatus, pin);
final Set<LogSequenceNumber> checkpoints = pinTableAndGetCheckpoints(tableSpace, tableName, tableStatus, pin);
List<Long> pagesForTable = new ArrayList<>();
String prefix = tableSpace + "." + tableName + "_";
for (String key : pages.keySet()) {
if (key.startsWith(prefix)) {
long pageId = Long.parseLong(key.substring(prefix.length()));
if (!pins.containsKey(pageId)) {
pagesForTable.add(pageId);
}
}
}
pagesForTable.removeAll(tableStatus.activePages.keySet());
List<PostCheckpointAction> result = new ArrayList<>();
for (long pageId : pagesForTable) {
result.add(new PostCheckpointAction(tableSpace, tableName, "drop page " + pageId) {
@Override
public void run() {
// remove only after checkpoint completed
pages.remove(prefix + pageId);
LOGGER.log(Level.SEVERE, "removing " + (prefix + pageId));
}
});
}
for (String oldStatus : tableStatuses.keySet()) {
if (oldStatus.startsWith(prefix)) {
/* Check for checkpoint skip only if match expected structure */
final LogSequenceNumber log = evaluateLogSequenceNumber(prefix);
if (log != null) {
/* If is pinned skip this status*/
if (checkpoints.contains(log)) {
continue;
}
}
result.add(new PostCheckpointAction(tableSpace, tableName, "drop table checkpoint " + oldStatus) {
@Override
public void run() {
// remove only after checkpoint completed
tableStatuses.remove(oldStatus);
}
});
}
}
VisibleByteArrayOutputStream oo = new VisibleByteArrayOutputStream(1024);
try (ExtendedDataOutputStream dataOutputKeys = new ExtendedDataOutputStream(oo)) {
tableStatus.serialize(dataOutputKeys);
dataOutputKeys.flush();
oo.write(oo.xxhash64());
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
/* Uses a copy to limit byte[] size at the min needed */
tableStatuses.put(checkpointName(tableSpace, tableName, tableStatus.sequenceNumber), oo.toByteArray());
return result;
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class BlockRangeIndex method boot.
public void boot(BlockRangeIndexMetadata<K> metadata) throws DataStorageManagerException {
if (metadata.getBlocksMetadata().size() > 0) {
LOG.info("boot index, with " + metadata.getBlocksMetadata().size() + " blocks");
}
if (metadata.getBlocksMetadata().size() == 0) {
reset();
} else {
clear();
/* Metadata are saved/recovered in reverse order so "next" block has been already created */
Block<K, V> next = null;
for (BlockRangeIndexMetadata.BlockMetadata<K> blockData : metadata.getBlocksMetadata()) {
/* Medatada safety check (do not trust blindly ordering) */
if (blockData.nextBlockId != null) {
if (next == null) {
throw new DataStorageManagerException("Wrong next block, expected notingh but " + blockData.nextBlockId + " found");
} else if (next.key.blockId != blockData.nextBlockId.longValue()) {
throw new DataStorageManagerException("Wrong next block, expected " + next.key.blockId + " but " + blockData.nextBlockId + " found");
}
} else {
if (next != null) {
throw new DataStorageManagerException("Wrong next block, expected " + next.key.blockId + " but nothing found");
}
}
final BlockStartKey<K> key = BlockStartKey.valueOf(blockData.firstKey, blockData.blockId);
next = new Block<>(this, key, blockData.size, blockData.pageId, next);
blocks.put(key, next);
currentBlockId.accumulateAndGet(Math.abs(next.key.blockId), EnsureLongIncrementAccumulator.INSTANCE);
}
}
}
Aggregations