Search in sources :

Example 41 with Server

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

the class SimpleClientServerTest method testHandleReadTimeout.

@Test
public void testHandleReadTimeout() throws Exception {
    Path baseDir = folder.newFolder().toPath();
    ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
    clientConfiguration.set(ClientConfiguration.PROPERTY_MAX_CONNECTIONS_PER_SERVER, 1);
    final int timeout = 1000;
    final AtomicInteger channelCreatedCount = new AtomicInteger();
    clientConfiguration.set(ClientConfiguration.PROPERTY_NETWORK_TIMEOUT, timeout);
    try (HDBClient client = new HDBClient(clientConfiguration) {

        @Override
        Channel createChannelTo(ServerHostData server, ChannelEventListener eventReceiver) throws IOException {
            channelCreatedCount.incrementAndGet();
            return super.createChannelTo(server, eventReceiver);
        }
    }) {
        try (HDBConnection connection1 = client.openConnection()) {
            try (Server server = new Server(newServerConfigurationWithAutoPort(baseDir))) {
                server.start();
                server.waitForStandaloneBoot();
                client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
                assertTrue(connection1.waitForTableSpace(TableSpace.DEFAULT, Integer.MAX_VALUE));
                channelCreatedCount.set(0);
                long resultCreateTable = connection1.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE mytable (id string primary key, n1 long, n2 integer)", 0, false, false, /*usePreparedStatement*/
                Collections.emptyList()).updateCount;
                Assert.assertEquals(1, resultCreateTable);
                assertEquals(0, channelCreatedCount.get());
                // wait for client side timeout
                // the only connected socket will be disconnected
                Thread.sleep(timeout + 1000);
                connection1.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable", false, /*usePreparedStatement*/
                Collections.emptyList(), 0, 0, 10, true).close();
                assertEquals(1, channelCreatedCount.get());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ChannelEventListener(herddb.network.ChannelEventListener) StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) Server(herddb.server.Server) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerHostData(herddb.network.ServerHostData) Test(org.junit.Test)

Example 42 with Server

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

the class SimpleClientServerTest method testCachePreparedStatementsPrepareSqlAgain.

/**
 * Testing that if the server discards the query the client will resend the PREPARE_STATEMENT COMMAND
 *
 * @throws Exception
 */
@Test
public void testCachePreparedStatementsPrepareSqlAgain() throws Exception {
    Path baseDir = folder.newFolder().toPath();
    try (Server server = new Server(newServerConfigurationWithAutoPort(baseDir))) {
        server.start();
        server.waitForStandaloneBoot();
        ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
        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 string primary key, n1 long, n2 integer)", 0, false, true, Collections.emptyList()).updateCount;
            Assert.assertEquals(1, resultCreateTable);
            {
                long tx = connection.beginTransaction(TableSpace.DEFAULT);
                long countInsert = connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", tx, false, true, Arrays.asList("test", 1, 2)).updateCount;
                Assert.assertEquals(1, countInsert);
                long countInsert2 = connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", tx, false, true, Arrays.asList("test2", 2, 3)).updateCount;
                Assert.assertEquals(1, countInsert2);
                connection.commitTransaction(TableSpace.DEFAULT, tx);
            }
            // SCAN
            {
                try (ScanResultSet res = connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test'", true, Collections.emptyList(), TransactionContext.NOTRANSACTION_ID, 100, 100, true)) {
                    assertEquals(1, res.consume().size());
                }
            }
            server.getManager().getPreparedStatementsCache().clear();
            {
                try (ScanResultSet res = connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test'", true, Collections.emptyList(), TransactionContext.NOTRANSACTION_ID, 100, 100, true)) {
                    assertEquals(1, res.consume().size());
                }
            }
            // GET
            {
                GetResult res = connection.executeGet(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test'", TransactionContext.NOTRANSACTION_ID, true, Collections.emptyList());
                Map<RawString, Object> record = res.data;
                Assert.assertNotNull(record);
                assertEquals(RawString.of("test"), record.get(RawString.of("id")));
                assertEquals(Long.valueOf(1), record.get(RawString.of("n1")));
                assertEquals(Integer.valueOf(2), record.get(RawString.of("n2")));
            }
            server.getManager().getPreparedStatementsCache().clear();
            {
                GetResult res = connection.executeGet(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test'", TransactionContext.NOTRANSACTION_ID, true, Collections.emptyList());
                Map<RawString, Object> record = res.data;
                Assert.assertNotNull(record);
            }
            // EXECUTE UPDATES
            {
                List<DMLResult> executeUpdates = connection.executeUpdates(TableSpace.DEFAULT, "UPDATE mytable set n2=? WHERE id=?", TransactionContext.NOTRANSACTION_ID, false, true, Arrays.asList(Arrays.asList(1, "test"), Arrays.asList(2, "test2"), Arrays.asList(3, "test_not_exists")));
                assertEquals(3, executeUpdates.size());
                assertEquals(1, executeUpdates.get(0).updateCount);
                assertEquals(1, executeUpdates.get(1).updateCount);
                assertEquals(0, executeUpdates.get(2).updateCount);
            }
            server.getManager().getPreparedStatementsCache().clear();
            {
                List<DMLResult> executeUpdates = connection.executeUpdates(TableSpace.DEFAULT, "UPDATE mytable set n2=? WHERE id=?", TransactionContext.NOTRANSACTION_ID, false, true, Arrays.asList(Arrays.asList(1, "test"), Arrays.asList(2, "test2"), Arrays.asList(3, "test_not_exists")));
                assertEquals(3, executeUpdates.size());
                assertEquals(1, executeUpdates.get(0).updateCount);
                assertEquals(1, executeUpdates.get(1).updateCount);
                assertEquals(0, executeUpdates.get(2).updateCount);
            }
            // EXECUTE UPDATE
            {
                DMLResult executeUpdate = connection.executeUpdate(TableSpace.DEFAULT, "UPDATE mytable set n2=? WHERE id=?", TransactionContext.NOTRANSACTION_ID, false, true, Arrays.asList(1, "test"));
                assertEquals(1, executeUpdate.updateCount);
            }
            server.getManager().getPreparedStatementsCache().clear();
            {
                DMLResult executeUpdate = connection.executeUpdate(TableSpace.DEFAULT, "UPDATE mytable set n2=? WHERE id=?", TransactionContext.NOTRANSACTION_ID, false, true, Arrays.asList(1, "test"));
                assertEquals(1, executeUpdate.updateCount);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) Server(herddb.server.Server) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 43 with Server

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

the class BootFollowerTest method testFollowerBootError.

@Test
public void testFollowerBootError() throws Exception {
    int size = 20_000;
    final AtomicInteger callCount = new AtomicInteger();
    // inject a temporary error during download
    final AtomicInteger errorCount = new AtomicInteger(1);
    SystemInstrumentation.addListener(new SystemInstrumentation.SingleInstrumentationPointListener("receiveTableDataChunk") {

        @Override
        public void acceptSingle(Object... args) throws Exception {
            callCount.incrementAndGet();
            if (errorCount.decrementAndGet() == 0) {
                throw new Exception("synthetic error");
            }
        }
    });
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
    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());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
    // disabled
    serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
    ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath()).set(ServerConfiguration.PROPERTY_BOOT_FORCE_DOWNLOAD_SNAPSHOT, true).set(ServerConfiguration.PROPERTY_MEMORY_LIMIT_REFERENCE, 5_000_000).set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 200_000);
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.INTEGER).primaryKey("c").build();
        server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        try (Server server_2 = new Server(serverconfig_2)) {
            server_2.start();
            LogSequenceNumber lastSequenceNumberServer1 = server_1.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
            for (int i = 0; i < size; i++) {
                server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i, "s", "1" + i)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            }
            server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
            LogSequenceNumber lastSequenceNumberServer2 = server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
            while (!lastSequenceNumberServer2.after(lastSequenceNumberServer1)) {
                System.out.println("WAITING FOR server2 to be in sync....now it is a " + lastSequenceNumberServer2 + " vs " + lastSequenceNumberServer1);
                lastSequenceNumberServer2 = server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
                Thread.sleep(1000);
            }
        }
        // reboot followerĖ™
        try (Server server_2 = new Server(serverconfig_2)) {
            server_2.start();
            assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
            for (int i = 0; i < size; i++) {
                GetResult found = server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(i), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
                if (found.found()) {
                    break;
                }
                Thread.sleep(100);
            }
        }
        assertEquals(3, callCount.get());
        assertTrue(errorCount.get() <= 0);
    }
}
Also used : AlterTableSpaceStatement(herddb.model.commands.AlterTableSpaceStatement) Table(herddb.model.Table) Server(herddb.server.Server) GetResult(herddb.model.GetResult) ServerConfiguration(herddb.server.ServerConfiguration) CreateTableStatement(herddb.model.commands.CreateTableStatement) LogSequenceNumber(herddb.log.LogSequenceNumber) InsertStatement(herddb.model.commands.InsertStatement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GetStatement(herddb.model.commands.GetStatement) SystemInstrumentation(herddb.utils.SystemInstrumentation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with Server

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

the class BootFollowerTest method testLeaderOnlineLogAvailable.

@Test
public void testLeaderOnlineLogAvailable() throws Exception {
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
    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());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
    // disabled
    serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
    ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.INTEGER).primaryKey("c").build();
        Index index = Index.builder().onTable(table).type(Index.TYPE_BRIN).column("s", ColumnTypes.STRING).build();
        server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        server_1.getManager().executeStatement(new CreateIndexStatement(index), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1, "s", "1")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2, "s", "2")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3, "s", "3")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4, "s", "4")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        DMLStatementExecutionResult executeUpdateTransaction = server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 5, "s", "5")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.AUTOTRANSACTION_TRANSACTION);
        server_1.getManager().executeStatement(new CommitTransactionStatement(TableSpace.DEFAULT, executeUpdateTransaction.transactionId), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        // force BK LAC
        server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 6, "s", "6")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        try (Server server_2 = new Server(serverconfig_2)) {
            server_2.getManager().setActivatorPauseStatus(true);
            server_2.start();
            assertTrue(server_2.getManager().isTableSpaceLocallyRecoverable(server_2.getMetadataStorageManager().describeTableSpace(TableSpace.DEFAULT)));
            server_2.getManager().setActivatorPauseStatus(false);
            server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
            // wait for data to arrive on server_2
            for (int i = 0; i < 100; i++) {
                GetResult found = server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(5), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
                if (found.found()) {
                    break;
                }
                Thread.sleep(100);
            }
            for (int i = 1; i <= 5; i++) {
                System.out.println("checking key c=" + i);
                assertTrue(server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(i), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
            }
            TranslatedQuery translated = server_1.getManager().getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM " + TableSpace.DEFAULT + ".t1 WHERE s=1", Collections.emptyList(), true, true, false, -1);
            ScanStatement statement = translated.plan.mainStatement.unwrap(ScanStatement.class);
            assertTrue(statement.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
            try (DataScanner scan = server_1.getManager().scan(statement, translated.context, TransactionContext.NO_TRANSACTION)) {
                assertEquals(1, scan.consume().size());
            }
        }
    }
}
Also used : AlterTableSpaceStatement(herddb.model.commands.AlterTableSpaceStatement) Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) Server(herddb.server.Server) GetResult(herddb.model.GetResult) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) ServerConfiguration(herddb.server.ServerConfiguration) CreateTableStatement(herddb.model.commands.CreateTableStatement) CreateIndexStatement(herddb.model.commands.CreateIndexStatement) Index(herddb.model.Index) InsertStatement(herddb.model.commands.InsertStatement) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) DataScanner(herddb.model.DataScanner) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) GetStatement(herddb.model.commands.GetStatement) HashSet(java.util.HashSet) ScanStatement(herddb.model.commands.ScanStatement) Test(org.junit.Test)

Example 45 with Server

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

the class SimpleFollowerTest method testLeaderOnlineLogAvailableMultipleVersionsActivePages.

@Test
public void testLeaderOnlineLogAvailableMultipleVersionsActivePages() throws Exception {
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 1000);
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
    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());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
    serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
    // delete ledgers soon
    serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_RETENTION_PERIOD, 1);
    serverconfig_1.set(ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD, 0);
    // disabled
    serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
    /*
         * Disable page compaction (avoid compaction of dirty page)
         */
    serverconfig_1.set(ServerConfiguration.PROPERTY_FILL_PAGE_THRESHOLD, 0.0D);
    ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BOOT_FORCE_DOWNLOAD_SNAPSHOT, true).set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
    Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.STRING).primaryKey("c").build();
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        TableSpaceManager tableSpaceManager = server_1.getManager().getTableSpaceManager(TableSpace.DEFAULT);
        AbstractTableManager tableManager = tableSpaceManager.getTableManager("t1");
        // fill table
        long tx = herddb.core.TestUtils.beginTransaction(server_1.getManager(), TableSpace.DEFAULT);
        for (int i = 0; i < 1000; i++) {
            server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i, "s", "1")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        }
        herddb.core.TestUtils.commitTransaction(server_1.getManager(), TableSpace.DEFAULT, tx);
        // when we send the dump to the follower we must send only the latest version of the record
        for (int i = 0; i < 10; i++) {
            tableManager.flush();
            server_1.getManager().executeUpdate(new UpdateStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1, "s", "2" + i), null), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        }
        BooleanHolder foundDuplicate = new BooleanHolder(false);
        server_1.getManager().getDataStorageManager().fullTableScan(tableSpaceManager.getTableSpaceUUID(), tableManager.getTable().uuid, new FullTableScanConsumer() {

            Map<Bytes, Long> recordPage = new HashMap<>();

            @Override
            public void acceptPage(long pageId, List<Record> records) {
                for (Record record : records) {
                    Long prev = recordPage.put(record.key, pageId);
                    if (prev != null) {
                        foundDuplicate.value = true;
                    }
                }
            }
        });
        assertTrue(foundDuplicate.value);
        // data will be downloaded from the server_1 (PROPERTY_BOOT_FORCE_DOWNLOAD_SNAPSHOT)
        try (Server server_2 = new Server(serverconfig_2)) {
            server_2.start();
            assertTrue(server_2.getManager().isTableSpaceLocallyRecoverable(server_1.getMetadataStorageManager().describeTableSpace(TableSpace.DEFAULT)));
            server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
        }
    }
}
Also used : UpdateStatement(herddb.model.commands.UpdateStatement) AlterTableSpaceStatement(herddb.model.commands.AlterTableSpaceStatement) Table(herddb.model.Table) Server(herddb.server.Server) HashMap(java.util.HashMap) ServerConfiguration(herddb.server.ServerConfiguration) CreateTableStatement(herddb.model.commands.CreateTableStatement) BooleanHolder(herddb.utils.BooleanHolder) InsertStatement(herddb.model.commands.InsertStatement) FullTableScanConsumer(herddb.storage.FullTableScanConsumer) Bytes(herddb.utils.Bytes) AbstractTableManager(herddb.core.AbstractTableManager) TransactionContext(herddb.model.TransactionContext) TableSpaceManager(herddb.core.TableSpaceManager) Record(herddb.model.Record) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Server (herddb.server.Server)119 Test (org.junit.Test)111 ServerConfiguration (herddb.server.ServerConfiguration)60 ClientConfiguration (herddb.client.ClientConfiguration)56 StaticClientSideMetadataProvider (herddb.server.StaticClientSideMetadataProvider)56 Connection (java.sql.Connection)53 HDBClient (herddb.client.HDBClient)52 Statement (java.sql.Statement)47 ResultSet (java.sql.ResultSet)37 Table (herddb.model.Table)36 CreateTableStatement (herddb.model.commands.CreateTableStatement)35 InsertStatement (herddb.model.commands.InsertStatement)32 PreparedStatement (java.sql.PreparedStatement)30 HashSet (java.util.HashSet)24 AlterTableSpaceStatement (herddb.model.commands.AlterTableSpaceStatement)19 Path (java.nio.file.Path)19 DataScanner (herddb.model.DataScanner)18 TableSpaceManager (herddb.core.TableSpaceManager)15 HDBConnection (herddb.client.HDBConnection)14 Index (herddb.model.Index)14