use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method getLastcheckpointSequenceNumber.
@Override
public LogSequenceNumber getLastcheckpointSequenceNumber(String tableSpace) throws DataStorageManagerException {
try {
Path tableSpaceDirectory = getTablespaceDirectory(tableSpace);
Files.createDirectories(tableSpaceDirectory);
LogSequenceNumber max = LogSequenceNumber.START_OF_TIME;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tableSpaceDirectory)) {
for (Path p : stream) {
if (isTablespaceCheckPointInfoFile(p)) {
try {
LogSequenceNumber logPositionInFile = readLogSequenceNumberFromCheckpointInfoFile(tableSpace, p);
if (logPositionInFile.after(max)) {
max = logPositionInFile;
}
} catch (DataStorageManagerException ignore) {
LOGGER.log(Level.SEVERE, "unparsable checkpoint info file " + p.toAbsolutePath(), ignore);
}
}
}
} catch (IOException err) {
LOGGER.log(Level.SEVERE, "Could not list dir " + tableSpaceDirectory, err);
}
return max;
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method writePage.
@Override
public void writePage(String tableSpace, String tableName, long pageId, Collection<Record> newPage) throws DataStorageManagerException {
// synch on table is done by the TableManager
long _start = System.currentTimeMillis();
Path tableDir = getTableDirectory(tableSpace, tableName);
Path pageFile = getPageFile(tableDir, pageId);
long size;
try {
if (pageodirect) {
try (ODirectFileOutputStream odirect = new ODirectFileOutputStream(pageFile, O_DIRECT_BLOCK_BATCH, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
size = writePage(newPage, null, odirect);
}
} else {
try (ManagedFile file = ManagedFile.open(pageFile, requirefsync, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
SimpleBufferedOutputStream buffer = new SimpleBufferedOutputStream(file.getOutputStream(), COPY_BUFFERS_SIZE)) {
size = writePage(newPage, file, buffer);
}
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
long now = System.currentTimeMillis();
long delta = (now - _start);
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "writePage {0} KBytes,{1} records, time {2} ms", new Object[] { (size / 1024) + "", newPage.size(), delta + "" });
}
dataPageWrites.registerSuccessfulEvent(delta, TimeUnit.MILLISECONDS);
}
use of herddb.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method dropTable.
@Override
public void dropTable(String tablespace, String tableName) throws DataStorageManagerException {
Path tableDir = getTableDirectory(tablespace, tableName);
LOGGER.log(Level.INFO, "dropTable {0}.{1} in {2}", new Object[] { tablespace, tableName, tableDir });
try {
deleteDirectory(tableDir);
} catch (IOException ex) {
throw new DataStorageManagerException(ex);
}
}
use of herddb.storage.DataStorageManagerException 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.storage.DataStorageManagerException in project herddb by diennea.
the class FileDataStorageManager method getTableStatus.
@Override
public TableStatus getTableStatus(String tableSpace, String tableUuid, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
try {
Path dir = getTableDirectory(tableSpace, tableUuid);
Path checkpointFile = getTableCheckPointsFile(dir, sequenceNumber);
if (!Files.exists(checkpointFile)) {
throw new DataStorageManagerException("no such table checkpoint: " + checkpointFile);
}
return readTableStatusFromFile(checkpointFile);
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
Aggregations