开发者社区 问答 正文

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

我发现在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; } } }

原提问者GitHub用户tsywkGo

展开
收起
Java工程师 2023-05-03 10:15:52 132 分享 版权
1 条回答
写回答
取消 提交回答
  • 升级druid版本为1.2.6后已解决,会正确处理create table if not exist的合并语义

    原回答者GitHub用户agapple

    2023-05-04 14:21:44
    赞同 展开评论