use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class MemoryDataStorageManager method getIndexStatus.
@Override
public IndexStatus getIndexStatus(String tableSpace, String indexName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
final String checkPoint = checkpointName(tableSpace, indexName, sequenceNumber);
byte[] data = indexStatuses.get(checkPoint);
if (data == null) {
throw new DataStorageManagerException("no such index checkpoint: " + checkPoint);
}
try {
try (InputStream input = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
return IndexStatus.deserialize(dataIn);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.utils.ExtendedDataInputStream 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.ExtendedDataInputStream in project herddb by diennea.
the class BookKeeperDataStorageManager method loadIndexes.
@Override
public List<Index> loadIndexes(LogSequenceNumber sequenceNumber, String tableSpace) throws DataStorageManagerException {
try {
String file = getTablespaceIndexesMetadataFile(tableSpace, sequenceNumber);
LOGGER.log(Level.INFO, "loadIndexes for tableSpace " + tableSpace + " from " + file + ", sequenceNumber:" + sequenceNumber);
byte[] content = readZNode(file, new Stat());
if (content == null) {
if (sequenceNumber.isStartOfTime()) {
LOGGER.log(Level.INFO, "file " + file + " not found");
return Collections.emptyList();
} else {
throw new DataStorageManagerException("local index data not available for tableSpace " + tableSpace + ", recovering from sequenceNumber " + sequenceNumber);
}
}
try (InputStream input = new ByteArrayInputStream(content);
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 index list file " + file);
}
String readname = din.readUTF();
if (!readname.equals(tableSpace)) {
throw new DataStorageManagerException("file " + file + " is not for tablespace " + tableSpace);
}
long ledgerId = din.readZLong();
long offset = din.readZLong();
if (ledgerId != sequenceNumber.ledgerId || offset != sequenceNumber.offset) {
throw new DataStorageManagerException("file " + file + " is not for sequence number " + sequenceNumber);
}
int numTables = din.readInt();
List<Index> res = new ArrayList<>();
for (int i = 0; i < numTables; i++) {
byte[] indexData = din.readArray();
Index table = Index.deserialize(indexData);
res.add(table);
}
return Collections.unmodifiableList(res);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class BookKeeperDataStorageManager method readLogSequenceNumberFromTransactionsFile.
private static LogSequenceNumber readLogSequenceNumberFromTransactionsFile(String tableSpace, byte[] data, String file) throws DataStorageManagerException {
try (InputStream input = new ByteArrayInputStream(data);
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 znode " + file);
}
String readname = din.readUTF();
if (!readname.equals(tableSpace)) {
throw new DataStorageManagerException("znode " + file + " 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 BookKeeperDataStorageManager method readLogSequenceNumberFromIndexMetadataFile.
private static LogSequenceNumber readLogSequenceNumberFromIndexMetadataFile(String tableSpace, byte[] data, String znode) throws DataStorageManagerException {
try (InputStream input = new ByteArrayInputStream(data);
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 index list znode " + znode);
}
String readname = din.readUTF();
if (!readname.equals(tableSpace)) {
throw new DataStorageManagerException("znode " + znode + " 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);
}
}
Aggregations