use of herddb.client.ZookeeperClientSideMetadataProvider in project herddb by diennea.
the class DownloadTableSpaceTest method downloadTablespaceTest.
@Test
public void downloadTablespaceTest() throws Exception {
ServerConfiguration serverconfig_1 = new ServerConfiguration(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_PORT, 7867);
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());
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).primaryKey("c").build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
for (int i = 0; i < 1000; i++) {
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
}
List<Map<String, Object>> logical_data = new ArrayList<>();
AtomicBoolean start = new AtomicBoolean();
try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));
HDBConnection con = client.openConnection()) {
client.setClientSideMetadataProvider(new ZookeeperClientSideMetadataProvider(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath()));
CountDownLatch count = new CountDownLatch(1);
con.dumpTableSpace(TableSpace.DEFAULT, new TableSpaceDumpReceiver() {
Table table;
@Override
public void start(LogSequenceNumber logSequenceNumber) throws DataStorageManagerException {
System.out.println("start at " + logSequenceNumber);
start.set(true);
}
@Override
public void finish(LogSequenceNumber logSequenceNumber) {
System.out.println("finish!");
count.countDown();
}
@Override
public void endTable() {
System.out.println("endTable");
table = null;
}
@Override
public void receiveTableDataChunk(List<Record> records) {
// System.out.println("receiveTableDataChunk " + records);
for (Record r : records) {
Map<String, Object> bean = r.toBean(table);
// System.out.println("received:" + bean);
logical_data.add(bean);
}
}
@Override
public void beginTable(DumpedTableMetadata table, Map<String, Object> stats) {
System.out.println("beginTable " + table);
this.table = table.table;
}
}, 89, false);
assertTrue(count.await(20, TimeUnit.SECONDS));
assertEquals(1000, logical_data.size());
assertTrue(start.get());
}
}
}
use of herddb.client.ZookeeperClientSideMetadataProvider in project herddb by diennea.
the class SimpleClusterTest method test.
@Test
public void test() throws Exception {
try (TestingServer zookeeperServer = new TestingServer(-1, folder.newFolder("zk"))) {
File tmpConfFile = folder.newFile("test.server_cluster.properties");
try (InputStream in = SimpleClusterTest.class.getResourceAsStream("/conf/test.server_cluster.properties")) {
Properties props = new Properties();
props.load(in);
props.put(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
props.put(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, zookeeperServer.getConnectString());
try (FileOutputStream oo = new FileOutputStream(tmpConfFile)) {
props.store(oo, "");
}
}
Thread runner = new Thread(() -> {
ServerMain.main(tmpConfFile.getAbsolutePath());
});
runner.start();
while (ServerMain.getRunningInstance() == null || !ServerMain.getRunningInstance().isStarted()) {
Thread.sleep(1000);
System.out.println("waiting for boot");
}
ServerMain.getRunningInstance().getServer().waitForStandaloneBoot();
try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
client.setClientSideMetadataProvider(new ZookeeperClientSideMetadataProvider(zookeeperServer.getConnectString(), 40000, "/herddb"));
try (HDBConnection con = client.openConnection()) {
try (ScanResultSet scan = con.executeScan(TableSpace.DEFAULT, "SELECT * FROM SYSTABLES", Collections.emptyList(), 0, 10, 10)) {
scan.consume();
}
}
}
ServerMain.getRunningInstance().close();
} finally {
if (ServerMain.getRunningInstance() != null) {
ServerMain.getRunningInstance().close();
}
}
}
use of herddb.client.ZookeeperClientSideMetadataProvider in project herddb by diennea.
the class UseVirtualTableSpaceIdWithZookKeeperTest method test_leader_online_log_available.
@Test
public void test_leader_online_log_available() throws Exception {
ServerConfiguration serverconfig_1 = new ServerConfiguration(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_PORT, 7867);
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);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath()).set(ServerConfiguration.PROPERTY_PORT, 7868);
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).primaryKey("c").build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 2, 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(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
if (found.found()) {
break;
}
Thread.sleep(100);
}
assertTrue(server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
try (HDBClient client = new HDBClient(clientConfiguration);
HDBConnection connection = client.openConnection()) {
client.setClientSideMetadataProvider(new ZookeeperClientSideMetadataProvider(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath()));
try (ScanResultSet scan = connection.executeScan(null, "SELECT * FROM " + server_1.getManager().getVirtualTableSpaceId() + ".sysnodes", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
assertEquals(2, all.size());
}
try (ScanResultSet scan = connection.executeScan(null, "SELECT * FROM " + server_2.getManager().getVirtualTableSpaceId() + ".sysnodes", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
assertEquals(2, all.size());
}
try (ScanResultSet scan = connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM sysnodes", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
assertEquals(2, all.size());
}
}
}
}
}
Aggregations