Search in sources :

Example 96 with DataStorageManagerException

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);
    }
}
Also used : Path(java.nio.file.Path) DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException)

Example 97 with DataStorageManagerException

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);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException)

Example 98 with DataStorageManagerException

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;
    }
}
Also used : Bytes(herddb.utils.Bytes) DataStorageManagerException(herddb.storage.DataStorageManagerException) ArrayList(java.util.ArrayList) Record(herddb.model.Record) IOException(java.io.IOException) ByteArrayCursor(herddb.utils.ByteArrayCursor)

Example 99 with DataStorageManagerException

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);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ODirectFileInputStream(herddb.utils.ODirectFileInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) LogSequenceNumber(herddb.log.LogSequenceNumber) IOException(java.io.IOException)

Example 100 with DataStorageManagerException

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);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) PostCheckpointAction(herddb.core.PostCheckpointAction) Bytes(herddb.utils.Bytes) IndexStatus(herddb.storage.IndexStatus) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashSet(java.util.HashSet)

Aggregations

DataStorageManagerException (herddb.storage.DataStorageManagerException)140 IOException (java.io.IOException)92 ArrayList (java.util.ArrayList)46 LogSequenceNumber (herddb.log.LogSequenceNumber)42 Bytes (herddb.utils.Bytes)30 Path (java.nio.file.Path)30 ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)25 SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)24 InputStream (java.io.InputStream)24 StatementExecutionException (herddb.model.StatementExecutionException)23 Table (herddb.model.Table)22 HashMap (java.util.HashMap)22 LogEntry (herddb.log.LogEntry)21 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)21 LogNotAvailableException (herddb.log.LogNotAvailableException)20 Record (herddb.model.Record)20 Index (herddb.model.Index)19 CommitLogResult (herddb.log.CommitLogResult)18 Transaction (herddb.model.Transaction)18 PostCheckpointAction (herddb.core.PostCheckpointAction)16