Search in sources :

Example 1 with TableAlreadyExistsException

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

the class TableSpaceManager method createTable.

private StatementExecutionResult createTable(CreateTableStatement statement, Transaction transaction) throws StatementExecutionException {
    generalLock.writeLock().lock();
    try {
        if (tables.containsKey(statement.getTableDefinition().name)) {
            throw new TableAlreadyExistsException(statement.getTableDefinition().name);
        }
        for (Index additionalIndex : statement.getAdditionalIndexes()) {
            if (indexes.containsKey(additionalIndex.name)) {
                throw new IndexAlreadyExistsException(additionalIndex.name);
            }
        }
        LogEntry entry = LogEntryFactory.createTable(statement.getTableDefinition(), transaction);
        CommitLogResult pos = log.log(entry, entry.transactionId <= 0);
        apply(pos, entry, false);
        for (Index additionalIndex : statement.getAdditionalIndexes()) {
            LogEntry index_entry = LogEntryFactory.createIndex(additionalIndex, transaction);
            CommitLogResult index_pos = log.log(index_entry, index_entry.transactionId <= 0);
            apply(index_pos, index_entry, false);
        }
        return new DDLStatementExecutionResult(entry.transactionId);
    } catch (DataStorageManagerException | LogNotAvailableException err) {
        throw new StatementExecutionException(err);
    } finally {
        generalLock.writeLock().unlock();
    }
}
Also used : TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) Index(herddb.model.Index) CommitLogResult(herddb.log.CommitLogResult) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 2 with TableAlreadyExistsException

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

the class TableSpaceManager method beginRestoreTable.

public void beginRestoreTable(byte[] tableDef, LogSequenceNumber dumpLogSequenceNumber) {
    Table table = Table.deserialize(tableDef);
    generalLock.writeLock().lock();
    try {
        if (tables.containsKey(table.name)) {
            throw new TableAlreadyExistsException(table.name);
        }
        bootTable(table, 0, dumpLogSequenceNumber);
    } finally {
        generalLock.writeLock().unlock();
    }
}
Also used : TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) Table(herddb.model.Table)

Example 3 with TableAlreadyExistsException

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

the class SimpleRecoveryTest method createTable1_aftercheckpoint.

@Test
public void createTable1_aftercheckpoint() 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();
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), 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();
    }
    try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmoDir, null)) {
        manager.start();
        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);
        try {
            manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            fail();
        } catch (TableAlreadyExistsException alreadyExists) {
        }
    }
}
Also used : Path(java.nio.file.Path) FileCommitLogManager(herddb.file.FileCommitLogManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) Table(herddb.model.Table) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) FileDataStorageManager(herddb.file.FileDataStorageManager) Test(org.junit.Test)

Example 4 with TableAlreadyExistsException

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

the class SimpleRecoveryTest method createTable1_nocheckpoint.

@Test
public void createTable1_nocheckpoint() 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();
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), 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);
    }
    try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath, 64 * 1024 * 1024), tmoDir, null)) {
        manager.start();
        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);
        try {
            manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            fail();
        } catch (TableAlreadyExistsException alreadyExists) {
        }
    }
}
Also used : Path(java.nio.file.Path) FileCommitLogManager(herddb.file.FileCommitLogManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) Table(herddb.model.Table) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) FileDataStorageManager(herddb.file.FileDataStorageManager) Test(org.junit.Test)

Aggregations

TableAlreadyExistsException (herddb.model.TableAlreadyExistsException)4 Table (herddb.model.Table)3 FileCommitLogManager (herddb.file.FileCommitLogManager)2 FileDataStorageManager (herddb.file.FileDataStorageManager)2 FileMetadataStorageManager (herddb.file.FileMetadataStorageManager)2 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)2 CreateTableStatement (herddb.model.commands.CreateTableStatement)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 DumpedLogEntry (herddb.backup.DumpedLogEntry)1 CommitLogResult (herddb.log.CommitLogResult)1 LogEntry (herddb.log.LogEntry)1 LogNotAvailableException (herddb.log.LogNotAvailableException)1 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)1 Index (herddb.model.Index)1 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)1 StatementExecutionException (herddb.model.StatementExecutionException)1 DataStorageManagerException (herddb.storage.DataStorageManagerException)1