use of herddb.file.FileCommitLog in project herddb by diennea.
the class SimpleRecoveryTest method ignoreInsertWithMissingTransactionOnRecovery.
@Test
public void ignoreInsertWithMissingTransactionOnRecovery() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Bytes key = Bytes.from_int(1234);
Bytes value = Bytes.from_long(8888);
Path tmoDir = folder.newFolder("tmoDir").toPath();
String nodeId = "localhost";
String tablespaceUUID = null;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
CreateTableStatement st2 = new CreateTableStatement(table);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.checkpoint();
tablespaceUUID = manager.getTableSpaceManager("tblspace1").getTableSpaceUUID();
}
try (FileCommitLogManager commitLogManager = new FileCommitLogManager(logsPath)) {
commitLogManager.start();
try (FileCommitLog log = commitLogManager.createCommitLog(tablespaceUUID, "tblspace1", nodeId)) {
log.recovery(LogSequenceNumber.START_OF_TIME, (n, e) -> {
}, false);
log.startWriting(1);
/* Insert an entry for a unknown transaction id */
LogEntry entry = new LogEntry(System.currentTimeMillis(), LogEntryType.INSERT, 1024, "t1", key, value);
log.log(entry, true).getLogSequenceNumber();
}
}
final boolean original = TableManager.ignoreMissingTransactionsOnRecovery;
TableManager.ignoreMissingTransactionsOnRecovery = true;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
manager.start();
manager.waitForTablespace("tblspace1", 10000);
{
GetStatement get = new GetStatement("tblspace1", "t1", key, null, false);
GetResult result = manager.get(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
} finally {
TableManager.ignoreMissingTransactionsOnRecovery = original;
}
}
use of herddb.file.FileCommitLog in project herddb by diennea.
the class SimpleRecoveryTest method ignoreUpdateWithMissingTransactionOnRecovery.
@Test
public void ignoreUpdateWithMissingTransactionOnRecovery() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Bytes key = Bytes.from_int(1234);
Bytes value = Bytes.from_long(8888);
Bytes value2 = Bytes.from_long(9999);
Path tmoDir = folder.newFolder("tmoDir").toPath();
String nodeId = "localhost";
String tablespaceUUID = null;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
CreateTableStatement st2 = new CreateTableStatement(table);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.checkpoint();
InsertStatement insert = new InsertStatement("tblspace1", "t1", new Record(key, value));
assertEquals(1, manager.executeUpdate(insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
tablespaceUUID = manager.getTableSpaceManager("tblspace1").getTableSpaceUUID();
}
try (FileCommitLogManager commitLogManager = new FileCommitLogManager(logsPath)) {
commitLogManager.start();
try (FileCommitLog log = commitLogManager.createCommitLog(tablespaceUUID, "tblspace1", nodeId)) {
log.recovery(LogSequenceNumber.START_OF_TIME, (n, e) -> {
}, false);
log.startWriting(1);
/* Insert an entry for a unknown transaction id */
LogEntry entry = new LogEntry(System.currentTimeMillis(), LogEntryType.UPDATE, 1024, "t1", key, value2);
log.log(entry, true).getLogSequenceNumber();
}
}
final boolean original = TableManager.ignoreMissingTransactionsOnRecovery;
TableManager.ignoreMissingTransactionsOnRecovery = true;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
manager.start();
manager.waitForTablespace("tblspace1", 10000);
{
GetStatement get = new GetStatement("tblspace1", "t1", key, null, false);
GetResult result = manager.get(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
assertEquals(key, result.getRecord().key);
assertEquals(value, result.getRecord().value);
}
} finally {
TableManager.ignoreMissingTransactionsOnRecovery = original;
}
}
use of herddb.file.FileCommitLog in project herddb by diennea.
the class SimpleRecoveryTest method ignoreDeleteWithMissingTransactionOnRecovery.
@Test
public void ignoreDeleteWithMissingTransactionOnRecovery() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Bytes key = Bytes.from_int(1234);
Bytes value = Bytes.from_long(8888);
Path tmoDir = folder.newFolder("tmoDir").toPath();
String nodeId = "localhost";
String tablespaceUUID = null;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
CreateTableStatement st2 = new CreateTableStatement(table);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.checkpoint();
InsertStatement insert = new InsertStatement("tblspace1", "t1", new Record(key, value));
assertEquals(1, manager.executeUpdate(insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
tablespaceUUID = manager.getTableSpaceManager("tblspace1").getTableSpaceUUID();
}
try (FileCommitLogManager commitLogManager = new FileCommitLogManager(logsPath)) {
commitLogManager.start();
try (FileCommitLog log = commitLogManager.createCommitLog(tablespaceUUID, "tblspace1", nodeId)) {
log.recovery(LogSequenceNumber.START_OF_TIME, (n, e) -> {
}, false);
log.startWriting(1);
/* Insert an entry for a unknown transaction id */
LogEntry entry = new LogEntry(System.currentTimeMillis(), LogEntryType.DELETE, 1024, "t1", key, null);
log.log(entry, true).getLogSequenceNumber();
}
}
final boolean original = TableManager.ignoreMissingTransactionsOnRecovery;
TableManager.ignoreMissingTransactionsOnRecovery = true;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmoDir, null)) {
manager.start();
manager.waitForTablespace("tblspace1", 10000);
{
GetStatement get = new GetStatement("tblspace1", "t1", key, null, false);
GetResult result = manager.get(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
} finally {
TableManager.ignoreMissingTransactionsOnRecovery = original;
}
}
Aggregations