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

[BUG] 如果TSDB已经存在了table schema cache,为什么还要继续进行apply? #2766

Closed
tsywkGo opened this issue May 25, 2020 · 2 comments
Labels
Milestone

Comments

@tsywkGo
Copy link

tsywkGo commented May 25, 2020

[BUG]

我发现在CREATE TABLE IF NOT EXIST xxx_table 这样的SQL执行会导致字段解析乱序;我分析到代码如果已经存在的表,执行这样的SQL会更新table cache schema,是不是这样原因导致的?

if (!isSeek && !isDml) {
                // 使用新的表结构元数据管理方式
                EntryPosition position = createPosition(event.getHeader());
                tableMetaCache.apply(position, event.getDbName(), queryString, null);
            }
/*
传递参数position,是尝试根据dump到不同位点位置的binlog使用不同的table schema进行解析,这里的逻辑是没有实现吗?
*/
 public boolean apply(EntryPosition position, String schema, String ddl, String extra) {
        tableMetas.clear();
        synchronized (this) {
            if (StringUtils.isNotEmpty(schema)) {
                repository.setDefaultSchema(schema);
            }

            try {
                // druid暂时flush privileges语法解析有问题
                if (!StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "flush")
                    && !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "grant")
                    && !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "revoke")
                    && !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "create user")
                    && !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "alter user")
                    && !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "drop user")
                    && !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "create database")) {
                    repository.console(ddl);
                }
            } catch (Throwable e) {
                logger.warn("parse faield : " + ddl, e);
            }
        }

        // TableMeta meta = find("tddl5_00", "ab");
        // if (meta != null) {
        // repository.setDefaultSchema("tddl5_00");
        // System.out.println(repository.console("show create table tddl5_00.ab"));
        // System.out.println(repository.console("show columns from tddl5_00.ab"));
        // }
        return true;
    }

public void setDefaultSchema(String name) {
        if (name == null) {
            this.defaultSchema = null;
        } else {
            String normalizedName = SQLUtils.normalize(name).toLowerCase();
            Schema defaultSchema = (Schema)this.schemas.get(normalizedName);
            if (defaultSchema != null) {
                this.defaultSchema = defaultSchema;
            } else if (this.defaultSchema != null && this.defaultSchema.getName() == null) {
                this.defaultSchema.setName(name);
                this.schemas.put(normalizedName, this.defaultSchema);
            } else {
                defaultSchema = new Schema(this);
                defaultSchema.setName(name);
                this.schemas.put(normalizedName, defaultSchema);
                this.defaultSchema = defaultSchema;
            }
        }
    }
@tsywkGo tsywkGo changed the title 如果TSDB已经存在了table schema cache,为什么还要继续进行apply? [BUG] 如果TSDB已经存在了table schema cache,为什么还要继续进行apply? May 25, 2020
@tsywkGo
Copy link
Author

tsywkGo commented May 26, 2020

@agapple

@agapple agapple added the bug label Aug 21, 2020
@agapple agapple added this to the v1.1.5 milestone Aug 21, 2020
@agapple
Copy link
Member

agapple commented Apr 19, 2021

升级druid版本为1.2.6后已解决,会正确处理create table if not exist的合并语义

@agapple agapple closed this as completed Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants