Skip to content

Commit

Permalink
[OceanBase][test] Update oceanbase and oblogproxy docker image (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe authored Jun 2, 2023
1 parent 23c20cc commit c8c8107
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 44 deletions.
54 changes: 42 additions & 12 deletions docs/content/quickstart/oceanbase-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ Create `docker-compose.yml`.
version: '2.1'
services:
observer:
image: oceanbase/oceanbase-ce:3.1.4
image: oceanbase/oceanbase-ce:4.0.0.0
container_name: observer
environment:
- 'OB_ROOT_PASSWORD=pswd'
network_mode: "host"
oblogproxy:
image: whhe/oblogproxy:1.0.3
image: whhe/oblogproxy:1.1.0_4x
container_name: oblogproxy
environment:
- 'OB_SYS_USERNAME=root'
Expand Down Expand Up @@ -60,12 +58,44 @@ Execute the following command in the directory where `docker-compose.yml` is loc
docker-compose up -d
```

### Set password

There is no password for 'root' user by default, but we need a user of 'sys' tenant with non-empty password in oblogproxy. So here we should set a password for 'root@sys' firstly.

Login 'root' user of 'sys' tenant.

```shell
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot@sys
```

Set a password, note that the password needs to be consistent with the environment variable 'OB_SYS_PASSWORD' of oblogproxy service.

```mysql
ALTER USER root IDENTIFIED BY 'pswd';
```

From OceanBase 4.0.0.0 CE, we can only fetch the commit log of non-sys tenant.

Here we use the 'test' tenant for example.

Login with 'root' user of 'test' tenant:

```shell
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot@test
```

Set a password:

```mysql
ALTER USER root IDENTIFIED BY 'test';
```

### Create data for reading snapshot

Open the CLI:
Login 'root' user of 'test' tenant.

```shell
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot -ppswd
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot@test -ptest
```

Insert data:
Expand Down Expand Up @@ -135,9 +165,9 @@ Flink SQL> CREATE TABLE orders (
) WITH (
'connector' = 'oceanbase-cdc',
'scan.startup.mode' = 'initial',
'username' = 'root',
'password' = 'pswd',
'tenant-name' = 'sys',
'username' = 'root@test',
'password' = 'test',
'tenant-name' = 'test',
'database-name' = '^ob$',
'table-name' = '^orders$',
'hostname' = 'localhost',
Expand All @@ -157,9 +187,9 @@ Flink SQL> CREATE TABLE products (
) WITH (
'connector' = 'oceanbase-cdc',
'scan.startup.mode' = 'initial',
'username' = 'root',
'password' = 'pswd',
'tenant-name' = 'sys',
'username' = 'root@test',
'password' = 'test',
'tenant-name' = 'test',
'database-name' = '^ob$',
'table-name' = '^products$',
'hostname' = 'localhost',
Expand Down
54 changes: 41 additions & 13 deletions docs/content/快速上手/oceanbase-tutorial-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
version: '2.1'
services:
observer:
image: oceanbase/oceanbase-ce:3.1.4
image: oceanbase/oceanbase-ce:4.0.0.0
container_name: observer
environment:
- 'OB_ROOT_PASSWORD=pswd'
network_mode: "host"
oblogproxy:
image: whhe/oblogproxy:1.0.3
image: whhe/oblogproxy:1.1.0_4x
container_name: oblogproxy
environment:
- 'OB_SYS_USERNAME=root'
Expand Down Expand Up @@ -61,12 +59,42 @@ services:
docker-compose up -d
```

### 准备数据:
### 设置密码

OceanBase 中 root 用户默认是没有密码的,但是 oblogproxy 需要配置一个使用非空密码的系统租户用户,因此这里我们需要先为 root@sys 用户设置一个密码。

登陆 sys 租户的 root 用户:

```shell
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot@sys
```

设置密码,注意这里的密码需要与上一步中 oblogproxy 服务的环境变量 'OB_SYS_PASSWORD' 保持一样。

```mysql
ALTER USER root IDENTIFIED BY 'pswd';
```

OceanBase 从社区版 4.0.0.0 开始只支持对非 sys 租户的增量数据拉取,这里我们使用 test 租户的 root 用户作为示例。

登陆 test 租户的 root 用户:

```shell
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot@test
```

设置密码:

```mysql
ALTER USER root IDENTIFIED BY 'test';
```

### 准备数据

使用新创建的用户名和密码进行登陆
使用 'root@test' 用户登陆

```shell
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot -ppswd
docker-compose exec observer obclient -h127.0.0.1 -P2881 -uroot@test -ptest
```

```sql
Expand Down Expand Up @@ -134,9 +162,9 @@ Flink SQL> CREATE TABLE orders (
) WITH (
'connector' = 'oceanbase-cdc',
'scan.startup.mode' = 'initial',
'username' = 'root',
'password' = 'pswd',
'tenant-name' = 'sys',
'username' = 'root@test',
'password' = 'test',
'tenant-name' = 'test',
'database-name' = '^ob$',
'table-name' = '^orders$',
'hostname' = 'localhost',
Expand All @@ -156,9 +184,9 @@ Flink SQL> CREATE TABLE products (
) WITH (
'connector' = 'oceanbase-cdc',
'scan.startup.mode' = 'initial',
'username' = 'root',
'password' = 'pswd',
'tenant-name' = 'sys',
'username' = 'root@test',
'password' = 'test',
'tenant-name' = 'test',
'database-name' = '^ob$',
'table-name' = '^products$',
'hostname' = 'localhost',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public class OceanBaseTestBase extends TestLogger {
public static final int OB_SERVER_RPC_PORT = 2882;
public static final int LOG_PROXY_PORT = 2983;

public static final String OB_SYS_USERNAME = "root";
public static final String OB_SYS_PASSWORD = "pswd";
public static final String OB_TEST_PASSWORD = "test";

public static final String NETWORK_MODE = "host";

Expand Down Expand Up @@ -91,37 +91,36 @@ protected static int getLogProxyPort() {

// --------------------------------------------------------------------------------------------
// Attributes about user.
// Here we use the root user of 'sys' tenant, which is not recommended for production.
// From OceanBase 4.0.0.0 CE, we can only fetch the commit log of non-sys tenant.
// --------------------------------------------------------------------------------------------

protected static String getTenant() {
return "sys";
return "test";
}

protected static String getUsername() {
return OB_SYS_USERNAME;
return "root@test";
}

protected static String getPassword() {
return OB_SYS_PASSWORD;
return OB_TEST_PASSWORD;
}

@ClassRule
public static final GenericContainer<?> OB_SERVER =
new GenericContainer<>("oceanbase/oceanbase-ce:3.1.4")
new GenericContainer<>("oceanbase/oceanbase-ce:4.0.0.0")
.withNetworkMode(NETWORK_MODE)
.withExposedPorts(OB_SERVER_SQL_PORT, OB_SERVER_RPC_PORT)
.withEnv("OB_ROOT_PASSWORD", OB_SYS_PASSWORD)
.waitingFor(Wait.forLogMessage(".*boot success!.*", 1))
.withStartupTimeout(CONTAINER_STARTUP_TIMEOUT)
.withLogConsumer(new Slf4jLogConsumer(LOG));

@ClassRule
public static final GenericContainer<?> LOG_PROXY =
new GenericContainer<>("whhe/oblogproxy:1.0.3")
new GenericContainer<>("whhe/oblogproxy:1.1.0_4x")
.withNetworkMode(NETWORK_MODE)
.withExposedPorts(LOG_PROXY_PORT)
.withEnv("OB_SYS_USERNAME", OB_SYS_USERNAME)
.withEnv("OB_SYS_USERNAME", "root")
.withEnv("OB_SYS_PASSWORD", OB_SYS_PASSWORD)
.waitingFor(Wait.forLogMessage(".*boot success!.*", 1))
.withStartupTimeout(CONTAINER_STARTUP_TIMEOUT)
Expand All @@ -132,6 +131,20 @@ public static void startContainers() {
LOG.info("Starting containers...");
Startables.deepStart(Stream.of(OB_SERVER, LOG_PROXY)).join();
LOG.info("Containers are started.");

setPassword("root@sys", OB_SYS_PASSWORD);
setPassword("root@test", OB_TEST_PASSWORD);
}

private static void setPassword(String username, String password) {
try (Connection connection = DriverManager.getConnection(getJdbcUrl(""), username, "");
Statement statement = connection.createStatement()) {
statement.execute(String.format("ALTER USER root IDENTIFIED BY '%s'", password));
LOG.info("Set password of {} to {}", username, password);
} catch (SQLException e) {
LOG.error("Set password of {} failed.", username, e);
throw new RuntimeException(e);
}
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,36 @@ public void testMetadataColumns() throws Exception {

List<String> expected =
Arrays.asList(
"+I(sys,inventory_meta,products,101,scooter,Small 2-wheel scooter,3.1400000000)",
"+I(sys,inventory_meta,products,102,car battery,12V car battery,8.1000000000)",
"+I(sys,inventory_meta,products,103,12-pack drill bits,12-pack of drill bits with sizes ranging from #40 to #3,0.8000000000)",
"+I(sys,inventory_meta,products,104,hammer,12oz carpenter's hammer,0.7500000000)",
"+I(sys,inventory_meta,products,105,hammer,14oz carpenter's hammer,0.8750000000)",
"+I(sys,inventory_meta,products,106,hammer,16oz carpenter's hammer,1.0000000000)",
"+I(sys,inventory_meta,products,107,rocks,box of assorted rocks,5.3000000000)",
"+I(sys,inventory_meta,products,108,jacket,water resistent black wind breaker,0.1000000000)",
"+I(sys,inventory_meta,products,109,spare tire,24 inch spare tire,22.2000000000)",
"+U(sys,inventory_meta,products,106,hammer,18oz carpenter hammer,1.0000000000)");
"+I("
+ getTenant()
+ ",inventory_meta,products,101,scooter,Small 2-wheel scooter,3.1400000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,102,car battery,12V car battery,8.1000000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,103,12-pack drill bits,12-pack of drill bits with sizes ranging from #40 to #3,0.8000000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,104,hammer,12oz carpenter's hammer,0.7500000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,105,hammer,14oz carpenter's hammer,0.8750000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,106,hammer,16oz carpenter's hammer,1.0000000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,107,rocks,box of assorted rocks,5.3000000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,108,jacket,water resistent black wind breaker,0.1000000000)",
"+I("
+ getTenant()
+ ",inventory_meta,products,109,spare tire,24 inch spare tire,22.2000000000)",
"+U("
+ getTenant()
+ ",inventory_meta,products,106,hammer,18oz carpenter hammer,1.0000000000)");
List<String> actual = TestValuesTableFactory.getRawResults("sink");
assertContainsInAnyOrder(expected, actual);
result.getJobClient().get().cancel().get();
Expand Down

0 comments on commit c8c8107

Please sign in to comment.