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