use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class FileDataStorageManager method rawReadDataPage.
public static List<Record> rawReadDataPage(Path pageFile) throws DataStorageManagerException, IOException {
List<Record> result;
long hashFromFile;
long hashFromDigest;
try (ODirectFileInputStream odirect = new ODirectFileInputStream(pageFile, O_DIRECT_BLOCK_BATCH);
XXHash64Utils.HashingStream hash = new XXHash64Utils.HashingStream(odirect);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(hash)) {
// 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();
result = new ArrayList<>(numRecords);
for (int i = 0; i < numRecords; i++) {
Bytes key = dataIn.readBytes();
Bytes value = dataIn.readBytes();
result.add(new Record(key, value));
}
hashFromDigest = hash.hash();
hashFromFile = dataIn.readLong();
}
if (hashFromFile != NO_HASH_PRESENT && hashFromDigest != hashFromFile) {
throw new DataStorageManagerException("Corrupted datafile " + pageFile + ". Bad hash " + hashFromFile + " <> " + hashFromDigest);
}
return result;
}
use of herddb.utils.ExtendedDataInputStream 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.ExtendedDataInputStream in project herddb by diennea.
the class FileDataStorageManager method loadTransactions.
@Override
public void loadTransactions(LogSequenceNumber sequenceNumber, String tableSpace, Consumer<Transaction> consumer) throws DataStorageManagerException {
try {
Path tableSpaceDirectory = getTablespaceDirectory(tableSpace);
Files.createDirectories(tableSpaceDirectory);
Path file = getTablespaceTransactionsFile(tableSpace, sequenceNumber);
boolean exists = Files.isRegularFile(file);
LOGGER.log(Level.INFO, "loadTransactions " + sequenceNumber + " for tableSpace " + tableSpace + " from file " + file + " (exists: " + exists + ")");
if (!exists) {
return;
}
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();
if (ledgerId != sequenceNumber.ledgerId || offset != sequenceNumber.offset) {
throw new DataStorageManagerException("file " + file.toAbsolutePath() + " is not for sequence number " + sequenceNumber);
}
int numTransactions = din.readInt();
for (int i = 0; i < numTransactions; i++) {
Transaction tx = Transaction.deserialize(tableSpace, din);
consumer.accept(tx);
}
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.utils.ExtendedDataInputStream 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);
}
}
use of herddb.utils.ExtendedDataInputStream 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);
}
Aggregations