use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method eraseTablespaceData.
@Override
public void eraseTablespaceData(String tableSpace) throws DataStorageManagerException {
SystemInstrumentation.instrumentationPoint("eraseTablespaceData", tableSpace);
Path tablespaceDirectory = getTablespaceDirectory(tableSpace);
LOGGER.log(Level.INFO, "erasing tablespace " + tableSpace + " directory {0}", tablespaceDirectory.toAbsolutePath().toString());
try {
FileUtils.cleanDirectory(tablespaceDirectory);
} catch (IOException err) {
LOGGER.log(Level.SEVERE, "Cannot clean directory for tablespace " + tableSpace, err);
throw new DataStorageManagerException(err);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method start.
@Override
public void start() throws DataStorageManagerException {
try {
LOGGER.log(Level.FINE, "ensuring directory {0}", baseDirectory.toAbsolutePath().toString());
Files.createDirectories(baseDirectory);
LOGGER.log(Level.FINE, "preparing tmp directory {0}", tmpDirectory.toAbsolutePath().toString());
FileUtils.cleanDirectory(tmpDirectory);
Files.createDirectories(tmpDirectory);
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method rawReadDataPage.
private List<Record> rawReadDataPage(Path pageFile, InputStream stream) throws IOException, DataStorageManagerException {
int size = (int) Files.size(pageFile);
byte[] dataPage = new byte[size];
int read = stream.read(dataPage);
if (read != size) {
throw new IOException("short read, read " + read + " instead of " + size + " bytes from " + pageFile);
}
try (ByteArrayCursor dataIn = ByteArrayCursor.wrap(dataPage)) {
// version
long version = dataIn.readVLong();
// flags for future implementations
long flags = dataIn.readVLong();
if (version != 1 || flags != 0) {
throw new DataStorageManagerException("corrupted data file " + pageFile.toAbsolutePath());
}
int numRecords = dataIn.readInt();
List<Record> result = new ArrayList<>(numRecords);
for (int i = 0; i < numRecords; i++) {
Bytes key = dataIn.readBytesNoCopy();
Bytes value = dataIn.readBytesNoCopy();
result.add(new Record(key, value));
}
int pos = dataIn.getPosition();
long hashFromFile = dataIn.readLong();
if (hashChecksEnabled && hashFromFile != NO_HASH_PRESENT) {
// after the hash we will have zeroes or garbage
// the hash is not at the end of file, but after data
long hashFromDigest = XXHash64Utils.hash(dataPage, 0, pos);
if (hashFromDigest != hashFromFile) {
throw new DataStorageManagerException("Corrupted datafile " + pageFile + ". Bad hash " + hashFromFile + " <> " + hashFromDigest);
}
}
return result;
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method readLogSequenceNumberFromTransactionsFile.
private static LogSequenceNumber readLogSequenceNumberFromTransactionsFile(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 transaction 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);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class BLinkKeyToPageIndex method checkpoint.
@Override
public List<PostCheckpointAction> checkpoint(LogSequenceNumber sequenceNumber, boolean pin) throws DataStorageManagerException {
try {
/* Tree can be null if no data was inserted (tree creation deferred to check evaluate key size) */
final BLink<Bytes, Long> tree = this.tree;
if (tree == null) {
return Collections.emptyList();
}
BLinkMetadata<Bytes> metadata = getTree().checkpoint();
byte[] metaPage = MetadataSerializer.INSTANCE.write(metadata);
Set<Long> activePages = new HashSet<>();
metadata.nodes.forEach(node -> activePages.add(node.storeId));
IndexStatus indexStatus = new IndexStatus(indexName, sequenceNumber, newPageId.get(), activePages, metaPage);
List<PostCheckpointAction> result = new ArrayList<>();
result.addAll(dataStorageManager.indexCheckpoint(tableSpace, indexName, indexStatus, pin));
LOGGER.log(Level.INFO, "checkpoint index {0} finished: logpos {1}, {2} pages", new Object[] { indexName, sequenceNumber, Integer.toString(metadata.nodes.size()) });
LOGGER.log(Level.FINE, "checkpoint index {0} finished: logpos {1}, pages {2}", new Object[] { indexName, sequenceNumber, activePages.toString() });
return result;
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
Aggregations