use of herddb.log.LogSequenceNumber 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.log.LogSequenceNumber 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.log.LogSequenceNumber in project herddb by diennea.
the class SyslogstatusManager method buildVirtualRecordList.
@Override
protected Iterable<Record> buildVirtualRecordList(Transaction transaction) throws StatementExecutionException {
boolean isVirtual = tableSpaceManager.isVirtual();
boolean isLeader = tableSpaceManager.isLeader();
LogSequenceNumber logSequenceNumber = isVirtual ? null : tableSpaceManager.getLog().getLastSequenceNumber();
List<Record> result = new ArrayList<>();
result.add(RecordSerializer.makeRecord(table, "tablespace_uuid", tableSpaceManager.getTableSpaceUUID(), "nodeid", tableSpaceManager.getDbmanager().getNodeId(), "tablespace_name", tableSpaceManager.getTableSpaceName(), "ledger", isVirtual ? 0L : logSequenceNumber.ledgerId, "offset", isVirtual ? 0L : logSequenceNumber.offset, "status", isVirtual ? "virtual" : isLeader ? "leader" : "follower"));
return result;
}
use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class MemoryCommitLogManager method createCommitLog.
@Override
public CommitLog createCommitLog(String tableSpace, String tablespaceName, String localNodeId) {
return new CommitLog() {
AtomicLong offset = new AtomicLong(-1);
@Override
public CommitLogResult log(LogEntry entry, boolean synch) throws LogNotAvailableException {
if (isHasListeners()) {
synch = true;
}
if (testSerialize) {
// NOOP, but trigger serialization subsystem
try {
entry.serialize(ExtendedDataOutputStream.NULL);
} catch (IOException err) {
throw new LogNotAvailableException(err);
}
}
LogSequenceNumber logPos = new LogSequenceNumber(1, offset.incrementAndGet());
notifyListeners(logPos, entry);
return new CommitLogResult(logPos, !synch, synch);
}
@Override
public LogSequenceNumber getLastSequenceNumber() {
return new LogSequenceNumber(1, offset.get());
}
private volatile boolean closed;
@Override
public void close() throws LogNotAvailableException {
closed = true;
}
@Override
public boolean isFailed() {
return false;
}
@Override
public boolean isClosed() {
return closed;
}
@Override
public void recovery(LogSequenceNumber snapshotSequenceNumber, BiConsumer<LogSequenceNumber, LogEntry> consumer, boolean fencing) throws LogNotAvailableException {
}
@Override
public void dropOldLedgers(LogSequenceNumber lastCheckPointSequenceNumber) throws LogNotAvailableException {
}
@Override
public void startWriting(int expectedReplicaCount) throws LogNotAvailableException {
}
@Override
public void clear() throws LogNotAvailableException {
}
};
}
use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class MemoryDataStorageManager method getLatestTableStatus.
@Override
public TableStatus getLatestTableStatus(String tableSpace, String tableName) throws DataStorageManagerException {
LogSequenceNumber max = null;
String prefix = tableSpace + "." + tableName + "_";
for (String status : tableStatuses.keySet()) {
if (status.startsWith(prefix)) {
final LogSequenceNumber log = evaluateLogSequenceNumber(prefix);
if (log != null) {
if (max == null || log.after(max)) {
max = log;
}
}
}
}
TableStatus latestStatus;
if (max == null) {
latestStatus = TableStatus.buildTableStatusForNewCreatedTable(tableName);
} else {
byte[] data = tableStatuses.get(checkpointName(tableSpace, tableName, max));
if (data == null) {
latestStatus = TableStatus.buildTableStatusForNewCreatedTable(tableName);
} else {
try {
try (InputStream input = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
latestStatus = TableStatus.deserialize(dataIn);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
}
return latestStatus;
}
Aggregations