Search in sources :

Example 71 with LogSequenceNumber

use of herddb.log.LogSequenceNumber 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 72 with LogSequenceNumber

use of herddb.log.LogSequenceNumber 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)

Example 73 with LogSequenceNumber

use of herddb.log.LogSequenceNumber in project herddb by diennea.

the class TableSpaceRestoreSourceFromFile method nextTransactionLogChunk.

@Override
public List<KeyValue> nextTransactionLogChunk() throws DataStorageManagerException {
    try {
        int numRecords = in.readVInt();
        listener.log("nexttxchunk", "sending " + numRecords + " tx log entries", Collections.singletonMap("count", numRecords));
        List<KeyValue> records = new ArrayList<>(numRecords);
        for (int i = 0; i < numRecords; i++) {
            long ledgerId = in.readVLong();
            long offset = in.readVLong();
            Bytes value = in.readBytes();
            records.add(new KeyValue(Bytes.from_array(new LogSequenceNumber(ledgerId, offset).serialize()), value));
        }
        return records;
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : Bytes(herddb.utils.Bytes) DataStorageManagerException(herddb.storage.DataStorageManagerException) KeyValue(herddb.utils.KeyValue) ArrayList(java.util.ArrayList) LogSequenceNumber(herddb.log.LogSequenceNumber) IOException(java.io.IOException)

Example 74 with LogSequenceNumber

use of herddb.log.LogSequenceNumber in project herddb by diennea.

the class TableSpaceRestoreSourceFromFile method nextTable.

@Override
public DumpedTableMetadata nextTable() throws DataStorageManagerException {
    currentTableSize = 0;
    try {
        long dumpLedgerId = in.readLong();
        long dumpOffset = in.readLong();
        byte[] table = in.readArray();
        int numIndexes = in.readInt();
        List<byte[]> indexesData = new ArrayList<>();
        for (int i = 0; i < numIndexes; i++) {
            byte[] index = in.readArray();
            indexesData.add(index);
        }
        List<Index> indexes = indexesData.stream().map(Index::deserialize).collect(Collectors.toList());
        Table tableMetadata = Table.deserialize(table);
        Map<String, Object> data = new HashMap<>();
        data.put("table", tableMetadata.name);
        data.put("dumpLedgerId", dumpLedgerId);
        data.put("dumpOffset", dumpOffset);
        data.put("indexes", indexesData.size());
        listener.log("starttable", "starting table " + tableMetadata.name, data);
        return new DumpedTableMetadata(tableMetadata, new LogSequenceNumber(dumpLedgerId, dumpOffset), indexes);
    } catch (EOFException end) {
        return null;
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) Table(herddb.model.Table) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LogSequenceNumber(herddb.log.LogSequenceNumber) Index(herddb.model.Index) IOException(java.io.IOException) EOFException(java.io.EOFException)

Aggregations

LogSequenceNumber (herddb.log.LogSequenceNumber)74 DataStorageManagerException (herddb.storage.DataStorageManagerException)35 IOException (java.io.IOException)34 ArrayList (java.util.ArrayList)30 Table (herddb.model.Table)21 Test (org.junit.Test)21 LogEntry (herddb.log.LogEntry)20 PostCheckpointAction (herddb.core.PostCheckpointAction)13 CommitLog (herddb.log.CommitLog)13 Index (herddb.model.Index)13 ExtendedDataOutputStream (herddb.utils.ExtendedDataOutputStream)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 CreateTableStatement (herddb.model.commands.CreateTableStatement)10 Path (java.nio.file.Path)10 HashMap (java.util.HashMap)10 Transaction (herddb.model.Transaction)9 InsertStatement (herddb.model.commands.InsertStatement)9 ServerConfiguration (herddb.server.ServerConfiguration)9 ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)9 SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)9