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);
}
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations