Search in sources :

Example 6 with ExtendedDataInputStream

use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.

the class FileDataStorageManager method readIndexStatusFromFile.

public static IndexStatus readIndexStatusFromFile(Path checkpointsFile) throws DataStorageManagerException {
    try {
        byte[] fileContent = FileUtils.fastReadFile(checkpointsFile);
        XXHash64Utils.verifyBlockWithFooter(fileContent, 0, fileContent.length);
        try (InputStream input = new SimpleByteArrayInputStream(fileContent);
            ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
            // version
            long version = dataIn.readVLong();
            // flags for future implementations
            long flags = dataIn.readVLong();
            if (version != 1 || flags != 0) {
                throw new DataStorageManagerException("corrupted index status file " + checkpointsFile.toAbsolutePath());
            }
            return IndexStatus.deserialize(dataIn);
        }
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) BufferedInputStream(java.io.BufferedInputStream) ODirectFileInputStream(herddb.utils.ODirectFileInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 7 with ExtendedDataInputStream

use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.

the class FileDataStorageManager method readTablespaceStructure.

public static List<Table> readTablespaceStructure(Path file, String tableSpace, LogSequenceNumber sequenceNumber) throws IOException, 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 table 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();
        if (sequenceNumber != null) {
            if (ledgerId != sequenceNumber.ledgerId || offset != sequenceNumber.offset) {
                throw new DataStorageManagerException("file " + file.toAbsolutePath() + " is not for sequence number " + sequenceNumber);
            }
        }
        int numTables = din.readInt();
        List<Table> res = new ArrayList<>();
        for (int i = 0; i < numTables; i++) {
            byte[] tableData = din.readArray();
            Table table = Table.deserialize(tableData);
            res.add(table);
        }
        return Collections.unmodifiableList(res);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) Table(herddb.model.Table) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ODirectFileInputStream(herddb.utils.ODirectFileInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Example 8 with ExtendedDataInputStream

use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.

the class FileDataStorageManager method readLogSequenceNumberFromTablesMetadataFile.

private static LogSequenceNumber readLogSequenceNumberFromTablesMetadataFile(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 table 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 9 with ExtendedDataInputStream

use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.

the class FileMetadataStorageManager method readTableSpaceMetadataFile.

public static TableSpace readTableSpaceMetadataFile(Path p) throws IOException, MetadataStorageManagerException {
    TableSpace ts;
    byte[] pageData;
    try {
        pageData = FileUtils.fastReadFile(p);
    } catch (IOException err) {
        throw new MetadataStorageManagerException(err);
    }
    boolean okHash = XXHash64Utils.verifyBlockWithFooter(pageData, 0, pageData.length);
    if (!okHash) {
        throw new MetadataStorageManagerException("corrutped data file " + p.toAbsolutePath() + ", checksum failed");
    }
    try (InputStream in = new SimpleByteArrayInputStream(pageData);
        ExtendedDataInputStream iin = new ExtendedDataInputStream(in)) {
        // version
        long version = iin.readVLong();
        // flags for future implementations
        long flags = iin.readVLong();
        if (version != 1 || flags != 0) {
            throw new IOException("corrupted data file " + p.toAbsolutePath());
        }
        ts = TableSpace.deserialize(iin, 0, 0);
    }
    return ts;
}
Also used : MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) TableSpace(herddb.model.TableSpace) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 10 with ExtendedDataInputStream

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

Aggregations

ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)28 SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)27 IOException (java.io.IOException)23 DataStorageManagerException (herddb.storage.DataStorageManagerException)22 InputStream (java.io.InputStream)22 ODirectFileInputStream (herddb.utils.ODirectFileInputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 LogSequenceNumber (herddb.log.LogSequenceNumber)9 BufferedInputStream (java.io.BufferedInputStream)9 ArrayList (java.util.ArrayList)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 KeyToPageIndex (herddb.index.KeyToPageIndex)2 BLinkKeyToPageIndex (herddb.index.blink.BLinkKeyToPageIndex)2 Index (herddb.model.Index)2 Table (herddb.model.Table)2 Transaction (herddb.model.Transaction)2 Bytes (herddb.utils.Bytes)2 RawString (herddb.utils.RawString)2 Path (java.nio.file.Path)2 Stat (org.apache.zookeeper.data.Stat)2