Search in sources :

Example 1 with TableSpaceAlreadyExistsException

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

the class AlterTablespaceSQLTest method createAlterTableSpace.

@Test
public void createAlterTableSpace() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager(nodeId, new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
        execute(manager, "EXECUTE CREATETABLESPACE 'ttt'", Collections.emptyList());
        execute(manager, "CREATE TABLESPACE 'ttt2','leader:" + nodeId + "'", Collections.emptyList());
        try {
            execute(manager, "EXECUTE CREATETABLESPACE 'ttt2','leader:othernode'", Collections.emptyList());
            fail();
        } catch (TableSpaceAlreadyExistsException err) {
        }
        execute(manager, "EXECUTE CREATETABLESPACE 'ttt3','leader:othernode'", Collections.emptyList());
        execute(manager, "EXECUTE CREATETABLESPACE 'ttt4','leader:othernode','replica:" + nodeId + ",othernode'", Collections.emptyList());
        execute(manager, "EXECUTE ALTERTABLESPACE 'ttt3','replica:" + nodeId + ",othernode','expectedReplicaCount:2'", Collections.emptyList());
        execute(manager, "EXECUTE ALTERTABLESPACE 'ttt3','leader:othernode'", Collections.emptyList());
        execute(manager, "EXECUTE ALTERTABLESPACE 'ttt3','expectedReplicaCount:12'", Collections.emptyList());
        TableSpace ttt3 = manager.getMetadataStorageManager().describeTableSpace("ttt3");
        assertEquals("othernode", ttt3.leaderId);
        assertEquals(12, ttt3.expectedReplicaCount);
        assertTrue(ttt3.replicas.contains("othernode"));
        assertTrue(ttt3.replicas.contains(nodeId));
        try (DataScanner scan = scan(manager, "SELECT * FROM SYSTABLESPACES", Collections.emptyList())) {
            List<DataAccessor> tuples = scan.consume();
            assertEquals(5, tuples.size());
            for (DataAccessor t : tuples) {
                System.out.println("tablespace: " + t.toMap());
                assertNotNull(t.get("expectedreplicacount"));
                assertNotNull(t.get("tablespace_name"));
                assertNotNull(t.get("replica"));
                assertNotNull(t.get("leader"));
            }
        }
        try (DataScanner scan = scan(manager, "SELECT expectedreplicacount FROM SYSTABLESPACES where tablespace_name='ttt3'", Collections.emptyList())) {
            List<DataAccessor> tuples = scan.consume();
            assertEquals(1, tuples.size());
            for (DataAccessor t : tuples) {
                System.out.println("tablespace: " + t.toMap());
                assertEquals(12, t.get("expectedreplicacount"));
            }
        }
    }
}
Also used : TableSpaceAlreadyExistsException(herddb.model.TableSpaceAlreadyExistsException) TableSpace(herddb.model.TableSpace) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 2 with TableSpaceAlreadyExistsException

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

the class AlterTablespaceSQLTest method escapeTableSpaceName.

@Test
public void escapeTableSpaceName() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager(nodeId, new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
        execute(manager, "CREATE TABLESPACE `default`,'leader:" + nodeId + "'", Collections.emptyList());
        try {
            execute(manager, "EXECUTE CREATETABLESPACE `default`,'leader:othernode'", Collections.emptyList());
            fail();
        } catch (TableSpaceAlreadyExistsException err) {
        }
        execute(manager, "EXECUTE ALTERTABLESPACE `default`,`replica:" + nodeId + ",othernode`,'expectedReplicaCount:2'", Collections.emptyList());
        execute(manager, "EXECUTE ALTERTABLESPACE 'default','leader:othernode'", Collections.emptyList());
        execute(manager, "EXECUTE ALTERTABLESPACE 'default','expectedReplicaCount:12'", Collections.emptyList());
        TableSpace ttt3 = manager.getMetadataStorageManager().describeTableSpace("default");
        assertEquals("othernode", ttt3.leaderId);
        assertEquals(12, ttt3.expectedReplicaCount);
        assertTrue(ttt3.replicas.contains("othernode"));
        assertTrue(ttt3.replicas.contains(nodeId));
        try (DataScanner scan = scan(manager, "SELECT * FROM SYSTABLESPACES", Collections.emptyList())) {
            List<DataAccessor> tuples = scan.consume();
            assertEquals(2, tuples.size());
            for (DataAccessor t : tuples) {
                System.out.println("tablespace: " + t.toMap());
                assertNotNull(t.get("expectedreplicacount"));
                assertNotNull(t.get("tablespace_name"));
                assertNotNull(t.get("replica"));
                assertNotNull(t.get("leader"));
            }
        }
        try (DataScanner scan = scan(manager, "SELECT expectedreplicacount FROM SYSTABLESPACES where tablespace_name='default'", Collections.emptyList())) {
            List<DataAccessor> tuples = scan.consume();
            assertEquals(1, tuples.size());
            for (DataAccessor t : tuples) {
                System.out.println("tablespace: " + t.toMap());
                assertEquals(12, t.get("expectedreplicacount"));
            }
        }
    }
}
Also used : TableSpaceAlreadyExistsException(herddb.model.TableSpaceAlreadyExistsException) TableSpace(herddb.model.TableSpace) DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 3 with TableSpaceAlreadyExistsException

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

the class ZookeeperMetadataStorageManager method ensureDefaultTableSpace.

@Override
public void ensureDefaultTableSpace(String localNodeId) throws MetadataStorageManagerException {
    try {
        TableSpaceList list = listTablesSpaces();
        if (!list.tableSpaces.contains(TableSpace.DEFAULT)) {
            TableSpace tableSpace = TableSpace.builder().leader(localNodeId).replica(localNodeId).expectedReplicaCount(1).maxLeaderInactivityTime(0).name(TableSpace.DEFAULT).build();
            createTableSpaceNode(tableSpace);
        }
    } catch (TableSpaceAlreadyExistsException err) {
    // not a problem
    } catch (InterruptedException | KeeperException | IOException err) {
        handleSessionExpiredError(err);
        throw new MetadataStorageManagerException(err);
    }
}
Also used : TableSpaceAlreadyExistsException(herddb.model.TableSpaceAlreadyExistsException) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) TableSpace(herddb.model.TableSpace) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

TableSpace (herddb.model.TableSpace)3 TableSpaceAlreadyExistsException (herddb.model.TableSpaceAlreadyExistsException)3 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)2 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)2 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)2 DataScanner (herddb.model.DataScanner)2 DataAccessor (herddb.utils.DataAccessor)2 Test (org.junit.Test)2 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 IOException (java.io.IOException)1 KeeperException (org.apache.zookeeper.KeeperException)1