Search in sources :

Example 71 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class DropTablespaceTest method testCleanPolicyOnDropTable.

@Test
public void testCleanPolicyOnDropTable() throws Exception {
    String nodeId = "localhost";
    ServerConfiguration serverConfig = newServerConfigurationWithAutoPort();
    // very low memory
    serverConfig.set(ServerConfiguration.PROPERTY_MAX_DATA_MEMORY, 2_000_000);
    serverConfig.set(ServerConfiguration.PROPERTY_MAX_PK_MEMORY, 2_000_000);
    Path dataPath = folder.newFolder("data").toPath();
    Path logsPath = folder.newFolder("logs").toPath();
    Path metadataPath = folder.newFolder("metadata").toPath();
    Path tmoDir = folder.newFolder("tmoDir").toPath();
    try (DBManager manager = new DBManager(nodeId, new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new MemoryCommitLogManager(false), tmoDir, null, serverConfig, NullStatsLogger.INSTANCE)) {
        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);
        execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        execute(manager, "CREATE TABLE tblspace1.tsql2 (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        for (int i = 0; i < 10000; i++) {
            execute(manager, "INSERT INTO tblspace1.tsql (k1 ,n1 ,s1 ) values(?,?,?)", Arrays.asList(i, i, "jkhdskfhjdskfhskdjfhksdhfkshfkjhsdlkhflksjhfklshdkljhsdlkf" + "ksdjhfkdsflksdjhfklsdhjflksdhjflksdhjfklsdhjfklsdjhfsd" + "skjhsdlkfjhdslkfjhsdlkfjhsdlkfhjsklhdfkldshjflksjhdflkhsdf" + "jsdklfjhdslkfjhsdlkfhjslkjhfdlksjhdfklshjdflkhslkfdhslkfhslkfhslkdjfhklsdhjflkhsfd" + "jklsdhfksdjhflksdjhflksjhfdlkjhsdlfkhjslkfjhslkdfjhklsdhjfklhsdff" + "lksdjhflkshdjflkhjsdlkfjhsldkfjhslkfdfoo" + i));
        }
        // drop the table, any reference to the pages should be discarded
        execute(manager, "DROP TABLE tblspace1.tsql", Collections.emptyList());
        // https://github.com/diennea/herddb/issues/434
        for (int i = 0; i < 3000; i++) {
            System.out.println("after " + i);
            execute(manager, "INSERT INTO tblspace1.tsql2 (k1 ,n1 ,s1 ) values(?,?,?)", Arrays.asList(i, i, "jkhdskfhjdskfhskdjfhksdhfkshfkjhsdlkhflksjhfklshdkljhsdlkf" + "ksdjhfkdsflksdjhfklsdhjflksdhjflksdhjfklsdhjfklsdjhfsd" + "skjhsdlkfjhdslkfjhsdlkfjhsdlkfhjsklhdfkldshjflksjhdflkhsdf" + "jsdklfjhdslkfjhsdlkfhjslkjhfdlksjhdfklshjdflkhslkfdhslkfhslkfhslkdjfhklsdhjflkhsfd" + "jklsdhfksdjhflksdjhflksjhfdlkjhsdlfkhjslkfjhslkdfjhklsdhjfklhsdff" + "lksdjhflkshdjflkhjsdlkfjhsldkfjhslkfdfoo" + i));
        }
    }
}
Also used : Path(java.nio.file.Path) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) ServerConfiguration(herddb.server.ServerConfiguration) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) FileDataStorageManager(herddb.file.FileDataStorageManager) Test(org.junit.Test)

Example 72 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class BookKeeperCommitLogTest method testSimpleFence.

@Test
public void testSimpleFence() throws Exception {
    final String tableSpaceUUID = UUID.randomUUID().toString();
    final String name = TableSpace.DEFAULT;
    final String nodeid = "nodeid";
    ServerConfiguration serverConfiguration = newServerConfigurationWithAutoPort();
    try (ZookeeperMetadataStorageManager man = new ZookeeperMetadataStorageManager(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath());
        BookkeeperCommitLogManager logManager = new BookkeeperCommitLogManager(man, serverConfiguration, NullStatsLogger.INSTANCE)) {
        man.start();
        logManager.start();
        LogSequenceNumber lsn1;
        LogSequenceNumber lsn2;
        LogSequenceNumber lsn3;
        try (BookkeeperCommitLog writer = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
            writer.startWriting(1);
            lsn1 = writer.log(LogEntryFactory.beginTransaction(1), true).getLogSequenceNumber();
            lsn2 = writer.log(LogEntryFactory.beginTransaction(2), true).getLogSequenceNumber();
            // a new leader starts, from START_OF_TIME
            try (BookkeeperCommitLog writer2 = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
                writer2.recovery(LogSequenceNumber.START_OF_TIME, (a, b) -> {
                }, true);
                writer2.startWriting(1);
                lsn3 = writer2.log(LogEntryFactory.beginTransaction(3), true).getLogSequenceNumber();
            }
            TestUtils.assertThrows(LogNotAvailableException.class, () -> FutureUtils.result(writer.log(LogEntryFactory.beginTransaction(3), true).logSequenceNumber));
            assertTrue(writer.isFailed());
            assertTrue(lsn1.after(LogSequenceNumber.START_OF_TIME));
            assertTrue(lsn2.after(lsn1));
            // written by second writer
            assertTrue(lsn3.after(lsn2));
        }
        try (BookkeeperCommitLog reader = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
            List<Map.Entry<LogSequenceNumber, LogEntry>> list = new ArrayList<>();
            reader.recovery(LogSequenceNumber.START_OF_TIME, (lsn, entry) -> {
                if (entry.type != LogEntryType.NOOP) {
                    list.add(new AbstractMap.SimpleImmutableEntry<>(lsn, entry));
                }
            }, false);
            assertEquals(3, list.size());
            assertEquals(lsn1, list.get(0).getKey());
            assertEquals(lsn2, list.get(1).getKey());
            assertEquals(lsn3, list.get(2).getKey());
        }
    }
}
Also used : AbstractMap(java.util.AbstractMap) LogEntry(herddb.log.LogEntry) ZookeeperMetadataStorageManager(herddb.cluster.ZookeeperMetadataStorageManager) ServerConfiguration(herddb.server.ServerConfiguration) ArrayList(java.util.ArrayList) LogSequenceNumber(herddb.log.LogSequenceNumber) BookkeeperCommitLogManager(herddb.cluster.BookkeeperCommitLogManager) BookkeeperCommitLog(herddb.cluster.BookkeeperCommitLog) Test(org.junit.Test)

Example 73 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class BookKeeperCommitLogTest method testWriteAsync.

@Test
public void testWriteAsync() throws Exception {
    final String tableSpaceUUID = UUID.randomUUID().toString();
    final String name = TableSpace.DEFAULT;
    final String nodeid = "nodeid";
    ServerConfiguration serverConfiguration = newServerConfigurationWithAutoPort();
    try (ZookeeperMetadataStorageManager man = new ZookeeperMetadataStorageManager(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath());
        BookkeeperCommitLogManager logManager = new BookkeeperCommitLogManager(man, serverConfiguration, NullStatsLogger.INSTANCE)) {
        man.start();
        logManager.start();
        CommitLogResult res1;
        CommitLogResult res2;
        CommitLogResult res3;
        try (BookkeeperCommitLog writer = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
            writer.startWriting(1);
            res1 = writer.log(LogEntryFactory.beginTransaction(1), false);
            res2 = writer.log(LogEntryFactory.beginTransaction(2), false);
            res3 = writer.log(LogEntryFactory.beginTransaction(3), true);
            assertTrue(res1.deferred);
            assertFalse(res1.sync);
            assertTrue(res2.deferred);
            assertFalse(res2.sync);
            assertFalse(res3.deferred);
            assertTrue(res3.sync);
            assertNull(res1.getLogSequenceNumber());
            assertNull(res2.getLogSequenceNumber());
            assertNotNull(res3.getLogSequenceNumber());
        }
        try (BookkeeperCommitLog reader = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
            List<Map.Entry<LogSequenceNumber, LogEntry>> list = new ArrayList<>();
            reader.recovery(LogSequenceNumber.START_OF_TIME, (lsn, entry) -> {
                if (entry.type != LogEntryType.NOOP) {
                    list.add(new AbstractMap.SimpleImmutableEntry<>(lsn, entry));
                }
            }, false);
            assertEquals(3, list.size());
            assertTrue(list.get(0).getKey().after(LogSequenceNumber.START_OF_TIME));
            assertTrue(list.get(1).getKey().after(list.get(0).getKey()));
            assertTrue(list.get(2).getKey().after(list.get(1).getKey()));
        }
    }
}
Also used : AbstractMap(java.util.AbstractMap) LogEntry(herddb.log.LogEntry) ZookeeperMetadataStorageManager(herddb.cluster.ZookeeperMetadataStorageManager) ServerConfiguration(herddb.server.ServerConfiguration) ArrayList(java.util.ArrayList) BookkeeperCommitLogManager(herddb.cluster.BookkeeperCommitLogManager) CommitLogResult(herddb.log.CommitLogResult) BookkeeperCommitLog(herddb.cluster.BookkeeperCommitLog) Test(org.junit.Test)

Example 74 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class ExpectedReplicaCountTest method testDisklessClusterReplication.

@Test
public void testDisklessClusterReplication() throws Exception {
    TestStatsProvider statsProvider = new TestStatsProvider();
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_DISKLESSCLUSTER);
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        TestUtils.execute(server_1.getManager(), "CREATE TABLESPACE 'ttt','leader:" + server_1.getNodeId() + "','expectedreplicacount:2'", Collections.emptyList());
        // perform some writes
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.set(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_CLUSTER);
        clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
        clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
        clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
        StatsLogger logger = statsProvider.getStatsLogger("ds");
        try (HDBClient client1 = new HDBClient(clientConfiguration, logger)) {
            try (HDBConnection connection = client1.openConnection()) {
                // create table and insert data
                connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE ttt.t1(k1 int primary key, n1 int)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(1,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(2,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(3,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                // flush data pages to BK
                server_1.getManager().checkpoint();
                Set<Long> initialLedgers = new HashSet<>();
                // verify that every ledger has ensemble size 2
                try (BookKeeper bk = createBookKeeper()) {
                    BookKeeperAdmin admin = new BookKeeperAdmin(bk);
                    for (long lId : admin.listLedgers()) {
                        LedgerMetadata md = bk.getLedgerManager().readLedgerMetadata(lId).get().getValue();
                        if ("ttt".equals(new String(md.getCustomMetadata().get("tablespaceuuid"), StandardCharsets.UTF_8))) {
                            assertEquals(2, md.getEnsembleSize());
                            assertEquals(2, md.getWriteQuorumSize());
                            assertEquals(2, md.getAckQuorumSize());
                            initialLedgers.add(lId);
                        }
                    }
                }
                BookkeeperCommitLog log = (BookkeeperCommitLog) server_1.getManager().getTableSpaceManager("ttt").getLog();
                final long currentLedgerId = log.getWriter().getLedgerId();
                // downsize to expectedreplicacount = 1
                TestUtils.execute(server_1.getManager(), "ALTER TABLESPACE 'ttt','leader:" + server_1.getNodeId() + "','expectedreplicacount:1'", Collections.emptyList());
                // the TableSpaceManager will roll a new ledger
                herddb.utils.TestUtils.waitForCondition(() -> {
                    if (log.getWriter() == null) {
                        return false;
                    }
                    long newLedgerId = log.getWriter().getLedgerId();
                    return newLedgerId != currentLedgerId;
                }, herddb.utils.TestUtils.NOOP, 100);
                // write some other record
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(4,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                // flush data pages
                server_1.getManager().checkpoint();
                // verify that every ledger has ensemble size 2 or 1
                try (BookKeeper bk = createBookKeeper()) {
                    BookKeeperAdmin admin = new BookKeeperAdmin(bk);
                    for (long lId : admin.listLedgers()) {
                        LedgerMetadata md = bk.getLedgerManager().readLedgerMetadata(lId).get().getValue();
                        if ("ttt".equals(new String(md.getCustomMetadata().get("tablespaceuuid"), StandardCharsets.UTF_8))) {
                            if (initialLedgers.contains(lId)) {
                                assertEquals(2, md.getEnsembleSize());
                                assertEquals(2, md.getWriteQuorumSize());
                                assertEquals(2, md.getAckQuorumSize());
                            } else {
                                assertEquals(1, md.getEnsembleSize());
                                assertEquals(1, md.getWriteQuorumSize());
                                assertEquals(1, md.getAckQuorumSize());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) Server(herddb.server.Server) ServerConfiguration(herddb.server.ServerConfiguration) BookKeeper(org.apache.bookkeeper.client.BookKeeper) HDBConnection(herddb.client.HDBConnection) HDBClient(herddb.client.HDBClient) LedgerMetadata(org.apache.bookkeeper.client.api.LedgerMetadata) ClientConfiguration(herddb.client.ClientConfiguration) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class SimpleClientServerTest method testTimeoutDuringAuth.

@Test
public void testTimeoutDuringAuth() throws Exception {
    Path baseDir = folder.newFolder().toPath();
    ServerConfiguration config = newServerConfigurationWithAutoPort(baseDir);
    final AtomicBoolean suspendProcessing = new AtomicBoolean(false);
    try (Server server = new Server(config) {

        @Override
        protected ServerSideConnectionPeer buildPeer(Channel channel) {
            return new ServerSideConnectionPeer(channel, this) {

                @Override
                public void requestReceived(Pdu message, Channel channel) {
                    if (suspendProcessing.get()) {
                        LOG.log(Level.INFO, "dropping message type " + message.type + " id " + message.messageId);
                        message.close();
                        return;
                    }
                    super.requestReceived(message, channel);
                }
            };
        }
    }) {
        server.start();
        server.waitForStandaloneBoot();
        ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
        clientConfiguration.set(ClientConfiguration.PROPERTY_TIMEOUT, 2000);
        clientConfiguration.set(ClientConfiguration.PROPERTY_MAX_CONNECTIONS_PER_SERVER, 1);
        try (HDBClient client = new HDBClient(clientConfiguration);
            HDBConnection connection = client.openConnection()) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            assertTrue(connection.waitForTableSpace(TableSpace.DEFAULT, Integer.MAX_VALUE));
            long resultCreateTable = connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE mytable (id int primary key, s1 string)", 0, false, true, Collections.emptyList()).updateCount;
            Assert.assertEquals(1, resultCreateTable);
            suspendProcessing.set(true);
            try (HDBConnection connection2 = client.openConnection()) {
                // auth will timeout
                try {
                    connection2.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,s1) values(?,?)", TransactionContext.NOTRANSACTION_ID, false, true, Arrays.asList(1, "test1"));
                    fail("insertion should fail");
                } catch (Exception e) {
                    TestUtils.assertExceptionPresentInChain(e, HDBOperationTimeoutException.class);
                }
                suspendProcessing.set(false);
                // new connection
                assertEquals(1, connection2.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,s1) values(?,?)", TransactionContext.NOTRANSACTION_ID, false, true, Arrays.asList(1, "test1")).updateCount);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Pdu(herddb.proto.Pdu) ServerSideConnectionPeer(herddb.server.ServerSideConnectionPeer) Server(herddb.server.Server) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) ServerConfiguration(herddb.server.ServerConfiguration) Channel(herddb.network.Channel) NettyChannel(herddb.network.netty.NettyChannel) SocketChannel(io.netty.channel.socket.SocketChannel) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) IOException(java.io.IOException) MissingJDBCParameterException(herddb.model.MissingJDBCParameterException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) Test(org.junit.Test)

Aggregations

ServerConfiguration (herddb.server.ServerConfiguration)86 Test (org.junit.Test)78 Server (herddb.server.Server)60 Table (herddb.model.Table)39 CreateTableStatement (herddb.model.commands.CreateTableStatement)36 InsertStatement (herddb.model.commands.InsertStatement)34 HashSet (java.util.HashSet)21 DataScanner (herddb.model.DataScanner)20 BookkeeperCommitLog (herddb.cluster.BookkeeperCommitLog)19 AlterTableSpaceStatement (herddb.model.commands.AlterTableSpaceStatement)19 ClientConfiguration (herddb.client.ClientConfiguration)16 ArrayList (java.util.ArrayList)16 TableSpaceManager (herddb.core.TableSpaceManager)15 Index (herddb.model.Index)15 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)15 Path (java.nio.file.Path)14 HDBClient (herddb.client.HDBClient)13 HDBConnection (herddb.client.HDBConnection)13 ZookeeperMetadataStorageManager (herddb.cluster.ZookeeperMetadataStorageManager)13 GetStatement (herddb.model.commands.GetStatement)13