Search in sources :

Example 6 with SimpleByteArrayInputStream

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

the class BookKeeperDataStorageManager method readTableStatusFromFile.

public TableStatus readTableStatusFromFile(byte[] fileContent, String znode) throws IOException {
    if (fileContent == null) {
        throw new IOException("Missing ZNode for TableStatus at " + znode);
    }
    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 table status file " + znode);
        }
        return TableStatus.deserialize(dataIn);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) ByteArrayInputStream(java.io.ByteArrayInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 7 with SimpleByteArrayInputStream

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

the class FileDataStorageManager method readTableStatusFromFile.

public static TableStatus readTableStatusFromFile(Path checkpointsFile) throws IOException {
    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 table status file " + checkpointsFile.toAbsolutePath());
        }
        return TableStatus.deserialize(dataIn);
    }
}
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)

Example 8 with SimpleByteArrayInputStream

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

the class LogEntry method deserialize.

public static LogEntry deserialize(byte[] data) throws EOFException {
    SimpleByteArrayInputStream in = new SimpleByteArrayInputStream(data);
    ExtendedDataInputStream dis = new ExtendedDataInputStream(in);
    return deserialize(dis);
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream)

Example 9 with SimpleByteArrayInputStream

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

the class MemoryDataStorageManager method getLatestTableStatus.

@Override
public TableStatus getLatestTableStatus(String tableSpace, String tableName) throws DataStorageManagerException {
    LogSequenceNumber max = null;
    String prefix = tableSpace + "." + tableName + "_";
    for (String status : tableStatuses.keySet()) {
        if (status.startsWith(prefix)) {
            final LogSequenceNumber log = evaluateLogSequenceNumber(prefix);
            if (log != null) {
                if (max == null || log.after(max)) {
                    max = log;
                }
            }
        }
    }
    TableStatus latestStatus;
    if (max == null) {
        latestStatus = TableStatus.buildTableStatusForNewCreatedTable(tableName);
    } else {
        byte[] data = tableStatuses.get(checkpointName(tableSpace, tableName, max));
        if (data == null) {
            latestStatus = TableStatus.buildTableStatusForNewCreatedTable(tableName);
        } else {
            try {
                try (InputStream input = new SimpleByteArrayInputStream(data);
                    ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
                    latestStatus = TableStatus.deserialize(dataIn);
                }
            } catch (IOException err) {
                throw new DataStorageManagerException(err);
            }
        }
    }
    return latestStatus;
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) TableStatus(herddb.storage.TableStatus) LogSequenceNumber(herddb.log.LogSequenceNumber) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 10 with SimpleByteArrayInputStream

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

the class Table method deserialize.

@SuppressFBWarnings("OS_OPEN_STREAM")
public static Table deserialize(byte[] data) {
    try {
        SimpleByteArrayInputStream ii = new SimpleByteArrayInputStream(data);
        ExtendedDataInputStream dii = new ExtendedDataInputStream(ii);
        // version
        long tversion = dii.readVLong();
        // flags for future implementations
        long tflags = dii.readVLong();
        if (tversion != 1 || tflags != 0) {
            throw new IOException("corrupted table file");
        }
        String tablespace = dii.readUTF();
        String name = dii.readUTF();
        String uuid = dii.readUTF();
        boolean auto_increment = dii.readByte() > 0;
        int maxSerialPosition = dii.readVInt();
        byte pkcols = dii.readByte();
        String[] primaryKey = new String[pkcols];
        for (int i = 0; i < pkcols; i++) {
            primaryKey[i] = dii.readUTF();
        }
        // for future implementations
        int flags = dii.readVInt();
        int ncols = dii.readVInt();
        Column[] columns = new Column[ncols];
        for (int i = 0; i < ncols; i++) {
            // version
            long cversion = dii.readVLong();
            // flags for future implementations
            long cflags = dii.readVLong();
            if (cversion != COLUMNVERSION_1 || (cflags != COLUMNFLAGS_NO_FLAGS && cflags != COLUMNFLAGS_HAS_DEFAULT_VALUE)) {
                throw new IOException("corrupted table file");
            }
            String cname = dii.readUTF();
            int type = dii.readVInt();
            int serialPosition = dii.readVInt();
            Bytes defaultValue = null;
            if ((cflags & COLUMNFLAGS_HAS_DEFAULT_VALUE) == COLUMNFLAGS_HAS_DEFAULT_VALUE) {
                defaultValue = dii.readBytes();
            }
            columns[i] = Column.column(cname, type, serialPosition, defaultValue);
        }
        ForeignKeyDef[] foreignKeys = null;
        if ((flags & TABLEFLAGS_HAS_FOREIGN_KEYS) == TABLEFLAGS_HAS_FOREIGN_KEYS) {
            int numForeignKeys = dii.readVInt();
            if (numForeignKeys > 0) {
                foreignKeys = new ForeignKeyDef[numForeignKeys];
                for (int i = 0; i < numForeignKeys; i++) {
                    ForeignKeyDef.Builder builder = ForeignKeyDef.builder();
                    String fkName = dii.readUTF();
                    String parentTableId = dii.readUTF();
                    builder.parentTableId(parentTableId);
                    builder.name(fkName);
                    int numColumns = dii.readVInt();
                    for (int k = 0; k < numColumns; k++) {
                        String col = dii.readUTF();
                        builder.column(col);
                    }
                    for (int k = 0; k < numColumns; k++) {
                        String col = dii.readUTF();
                        builder.parentTableColumn(col);
                    }
                    builder.onUpdateAction(dii.readVInt());
                    builder.onDeleteAction(dii.readVInt());
                    foreignKeys[i] = builder.build();
                }
            }
        }
        return new Table(uuid, name, columns, primaryKey, tablespace, auto_increment, maxSerialPosition, foreignKeys);
    } catch (IOException err) {
        throw new IllegalArgumentException(err);
    }
}
Also used : IOException(java.io.IOException) Bytes(herddb.utils.Bytes) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)13 ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)12 IOException (java.io.IOException)11 InputStream (java.io.InputStream)8 DataStorageManagerException (herddb.storage.DataStorageManagerException)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ODirectFileInputStream (herddb.utils.ODirectFileInputStream)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 LogSequenceNumber (herddb.log.LogSequenceNumber)1 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 TableSpace (herddb.model.TableSpace)1 TableStatus (herddb.storage.TableStatus)1 Bytes (herddb.utils.Bytes)1 RawString (herddb.utils.RawString)1