use of herddb.utils.ODirectFileInputStream in project herddb by diennea.
the class FileDataStorageManager method readIndexPage.
@Override
public <X> X readIndexPage(String tableSpace, String indexName, Long pageId, DataReader<X> reader) throws DataStorageManagerException {
Path tableDir = getIndexDirectory(tableSpace, indexName);
Path pageFile = getPageFile(tableDir, pageId);
long _start = System.currentTimeMillis();
X result;
try {
if (indexodirect) {
try (ODirectFileInputStream odirect = new ODirectFileInputStream(pageFile, O_DIRECT_BLOCK_BATCH)) {
result = readIndexPage(reader, pageFile, odirect);
}
} else {
try (InputStream input = Files.newInputStream(pageFile);
BufferedInputStream buffer = new BufferedInputStream(input, COPY_BUFFERS_SIZE)) {
result = readIndexPage(reader, pageFile, buffer);
}
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
long _stop = System.currentTimeMillis();
long delta = _stop - _start;
LOGGER.log(Level.FINE, "readIndexPage {0}.{1} {2} ms", new Object[] { tableSpace, indexName, delta + "" });
indexPageReads.registerSuccessfulEvent(delta, TimeUnit.MILLISECONDS);
return result;
}
use of herddb.utils.ODirectFileInputStream 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.ODirectFileInputStream in project herddb by diennea.
the class FileDataStorageManager method readPage.
@Override
public List<Record> readPage(String tableSpace, String tableName, Long pageId) throws DataStorageManagerException {
long _start = System.currentTimeMillis();
Path tableDir = getTableDirectory(tableSpace, tableName);
Path pageFile = getPageFile(tableDir, pageId);
List<Record> result;
try {
if (pageodirect) {
try (ODirectFileInputStream odirect = new ODirectFileInputStream(pageFile, O_DIRECT_BLOCK_BATCH)) {
result = rawReadDataPage(pageFile, odirect);
}
} else {
try (InputStream input = Files.newInputStream(pageFile);
BufferedInputStream buffer = new BufferedInputStream(input, COPY_BUFFERS_SIZE)) {
result = rawReadDataPage(pageFile, buffer);
}
}
} catch (NoSuchFileException nsfe) {
throw new DataPageDoesNotExistException("No such page: " + tableSpace + "_" + tableName + "." + pageId, nsfe);
} catch (IOException err) {
throw new DataStorageManagerException("error reading data page: " + tableSpace + "_" + tableName + "." + pageId, err);
}
long _stop = System.currentTimeMillis();
long delta = _stop - _start;
LOGGER.log(Level.FINE, "readPage {0}.{1} {2} ms", new Object[] { tableSpace, tableName, delta + "" });
dataPageReads.registerSuccessfulEvent(delta, TimeUnit.MILLISECONDS);
return result;
}
Aggregations