Search in sources :

Example 41 with TransactionResult

use of herddb.model.TransactionResult in project herddb by diennea.

the class RestartTestBase method recoverTableTruncatedNoCheckpoint.

@Test
public void recoverTableTruncatedNoCheckpoint() throws Exception {
    Path dataPath = folder.newFolder("data").toPath();
    Path logsPath = folder.newFolder("logs").toPath();
    Path metadataPath = folder.newFolder("metadata").toPath();
    Path tmoDir = folder.newFolder("tmoDir").toPath();
    Bytes key = Bytes.from_string("k1");
    String nodeId = "localhost";
    try (DBManager manager = buildDBManager(nodeId, metadataPath, dataPath, logsPath, tmoDir)) {
        manager.start();
        CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertTrue(manager.waitForTablespace("tblspace1", 10000));
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        long tx = ((TransactionResult) manager.executeStatement(new BeginTransactionStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION)).getTransactionId();
        manager.executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key, key)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.executeStatement(new CommitTransactionStatement("tblspace1", tx), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        GetResult result = manager.get(new GetStatement("tblspace1", "t1", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertTrue(result.found());
        manager.checkpoint();
        manager.executeStatement(new TruncateTableStatement("tblspace1", table.name), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        GetResult result2 = manager.get(new GetStatement("tblspace1", "t1", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertFalse(result2.found());
    // no checkpoint
    }
    try (DBManager manager = buildDBManager(nodeId, metadataPath, dataPath, logsPath, tmoDir)) {
        manager.start();
        assertTrue(manager.waitForBootOfLocalTablespaces(10000));
        GetResult result = manager.get(new GetStatement("tblspace1", "t1", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertFalse(result.found());
    }
}
Also used : Path(java.nio.file.Path) TruncateTableStatement(herddb.model.commands.TruncateTableStatement) TransactionResult(herddb.model.TransactionResult) Table(herddb.model.Table) GetResult(herddb.model.GetResult) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) CreateTableStatement(herddb.model.commands.CreateTableStatement) InsertStatement(herddb.model.commands.InsertStatement) Bytes(herddb.utils.Bytes) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) BeginTransactionStatement(herddb.model.commands.BeginTransactionStatement) Record(herddb.model.Record) Test(org.junit.Test)

Example 42 with TransactionResult

use of herddb.model.TransactionResult in project herddb by diennea.

the class RestartTestBase method recoverTableTruncatedWithCheckpoint.

@Test
public void recoverTableTruncatedWithCheckpoint() throws Exception {
    Path dataPath = folder.newFolder("data").toPath();
    Path logsPath = folder.newFolder("logs").toPath();
    Path metadataPath = folder.newFolder("metadata").toPath();
    Path tmoDir = folder.newFolder("tmoDir").toPath();
    Bytes key = Bytes.from_string("k1");
    String nodeId = "localhost";
    try (DBManager manager = buildDBManager(nodeId, metadataPath, dataPath, logsPath, tmoDir)) {
        manager.start();
        CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertTrue(manager.waitForTablespace("tblspace1", 10000));
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        long tx = ((TransactionResult) manager.executeStatement(new BeginTransactionStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION)).getTransactionId();
        manager.executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key, key)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.executeStatement(new CommitTransactionStatement("tblspace1", tx), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        GetResult result = manager.get(new GetStatement("tblspace1", "t1", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertTrue(result.found());
        manager.checkpoint();
        manager.executeStatement(new TruncateTableStatement("tblspace1", table.name), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        GetResult result2 = manager.get(new GetStatement("tblspace1", "t1", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertFalse(result2.found());
        manager.checkpoint();
    }
    try (DBManager manager = buildDBManager(nodeId, metadataPath, dataPath, logsPath, tmoDir)) {
        manager.start();
        assertTrue(manager.waitForBootOfLocalTablespaces(10000));
        GetResult result = manager.get(new GetStatement("tblspace1", "t1", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertFalse(result.found());
    }
}
Also used : Path(java.nio.file.Path) TruncateTableStatement(herddb.model.commands.TruncateTableStatement) TransactionResult(herddb.model.TransactionResult) Table(herddb.model.Table) GetResult(herddb.model.GetResult) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) CreateTableStatement(herddb.model.commands.CreateTableStatement) InsertStatement(herddb.model.commands.InsertStatement) Bytes(herddb.utils.Bytes) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) BeginTransactionStatement(herddb.model.commands.BeginTransactionStatement) Record(herddb.model.Record) Test(org.junit.Test)

Example 43 with TransactionResult

use of herddb.model.TransactionResult in project herddb by diennea.

the class CleanupOnCheckPointTest method cleanupTransactionsFile.

@Test
public void cleanupTransactionsFile() throws Exception {
    Path dataPath = folder.newFolder("data").toPath();
    Path logsPath = folder.newFolder("logs").toPath();
    Path metadataPath = folder.newFolder("metadata").toPath();
    Path tmoDir = folder.newFolder("tmoDir").toPath();
    Bytes key = Bytes.from_string("k1");
    String nodeId = "localhost";
    FileDataStorageManager storageManager = new FileDataStorageManager(dataPath);
    try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), storageManager, 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();
        manager.executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        long tx = ((TransactionResult) manager.executeStatement(new BeginTransactionStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION)).getTransactionId();
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key, key)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.checkpoint();
        assertEquals(new LogSequenceNumber(1, 2), manager.getTableSpaceManager("tblspace1").getLog().getLastSequenceNumber());
        manager.executeStatement(new CommitTransactionStatement("tblspace1", tx), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertEquals(new LogSequenceNumber(1, 3), manager.getTableSpaceManager("tblspace1").getLog().getLastSequenceNumber());
        String uuid = manager.getTableSpaceManager("tblspace1").getTableSpaceUUID();
        Path path = dataPath.resolve(uuid + ".tablespace");
        Files.list(path).forEach(p -> {
            System.out.println("path:" + p);
        });
        assertTrue(Files.isRegularFile(path.resolve("transactions.1.2.tx")));
        assertTrue(Files.isRegularFile(path.resolve("tables.1.2.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("indexes.1.2.tablesmetadata")));
        assertFalse(Files.isRegularFile(path.resolve("transactions.1.3.tx")));
        assertFalse(Files.isRegularFile(path.resolve("tables.1.3.tablesmetadata")));
        assertFalse(Files.isRegularFile(path.resolve("indexes.1.3.tablesmetadata")));
        manager.checkpoint();
        assertFalse(Files.isRegularFile(path.resolve("transactions.1.2.tx")));
        assertFalse(Files.isRegularFile(path.resolve("tables.1.2.tablesmetadata")));
        assertFalse(Files.isRegularFile(path.resolve("indexes.1.2.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("transactions.1.3.tx")));
        assertTrue(Files.isRegularFile(path.resolve("tables.1.3.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("indexes.1.3.tablesmetadata")));
    }
}
Also used : Path(java.nio.file.Path) TransactionResult(herddb.model.TransactionResult) Table(herddb.model.Table) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) CreateTableStatement(herddb.model.commands.CreateTableStatement) LogSequenceNumber(herddb.log.LogSequenceNumber) InsertStatement(herddb.model.commands.InsertStatement) Bytes(herddb.utils.Bytes) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) TransactionContext(herddb.model.TransactionContext) BeginTransactionStatement(herddb.model.commands.BeginTransactionStatement) Record(herddb.model.Record) Test(org.junit.Test)

Example 44 with TransactionResult

use of herddb.model.TransactionResult in project herddb by diennea.

the class CleanupOnCheckPointTest method cleanupTransactionsFileWithUnCommittedTable.

@Test
public void cleanupTransactionsFileWithUnCommittedTable() throws Exception {
    Path dataPath = folder.newFolder("data").toPath();
    Path logsPath = folder.newFolder("logs").toPath();
    Path metadataPath = folder.newFolder("metadata").toPath();
    Path tmoDir = folder.newFolder("tmoDir").toPath();
    Bytes key = Bytes.from_string("k1");
    String nodeId = "localhost";
    FileDataStorageManager storageManager = new FileDataStorageManager(dataPath);
    try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), storageManager, 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();
        long tx = ((TransactionResult) manager.executeStatement(new BeginTransactionStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION)).getTransactionId();
        manager.executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key, key)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        manager.checkpoint();
        assertEquals(new LogSequenceNumber(1, 2), manager.getTableSpaceManager("tblspace1").getLog().getLastSequenceNumber());
        manager.executeStatement(new CommitTransactionStatement("tblspace1", tx), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertEquals(new LogSequenceNumber(1, 3), manager.getTableSpaceManager("tblspace1").getLog().getLastSequenceNumber());
        String uuid = manager.getTableSpaceManager("tblspace1").getTableSpaceUUID();
        Path path = dataPath.resolve(uuid + ".tablespace");
        Files.list(path).forEach(p -> {
            System.out.println("path:" + p);
        });
        assertTrue(Files.isRegularFile(path.resolve("transactions.1.2.tx")));
        assertTrue(Files.isRegularFile(path.resolve("tables.1.2.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("indexes.1.2.tablesmetadata")));
        assertFalse(Files.isRegularFile(path.resolve("transactions.1.3.tx")));
        // il commit della create table fa creare i file che contengono la nuova tabella
        assertTrue(Files.isRegularFile(path.resolve("tables.1.3.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("indexes.1.3.tablesmetadata")));
        manager.checkpoint();
        assertFalse(Files.isRegularFile(path.resolve("transactions.1.2.tx")));
        assertFalse(Files.isRegularFile(path.resolve("tables.1.2.tablesmetadata")));
        assertFalse(Files.isRegularFile(path.resolve("indexes.1.2.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("transactions.1.3.tx")));
        assertTrue(Files.isRegularFile(path.resolve("tables.1.3.tablesmetadata")));
        assertTrue(Files.isRegularFile(path.resolve("indexes.1.3.tablesmetadata")));
    }
}
Also used : Path(java.nio.file.Path) TransactionResult(herddb.model.TransactionResult) Table(herddb.model.Table) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) CreateTableStatement(herddb.model.commands.CreateTableStatement) LogSequenceNumber(herddb.log.LogSequenceNumber) InsertStatement(herddb.model.commands.InsertStatement) Bytes(herddb.utils.Bytes) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) TransactionContext(herddb.model.TransactionContext) BeginTransactionStatement(herddb.model.commands.BeginTransactionStatement) Record(herddb.model.Record) Test(org.junit.Test)

Aggregations

TransactionResult (herddb.model.TransactionResult)44 TransactionContext (herddb.model.TransactionContext)36 Test (org.junit.Test)35 BeginTransactionStatement (herddb.model.commands.BeginTransactionStatement)33 Table (herddb.model.Table)32 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)32 Record (herddb.model.Record)31 GetResult (herddb.model.GetResult)30 CreateTableStatement (herddb.model.commands.CreateTableStatement)30 Bytes (herddb.utils.Bytes)30 InsertStatement (herddb.model.commands.InsertStatement)29 Path (java.nio.file.Path)29 CommitTransactionStatement (herddb.model.commands.CommitTransactionStatement)28 GetStatement (herddb.model.commands.GetStatement)28 FileCommitLogManager (herddb.file.FileCommitLogManager)17 FileDataStorageManager (herddb.file.FileDataStorageManager)17 FileMetadataStorageManager (herddb.file.FileMetadataStorageManager)17 UpdateStatement (herddb.model.commands.UpdateStatement)14 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)9 StatementExecutionException (herddb.model.StatementExecutionException)9