Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
killuaz丶x
SkyWalking
提交
594994ff
S
SkyWalking
项目概览
killuaz丶x
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
594994ff
编写于
7月 21, 2019
作者:
彭
彭勇升 pengys
提交者:
wu-sheng
7月 21, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. Provide InsertRequest and UpdateRequest interface for prepare persistence. (#3131)
2. Implement the ids query for H2 metrics DAO.
上级
3fd1f072
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
286 addition
and
43 deletion
+286
-43
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/MetricsPersistentWorker.java
.../server/core/analysis/worker/MetricsPersistentWorker.java
+1
-1
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/IMetricsDAO.java
...pache/skywalking/oap/server/core/storage/IMetricsDAO.java
+4
-3
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/StorageDAO.java
...apache/skywalking/oap/server/core/storage/StorageDAO.java
+2
-2
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java
...ver/library/client/elasticsearch/ElasticSearchClient.java
+4
-4
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchInsertRequest.java
...rary/client/elasticsearch/ElasticSearchInsertRequest.java
+37
-0
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchUpdateRequest.java
...rary/client/elasticsearch/ElasticSearchUpdateRequest.java
+36
-0
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/jdbc/hikaricp/JDBCHikariCPClient.java
...rver/library/client/jdbc/hikaricp/JDBCHikariCPClient.java
+1
-1
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/request/InsertRequest.java
...king/oap/server/library/client/request/InsertRequest.java
+24
-0
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/request/PrepareRequest.java
...ing/oap/server/library/client/request/PrepareRequest.java
+24
-0
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/request/UpdateRequest.java
...king/oap/server/library/client/request/UpdateRequest.java
+24
-0
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/MetricsEsDAO.java
...erver/storage/plugin/elasticsearch/base/MetricsEsDAO.java
+4
-6
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsDAO.java
...erver/storage/plugin/elasticsearch/base/StorageEsDAO.java
+2
-4
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/ArrayParamBuilder.java
...ing/oap/server/storage/plugin/jdbc/ArrayParamBuilder.java
+35
-0
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/SQLExecutor.java
...kywalking/oap/server/storage/plugin/jdbc/SQLExecutor.java
+6
-7
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetricsDAO.java
...g/oap/server/storage/plugin/jdbc/h2/dao/H2MetricsDAO.java
+15
-4
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2SQLExecutor.java
.../oap/server/storage/plugin/jdbc/h2/dao/H2SQLExecutor.java
+26
-7
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2StorageDAO.java
...g/oap/server/storage/plugin/jdbc/h2/dao/H2StorageDAO.java
+3
-4
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/ArrayParamBuilderTestCase.java
...server/storage/plugin/jdbc/ArrayParamBuilderTestCase.java
+38
-0
未找到文件。
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/MetricsPersistentWorker.java
浏览文件 @
594994ff
...
...
@@ -40,7 +40,7 @@ public class MetricsPersistentWorker extends PersistenceWorker<Metrics, MergeDat
private
final
Model
model
;
private
final
MergeDataCache
<
Metrics
>
mergeDataCache
;
private
final
IMetricsDAO
<?,
?>
metricsDAO
;
private
final
IMetricsDAO
metricsDAO
;
private
final
AbstractWorker
<
Metrics
>
nextAlarmWorker
;
private
final
AbstractWorker
<
ExportEvent
>
nextExportWorker
;
private
final
DataCarrier
<
Metrics
>
dataCarrier
;
...
...
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/IMetricsDAO.java
浏览文件 @
594994ff
...
...
@@ -22,15 +22,16 @@ import java.io.IOException;
import
java.util.Map
;
import
org.apache.skywalking.oap.server.core.analysis.metrics.Metrics
;
import
org.apache.skywalking.oap.server.core.storage.model.Model
;
import
org.apache.skywalking.oap.server.library.client.request.*
;
/**
* @author peng-yongsheng
*/
public
interface
IMetricsDAO
<
INSERT
,
UPDATE
>
extends
DAO
{
public
interface
IMetricsDAO
extends
DAO
{
Map
<
String
,
Metrics
>
get
(
Model
model
,
Metrics
[]
metrics
)
throws
IOException
;
I
NSERT
prepareBatchInsert
(
Model
model
,
Metrics
metrics
)
throws
IOException
;
I
nsertRequest
prepareBatchInsert
(
Model
model
,
Metrics
metrics
)
throws
IOException
;
U
PDATE
prepareBatchUpdate
(
Model
model
,
Metrics
metrics
)
throws
IOException
;
U
pdateRequest
prepareBatchUpdate
(
Model
model
,
Metrics
metrics
)
throws
IOException
;
}
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/StorageDAO.java
浏览文件 @
594994ff
...
...
@@ -26,9 +26,9 @@ import org.apache.skywalking.oap.server.library.module.Service;
/**
* @author peng-yongsheng
*/
public
interface
StorageDAO
<
INSERT
,
UPDATE
>
extends
Service
{
public
interface
StorageDAO
extends
Service
{
IMetricsDAO
<
INSERT
,
UPDATE
>
newMetricsDao
(
StorageBuilder
<
Metrics
>
storageBuilder
);
IMetricsDAO
newMetricsDao
(
StorageBuilder
<
Metrics
>
storageBuilder
);
IRegisterDAO
newRegisterDao
(
StorageBuilder
<
RegisterSource
>
storageBuilder
);
...
...
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java
浏览文件 @
594994ff
...
...
@@ -254,14 +254,14 @@ public class ElasticSearchClient implements Client {
client
.
update
(
request
);
}
public
Index
Request
prepareInsert
(
String
indexName
,
String
id
,
XContentBuilder
source
)
{
public
ElasticSearchInsert
Request
prepareInsert
(
String
indexName
,
String
id
,
XContentBuilder
source
)
{
indexName
=
formatIndexName
(
indexName
);
return
new
Index
Request
(
indexName
,
TYPE
,
id
).
source
(
source
);
return
new
ElasticSearchInsert
Request
(
indexName
,
TYPE
,
id
).
source
(
source
);
}
public
UpdateRequest
prepareUpdate
(
String
indexName
,
String
id
,
XContentBuilder
source
)
{
public
ElasticSearch
UpdateRequest
prepareUpdate
(
String
indexName
,
String
id
,
XContentBuilder
source
)
{
indexName
=
formatIndexName
(
indexName
);
return
new
UpdateRequest
(
indexName
,
TYPE
,
id
).
doc
(
source
);
return
new
ElasticSearch
UpdateRequest
(
indexName
,
TYPE
,
id
).
doc
(
source
);
}
public
int
delete
(
String
indexName
,
String
timeBucketColumnName
,
long
endTimeBucket
)
throws
IOException
{
...
...
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchInsertRequest.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.library.client.elasticsearch
;
import
org.apache.skywalking.oap.server.library.client.request.InsertRequest
;
import
org.elasticsearch.action.index.IndexRequest
;
import
org.elasticsearch.common.xcontent.XContentBuilder
;
/**
* @author peng-yongsheng
*/
public
class
ElasticSearchInsertRequest
extends
IndexRequest
implements
InsertRequest
{
public
ElasticSearchInsertRequest
(
String
index
,
String
type
,
String
id
)
{
super
(
index
,
type
,
id
);
}
@Override
public
ElasticSearchInsertRequest
source
(
XContentBuilder
sourceBuilder
)
{
super
.
source
(
sourceBuilder
);
return
this
;
}
}
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchUpdateRequest.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.library.client.elasticsearch
;
import
org.elasticsearch.action.update.UpdateRequest
;
import
org.elasticsearch.common.xcontent.XContentBuilder
;
/**
* @author peng-yongsheng
*/
public
class
ElasticSearchUpdateRequest
extends
UpdateRequest
implements
org
.
apache
.
skywalking
.
oap
.
server
.
library
.
client
.
request
.
UpdateRequest
{
public
ElasticSearchUpdateRequest
(
String
index
,
String
type
,
String
id
)
{
super
(
index
,
type
,
id
);
}
@Override
public
ElasticSearchUpdateRequest
doc
(
XContentBuilder
source
)
{
super
.
doc
(
source
);
return
this
;
}
}
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/jdbc/hikaricp/JDBCHikariCPClient.java
浏览文件 @
594994ff
...
...
@@ -31,7 +31,7 @@ import org.slf4j.*;
* @author wusheng
*/
public
class
JDBCHikariCPClient
implements
Client
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
JDBCHikariCPClient
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
JDBCHikariCPClient
.
class
);
private
HikariDataSource
dataSource
;
private
HikariConfig
hikariConfig
;
...
...
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/request/InsertRequest.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.library.client.request
;
/**
* @author peng-yongsheng
*/
public
interface
InsertRequest
extends
PrepareRequest
{
}
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/request/PrepareRequest.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.library.client.request
;
/**
* @author peng-yongsheng
*/
public
interface
PrepareRequest
{
}
oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/request/UpdateRequest.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.library.client.request
;
/**
* @author peng-yongsheng
*/
public
interface
UpdateRequest
extends
PrepareRequest
{
}
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/MetricsEsDAO.java
浏览文件 @
594994ff
...
...
@@ -23,16 +23,14 @@ import java.util.*;
import
org.apache.skywalking.oap.server.core.analysis.metrics.Metrics
;
import
org.apache.skywalking.oap.server.core.storage.*
;
import
org.apache.skywalking.oap.server.core.storage.model.Model
;
import
org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient
;
import
org.elasticsearch.action.index.IndexRequest
;
import
org.apache.skywalking.oap.server.library.client.elasticsearch.*
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.update.UpdateRequest
;
import
org.elasticsearch.common.xcontent.XContentBuilder
;
/**
* @author peng-yongsheng
*/
public
class
MetricsEsDAO
extends
EsDAO
implements
IMetricsDAO
<
IndexRequest
,
UpdateRequest
>
{
public
class
MetricsEsDAO
extends
EsDAO
implements
IMetricsDAO
{
private
final
StorageBuilder
<
Metrics
>
storageBuilder
;
...
...
@@ -57,13 +55,13 @@ public class MetricsEsDAO extends EsDAO implements IMetricsDAO<IndexRequest, Upd
return
result
;
}
@Override
public
Index
Request
prepareBatchInsert
(
Model
model
,
Metrics
metrics
)
throws
IOException
{
@Override
public
ElasticSearchInsert
Request
prepareBatchInsert
(
Model
model
,
Metrics
metrics
)
throws
IOException
{
XContentBuilder
builder
=
map2builder
(
storageBuilder
.
data2Map
(
metrics
));
String
modelName
=
TimeSeriesUtils
.
timeSeries
(
model
,
metrics
.
getTimeBucket
());
return
getClient
().
prepareInsert
(
modelName
,
metrics
.
id
(),
builder
);
}
@Override
public
UpdateRequest
prepareBatchUpdate
(
Model
model
,
Metrics
metrics
)
throws
IOException
{
@Override
public
ElasticSearch
UpdateRequest
prepareBatchUpdate
(
Model
model
,
Metrics
metrics
)
throws
IOException
{
XContentBuilder
builder
=
map2builder
(
storageBuilder
.
data2Map
(
metrics
));
String
modelName
=
TimeSeriesUtils
.
timeSeries
(
model
,
metrics
.
getTimeBucket
());
return
getClient
().
prepareUpdate
(
modelName
,
metrics
.
id
(),
builder
);
...
...
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsDAO.java
浏览文件 @
594994ff
...
...
@@ -23,19 +23,17 @@ import org.apache.skywalking.oap.server.core.analysis.record.Record;
import
org.apache.skywalking.oap.server.core.register.RegisterSource
;
import
org.apache.skywalking.oap.server.core.storage.*
;
import
org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient
;
import
org.elasticsearch.action.index.IndexRequest
;
import
org.elasticsearch.action.update.UpdateRequest
;
/**
* @author peng-yongsheng
*/
public
class
StorageEsDAO
extends
EsDAO
implements
StorageDAO
<
IndexRequest
,
UpdateRequest
>
{
public
class
StorageEsDAO
extends
EsDAO
implements
StorageDAO
{
public
StorageEsDAO
(
ElasticSearchClient
client
)
{
super
(
client
);
}
@Override
public
IMetricsDAO
<
IndexRequest
,
UpdateRequest
>
newMetricsDao
(
StorageBuilder
<
Metrics
>
storageBuilder
)
{
@Override
public
IMetricsDAO
newMetricsDao
(
StorageBuilder
<
Metrics
>
storageBuilder
)
{
return
new
MetricsEsDAO
(
getClient
(),
storageBuilder
);
}
...
...
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/ArrayParamBuilder.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.storage.plugin.jdbc
;
/**
* @author peng-yongsheng
*/
public
class
ArrayParamBuilder
{
public
static
String
build
(
String
[]
values
)
{
StringBuilder
param
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
param
.
append
(
"'"
).
append
(
values
[
i
]).
append
(
"'"
);
if
(
i
<
values
.
length
-
1
)
{
param
.
append
(
","
);
}
}
return
param
.
toString
();
}
}
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/SQLExecutor.java
浏览文件 @
594994ff
...
...
@@ -18,20 +18,19 @@
package
org.apache.skywalking.oap.server.storage.plugin.jdbc
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.*
;
import
java.util.List
;
import
org.
slf4j.Logger
;
import
org.slf4j.
LoggerFactory
;
import
org.
apache.skywalking.oap.server.library.client.request.*
;
import
org.slf4j.
*
;
/**
* A SQL executor.
*
* @author wusheng
*/
public
class
SQLExecutor
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SQLExecutor
.
class
);
public
class
SQLExecutor
implements
InsertRequest
,
UpdateRequest
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SQLExecutor
.
class
);
private
String
sql
;
private
List
<
Object
>
param
;
...
...
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetricsDAO.java
浏览文件 @
594994ff
...
...
@@ -19,7 +19,7 @@
package
org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao
;
import
java.io.IOException
;
import
java.util.
Map
;
import
java.util.
*
;
import
org.apache.skywalking.oap.server.core.analysis.metrics.Metrics
;
import
org.apache.skywalking.oap.server.core.storage.*
;
import
org.apache.skywalking.oap.server.core.storage.model.Model
;
...
...
@@ -29,7 +29,7 @@ import org.apache.skywalking.oap.server.storage.plugin.jdbc.SQLExecutor;
/**
* @author wusheng
*/
public
class
H2MetricsDAO
extends
H2SQLExecutor
implements
IMetricsDAO
<
SQLExecutor
,
SQLExecutor
>
{
public
class
H2MetricsDAO
extends
H2SQLExecutor
implements
IMetricsDAO
{
private
JDBCHikariCPClient
h2Client
;
private
StorageBuilder
<
Metrics
>
storageBuilder
;
...
...
@@ -40,8 +40,19 @@ public class H2MetricsDAO extends H2SQLExecutor implements IMetricsDAO<SQLExecut
}
@Override
public
Map
<
String
,
Metrics
>
get
(
Model
model
,
Metrics
[]
metrics
)
throws
IOException
{
// return (Metrics)getByID(h2Client, model.getName(), metrics.id(), storageBuilder);
return
null
;
Map
<
String
,
Metrics
>
result
=
new
HashMap
<>();
String
[]
ids
=
new
String
[
metrics
.
length
];
for
(
int
i
=
0
;
i
<
metrics
.
length
;
i
++)
{
ids
[
i
]
=
metrics
[
i
].
id
();
}
List
<
StorageData
>
storageDataList
=
getByIDs
(
h2Client
,
model
.
getName
(),
ids
,
storageBuilder
);
for
(
StorageData
storageData
:
storageDataList
)
{
result
.
put
(
storageData
.
id
(),
(
Metrics
)
storageData
);
}
return
result
;
}
@Override
public
SQLExecutor
prepareBatchInsert
(
Model
model
,
Metrics
metrics
)
throws
IOException
{
...
...
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2SQLExecutor.java
浏览文件 @
594994ff
...
...
@@ -32,11 +32,33 @@ import org.apache.skywalking.oap.server.storage.plugin.jdbc.*;
import
org.slf4j.*
;
/**
* @author wusheng
* @author wusheng
, peng-yongsheng
*/
public
class
H2SQLExecutor
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
H2SQLExecutor
.
class
);
protected
List
<
StorageData
>
getByIDs
(
JDBCHikariCPClient
h2Client
,
String
modelName
,
String
[]
ids
,
StorageBuilder
storageBuilder
)
throws
IOException
{
try
(
Connection
connection
=
h2Client
.
getConnection
())
{
/*
* Although H2 database or other database support createArrayOf and setArray operate.
* But Mysql 5.1.44 driver doesn't.
*/
String
param
=
ArrayParamBuilder
.
build
(
ids
);
try
(
ResultSet
rs
=
h2Client
.
executeQuery
(
connection
,
"SELECT * FROM "
+
modelName
+
" WHERE id in ("
+
param
+
")"
))
{
List
<
StorageData
>
storageDataList
=
new
ArrayList
<>();
while
(
rs
.
next
())
{
storageDataList
.
add
(
toStorageData
(
rs
,
modelName
,
storageBuilder
));
}
return
storageDataList
;
}
}
catch
(
SQLException
|
JDBCClientException
e
)
{
throw
new
IOException
(
e
.
getMessage
(),
e
);
}
}
protected
StorageData
getByID
(
JDBCHikariCPClient
h2Client
,
String
modelName
,
String
id
,
StorageBuilder
storageBuilder
)
throws
IOException
{
try
(
Connection
connection
=
h2Client
.
getConnection
())
{
...
...
@@ -59,8 +81,7 @@ public class H2SQLExecutor {
}
}
protected
StorageData
toStorageData
(
ResultSet
rs
,
String
modelName
,
StorageBuilder
storageBuilder
)
throws
SQLException
{
protected
StorageData
toStorageData
(
ResultSet
rs
,
String
modelName
,
StorageBuilder
storageBuilder
)
throws
SQLException
{
if
(
rs
.
next
())
{
Map
data
=
new
HashMap
();
List
<
ModelColumn
>
columns
=
TableMetaInfo
.
get
(
modelName
).
getColumns
();
...
...
@@ -85,8 +106,7 @@ public class H2SQLExecutor {
return
Const
.
NONE
;
}
protected
SQLExecutor
getInsertExecutor
(
String
modelName
,
StorageData
metrics
,
StorageBuilder
storageBuilder
)
throws
IOException
{
protected
SQLExecutor
getInsertExecutor
(
String
modelName
,
StorageData
metrics
,
StorageBuilder
storageBuilder
)
throws
IOException
{
Map
<
String
,
Object
>
objectMap
=
storageBuilder
.
data2Map
(
metrics
);
SQLBuilder
sqlBuilder
=
new
SQLBuilder
(
"INSERT INTO "
+
modelName
+
" VALUES"
);
...
...
@@ -113,8 +133,7 @@ public class H2SQLExecutor {
return
new
SQLExecutor
(
sqlBuilder
.
toString
(),
param
);
}
protected
SQLExecutor
getUpdateExecutor
(
String
modelName
,
StorageData
metrics
,
StorageBuilder
storageBuilder
)
throws
IOException
{
protected
SQLExecutor
getUpdateExecutor
(
String
modelName
,
StorageData
metrics
,
StorageBuilder
storageBuilder
)
throws
IOException
{
Map
<
String
,
Object
>
objectMap
=
storageBuilder
.
data2Map
(
metrics
);
SQLBuilder
sqlBuilder
=
new
SQLBuilder
(
"UPDATE "
+
modelName
+
" SET "
);
...
...
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2StorageDAO.java
浏览文件 @
594994ff
...
...
@@ -23,12 +23,11 @@ import org.apache.skywalking.oap.server.core.analysis.record.Record;
import
org.apache.skywalking.oap.server.core.register.RegisterSource
;
import
org.apache.skywalking.oap.server.core.storage.*
;
import
org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient
;
import
org.apache.skywalking.oap.server.storage.plugin.jdbc.SQLExecutor
;
/**
* @author wusheng
* @author wusheng
, peng-yongsheng
*/
public
class
H2StorageDAO
implements
StorageDAO
<
SQLExecutor
,
SQLExecutor
>
{
public
class
H2StorageDAO
implements
StorageDAO
{
private
JDBCHikariCPClient
h2Client
;
...
...
@@ -36,7 +35,7 @@ public class H2StorageDAO implements StorageDAO<SQLExecutor, SQLExecutor> {
this
.
h2Client
=
h2Client
;
}
@Override
public
IMetricsDAO
<
SQLExecutor
,
SQLExecutor
>
newMetricsDao
(
StorageBuilder
<
Metrics
>
storageBuilder
)
{
@Override
public
IMetricsDAO
newMetricsDao
(
StorageBuilder
<
Metrics
>
storageBuilder
)
{
return
new
H2MetricsDAO
(
h2Client
,
storageBuilder
);
}
...
...
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/ArrayParamBuilderTestCase.java
0 → 100644
浏览文件 @
594994ff
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.oap.server.storage.plugin.jdbc
;
import
org.junit.*
;
/**
* @author peng-yongsheng
*/
public
class
ArrayParamBuilderTestCase
{
@Test
public
void
testBuild
()
{
String
param
=
ArrayParamBuilder
.
build
(
new
String
[]
{
"1"
});
Assert
.
assertEquals
(
"'1'"
,
param
);
param
=
ArrayParamBuilder
.
build
(
new
String
[]
{
"1"
,
"2"
});
Assert
.
assertEquals
(
"'1','2'"
,
param
);
param
=
ArrayParamBuilder
.
build
(
new
String
[]
{
"1"
,
"2"
,
"3"
});
Assert
.
assertEquals
(
"'1','2','3'"
,
param
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录