Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend should check table exists before creating a table #2128

Closed
WenyXu opened this issue Aug 9, 2023 · 5 comments
Closed

Frontend should check table exists before creating a table #2128

WenyXu opened this issue Aug 9, 2023 · 5 comments
Labels
C-bug Category Bugs

Comments

@WenyXu
Copy link
Member

WenyXu commented Aug 9, 2023

What type of bug is this?

Incorrect result

What subsystems are affected?

Frontend, Meta

What happened?

Runs a 3-node datanode cluster.

Firstly, Creates a 3-region table, it should be ok.

 CREATE TABLE if not exists my_table6 (
        i INT PRIMARY KEY,
        ts TIMESTAMP(9) TIME INDEX,
    ) PARTITION BY RANGE COLUMNS (i) (PARTITION r0 VALUES LESS THAN (715827882), PARTITION r1 VALUES LESS THAN (1431655764), PARTITION r2 VALUES LESS THAN (MAXVALUE),);

And rerun the above, then you will get an error:

"Error: 1003(Internal), status: Internal, message: \"Failed to request Datanode, expected: 3, but only 0 available\", details: [], metadata: MetadataMap { headers: {\"content-type\": \"application/grpc\", \"date\": \"Wed, 09 Aug 2023 02:52:49 GMT\", \"content-length\": \"0\"} }"`

This is because the creating table will run into the selector method before checking whether the table exists. Currently, the datanode can't have multiple regions of one table.

What operating system did you use?

ubuntu 23.04

Relevant log output and stack trace

No response

How can we reproduce the bug?

Runs a 3-node datanode cluster.

Firstly, Creates a 3-region table, it should be ok.

 CREATE TABLE if not exists my_table6 (
        i INT PRIMARY KEY,
        ts TIMESTAMP(9) TIME INDEX,
    ) PARTITION BY RANGE COLUMNS (i) (PARTITION r0 VALUES LESS THAN (715827882), PARTITION r1 VALUES LESS THAN (1431655764), PARTITION r2 VALUES LESS THAN (MAXVALUE),);

And rerun the above, then you will get an error:

"Error: 1003(Internal), status: Internal, message: \"Failed to request Datanode, expected: 3, but only 0 available\", details: [], metadata: MetadataMap { headers: {\"content-type\": \"application/grpc\", \"date\": \"Wed, 09 Aug 2023 02:52:49 GMT\", \"content-length\": \"0\"} }"`
@WenyXu WenyXu added the C-bug Category Bugs label Aug 9, 2023
@NiwakaDev
Copy link
Collaborator

NiwakaDev commented Aug 13, 2023

I'd like to address this issue, but I don't know how to make a test which can reproduce it.

I tried to reproduce this issue, like so:

    #[tokio::test(flavor = "multi_thread")]
    async fn test_issue2128() {
        common_telemetry::init_default_ut_logging();

        let instance =
            tests::create_distributed_instance("test_distributed_insert_delete_and_query").await;
        let frontend = instance.frontend();
        let frontend = frontend.as_ref();

        let table_name = "my_dist_table";
        let sql = format!(
            r"
CREATE TABLE {table_name} (
    a INT,
    ts TIMESTAMP,
    TIME INDEX (ts)
) PARTITION BY RANGE COLUMNS(a) (
    PARTITION r0 VALUES LESS THAN (10),
    PARTITION r1 VALUES LESS THAN (20),
    PARTITION r2 VALUES LESS THAN (50),
    PARTITION r3 VALUES LESS THAN (MAXVALUE),
)"
        );
        create_table(frontend, sql).await;
        let sql = format!(
            r"
CREATE TABLE if not exists {table_name} (
    a INT,
    ts TIMESTAMP,
    TIME INDEX (ts)
) PARTITION BY RANGE COLUMNS(a) (
    PARTITION r0 VALUES LESS THAN (10),
    PARTITION r1 VALUES LESS THAN (20),
    PARTITION r2 VALUES LESS THAN (50),
    PARTITION r3 VALUES LESS THAN (MAXVALUE),
)"
        );
        create_table(frontend, sql).await;

    //

And then I executed cargo nextest run test_issue2128
But, the above test seems to pass.

@WenyXu
Copy link
Member Author

WenyXu commented Aug 14, 2023

How about having a try with gtctl

@NiwakaDev
Copy link
Collaborator

How about having a try with gtctl

I tried it and playground in greptimecloud, but create table was successfully created. (playground in greptimecloud has 3 regions.) Am I missing something?

Reproduction

CREATE TABLE test_table (
    a INT PRIMARY KEY,
    ts TIMESTAMP TIME INDEX
) PARTITION BY RANGE COLUMNS(a) (
    PARTITION r0 VALUES LESS THAN (10),
    PARTITION r1 VALUES LESS THAN (20),
    PARTITION r2 VALUES LESS THAN (MAXVALUE),
);

Then

CREATE TABLE if not exists test_table (
    a INT PRIMARY KEY,
    ts TIMESTAMP TIME INDEX
) PARTITION BY RANGE COLUMNS(a) (
    PARTITION r0 VALUES LESS THAN (10),
    PARTITION r1 VALUES LESS THAN (20),
    PARTITION r2 VALUES LESS THAN (MAXVALUE),
);

Link

https://greptime.com/product/cloud

@WenyXu
Copy link
Member Author

WenyXu commented Sep 12, 2023

How about having a try with gtctl

I tried it and playground in greptimecloud, but create table was successfully created. (playground in greptimecloud has 3 regions.) Am I missing something?

Reproduction

CREATE TABLE test_table (
    a INT PRIMARY KEY,
    ts TIMESTAMP TIME INDEX
) PARTITION BY RANGE COLUMNS(a) (
    PARTITION r0 VALUES LESS THAN (10),
    PARTITION r1 VALUES LESS THAN (20),
    PARTITION r2 VALUES LESS THAN (MAXVALUE),
);

Then

CREATE TABLE if not exists test_table (
    a INT PRIMARY KEY,
    ts TIMESTAMP TIME INDEX
) PARTITION BY RANGE COLUMNS(a) (
    PARTITION r0 VALUES LESS THAN (10),
    PARTITION r1 VALUES LESS THAN (20),
    PARTITION r2 VALUES LESS THAN (MAXVALUE),
);

Link

https://greptime.com/product/cloud

Hi @NiwakaDev , Thank you for your report. The cloud service may not use the latest version. I'll double-check it later.

@MichaelScofield
Copy link
Collaborator

Verified, it's gone in v0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category Bugs
Projects
None yet
Development

No branches or pull requests

3 participants