Skip to content

Commit

Permalink
compatible with TDSQL-C Mysql (ccfos#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo authored Apr 27, 2023
1 parent 2a36902 commit 63aa615
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cli/upgrade/upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ alter table `alert_his_event` add annotations text not null comment 'annotations
alter table `alert_his_event` add rule_config text not null comment 'rule_config';

alter table `alerting_engines` add datasource_id bigint unsigned not null default 0;
alter table `alerting_engines` change cluster engine_cluster varchar(128) not null default '' comment 'n9e engine cluster';

alter table `task_record` add event_id bigint not null comment 'event id' default 0;

CREATE TABLE `datasource`
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,13 @@ CREATE TABLE alerting_engines
id serial,
instance varchar(128) not null default '' ,
datasource_id bigint not null default 0 ,
cluster varchar(128) not null default '' ,
engine_cluster varchar(128) not null default '' ,
clock bigint not null,
PRIMARY KEY (id)
) ;
COMMENT ON COLUMN alerting_engines.instance IS 'instance identification, e.g. 10.9.0.9:9090';
COMMENT ON COLUMN alerting_engines.datasource_id IS 'datasource id';
COMMENT ON COLUMN alerting_engines.cluster IS 'target reader cluster';
COMMENT ON COLUMN alerting_engines.engine_cluster IS 'target reader cluster';


CREATE TABLE datasource
Expand Down
3 changes: 1 addition & 2 deletions docker/initsql/a-n9e.sql
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,11 @@ CREATE TABLE `alerting_engines`
`id` int unsigned NOT NULL AUTO_INCREMENT,
`instance` varchar(128) not null default '' comment 'instance identification, e.g. 10.9.0.9:9090',
`datasource_id` bigint not null default 0 comment 'datasource id',
`cluster` varchar(128) not null default '' comment 'n9e-alert cluster',
`engine_cluster` varchar(128) not null default '' comment 'n9e-alert cluster',
`clock` bigint not null,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;


CREATE TABLE `datasource`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
Expand Down
22 changes: 11 additions & 11 deletions models/alerting_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

type AlertingEngines struct {
Id int64 `json:"id" gorm:"primaryKey"`
Instance string `json:"instance"`
Cluster string `json:"cluster"`
DatasourceId int64 `json:"datasource_id"`
Clock int64 `json:"clock"`
Id int64 `json:"id" gorm:"primaryKey"`
Instance string `json:"instance"`
EngineCluster string `json:"cluster" gorm:"engine_cluster"`
DatasourceId int64 `json:"datasource_id"`
Clock int64 `json:"clock"`
}

func (e *AlertingEngines) TableName() string {
Expand Down Expand Up @@ -130,23 +130,23 @@ func AlertingEngineGetsInstances(ctx *ctx.Context, where string, args ...interfa

func AlertingEngineHeartbeatWithCluster(ctx *ctx.Context, instance, cluster string, datasourceId int64) error {
var total int64
err := DB(ctx).Model(new(AlertingEngines)).Where("instance=? and `cluster` = ? and datasource_id=?", instance, cluster, datasourceId).Count(&total).Error
err := DB(ctx).Model(new(AlertingEngines)).Where("instance=? and engine_cluster = ? and datasource_id=?", instance, cluster, datasourceId).Count(&total).Error
if err != nil {
return err
}

if total == 0 {
// insert
err = DB(ctx).Create(&AlertingEngines{
Instance: instance,
DatasourceId: datasourceId,
Cluster: cluster,
Clock: time.Now().Unix(),
Instance: instance,
DatasourceId: datasourceId,
EngineCluster: cluster,
Clock: time.Now().Unix(),
}).Error
} else {
// updates
fields := map[string]interface{}{"clock": time.Now().Unix()}
err = DB(ctx).Model(new(AlertingEngines)).Where("instance=? and `cluster` = ? and datasource_id=?", instance, cluster, datasourceId).Updates(fields).Error
err = DB(ctx).Model(new(AlertingEngines)).Where("instance=? and engine_cluster = ? and datasource_id=?", instance, cluster, datasourceId).Updates(fields).Error
}

return err
Expand Down

0 comments on commit 63aa615

Please sign in to comment.