Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
7c256485
I
Iotdb
项目概览
apache
/
Iotdb
大约 1 年 前同步成功
通知
25
Star
3344
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iotdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7c256485
编写于
7月 24, 2023
作者:
C
Chen YZ
提交者:
GitHub
7月 24, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[To rel/1.2][IOTDB-6076] Add duplicate checking when upsert alias
上级
43601d7f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
110 addition
and
77 deletion
+110
-77
integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java
...t/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java
+29
-0
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
...chemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
+6
-37
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
...chemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
+6
-40
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/MTreeBelowSGMemoryImpl.java
...e/schemaregion/mtree/impl/mem/MTreeBelowSGMemoryImpl.java
+23
-0
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java
...chemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java
+27
-0
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
...db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
+19
-0
未找到文件。
integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java
浏览文件 @
7c256485
...
...
@@ -607,4 +607,33 @@ public class IoTDBTagAlterIT extends AbstractSchemaIT {
fail
();
}
}
@Test
public
void
alterDuplicateAliasTest
()
{
try
(
Connection
connection
=
EnvFactory
.
getEnv
().
getConnection
();
Statement
statement
=
connection
.
createStatement
())
{
statement
.
execute
(
"create timeseries root.turbine.d1.s1(a1) with datatype=FLOAT, encoding=RLE, compression=SNAPPY;"
);
statement
.
execute
(
"create timeseries root.turbine.d1.s2 with datatype=INT32, encoding=RLE;"
);
try
{
statement
.
execute
(
"alter timeseries root.turbine.d1.s2 upsert alias=s1;"
);
fail
();
}
catch
(
Exception
e
)
{
assertTrue
(
e
.
getMessage
()
.
contains
(
"The alias is duplicated with the name or alias of other measurement."
));
}
try
{
statement
.
execute
(
"alter timeseries root.turbine.d1.s2 upsert alias=a1;"
);
fail
();
}
catch
(
Exception
e
)
{
assertTrue
(
e
.
getMessage
()
.
contains
(
"The alias is duplicated with the name or alias of other measurement."
));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
fail
();
}
}
}
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
浏览文件 @
7c256485
...
...
@@ -28,7 +28,6 @@ import org.apache.iotdb.commons.path.PartialPath;
import
org.apache.iotdb.commons.path.PathPatternTree
;
import
org.apache.iotdb.commons.schema.ClusterSchemaQuotaLevel
;
import
org.apache.iotdb.commons.schema.filter.SchemaFilterType
;
import
org.apache.iotdb.commons.schema.node.role.IDeviceMNode
;
import
org.apache.iotdb.commons.schema.node.role.IMeasurementMNode
;
import
org.apache.iotdb.commons.schema.view.LogicalViewSchema
;
import
org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression
;
...
...
@@ -943,22 +942,6 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
}
}
private
void
changeAlias
(
PartialPath
path
,
String
alias
)
throws
MetadataException
{
IMeasurementMNode
<
IMemMNode
>
leafMNode
=
mtree
.
getMeasurementMNode
(
path
);
IDeviceMNode
<
IMemMNode
>
device
=
leafMNode
.
getParent
().
getAsDeviceMNode
();
if
(
leafMNode
.
getAlias
()
!=
null
)
{
device
.
deleteAliasChild
(
leafMNode
.
getAlias
());
}
device
.
addAlias
(
alias
,
leafMNode
);
mtree
.
setAlias
(
leafMNode
,
alias
);
try
{
writeToMLog
(
SchemaRegionWritePlanFactory
.
getChangeAliasPlan
(
path
,
alias
));
}
catch
(
IOException
e
)
{
throw
new
MetadataException
(
e
);
}
}
/**
* Upsert tags and attributes key-value for the timeseries if the key has existed, just use the
* new value to update it.
...
...
@@ -976,11 +959,9 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
Map
<
String
,
String
>
attributesMap
,
PartialPath
fullPath
)
throws
MetadataException
,
IOException
{
IMeasurementMNode
<
IMemMNode
>
leafMNode
=
mtree
.
getMeasurementMNode
(
fullPath
);
// upsert alias
upsertAlias
(
alias
,
fullPath
,
leafMNode
);
upsertAlias
(
alias
,
fullPath
);
IMeasurementMNode
<
IMemMNode
>
leafMNode
=
mtree
.
getMeasurementMNode
(
fullPath
);
if
(
tagsMap
==
null
&&
attributesMap
==
null
)
{
return
;
}
...
...
@@ -1000,21 +981,9 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
tagManager
.
updateTagsAndAttributes
(
tagsMap
,
attributesMap
,
leafMNode
);
}
private
void
upsertAlias
(
String
alias
,
PartialPath
fullPath
,
IMeasurementMNode
<
IMemMNode
>
leafMNode
)
private
void
upsertAlias
(
String
alias
,
PartialPath
fullPath
)
throws
MetadataException
,
IOException
{
// upsert alias
if
(
alias
!=
null
&&
!
alias
.
equals
(
leafMNode
.
getAlias
()))
{
IDeviceMNode
<
IMemMNode
>
deviceMNode
=
leafMNode
.
getParent
().
getAsDeviceMNode
();
if
(!
deviceMNode
.
addAlias
(
alias
,
leafMNode
))
{
throw
new
MetadataException
(
"The alias already exists."
);
}
if
(
leafMNode
.
getAlias
()
!=
null
)
{
deviceMNode
.
deleteAliasChild
(
leafMNode
.
getAlias
());
}
mtree
.
setAlias
(
leafMNode
,
alias
);
if
(
mtree
.
changeAlias
(
alias
,
fullPath
))
{
// persist to WAL
writeToMLog
(
SchemaRegionWritePlanFactory
.
getChangeAliasPlan
(
fullPath
,
alias
));
}
...
...
@@ -1315,9 +1284,9 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
public
RecoverOperationResult
visitChangeAlias
(
IChangeAliasPlan
changeAliasPlan
,
SchemaRegionMemoryImpl
context
)
{
try
{
changeAlias
(
changeAliasPlan
.
getPath
(),
changeAliasPlan
.
getAlias
());
upsertAlias
(
changeAliasPlan
.
getAlias
(),
changeAliasPlan
.
getPath
());
return
RecoverOperationResult
.
SUCCESS
;
}
catch
(
MetadataException
e
)
{
}
catch
(
MetadataException
|
IOException
e
)
{
return
new
RecoverOperationResult
(
e
);
}
}
...
...
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
浏览文件 @
7c256485
...
...
@@ -954,26 +954,6 @@ public class SchemaRegionPBTreeImpl implements ISchemaRegion {
}
}
private
void
changeAlias
(
PartialPath
path
,
String
alias
)
throws
MetadataException
{
IMeasurementMNode
<
ICachedMNode
>
leafMNode
=
mtree
.
getMeasurementMNode
(
path
);
try
{
IDeviceMNode
<
ICachedMNode
>
device
=
leafMNode
.
getParent
().
getAsDeviceMNode
();
if
(
leafMNode
.
getAlias
()
!=
null
)
{
device
.
deleteAliasChild
(
leafMNode
.
getAlias
());
}
device
.
addAlias
(
alias
,
leafMNode
);
mtree
.
setAlias
(
leafMNode
,
alias
);
}
finally
{
mtree
.
unPinMNode
(
leafMNode
.
getAsMNode
());
}
try
{
writeToMLog
(
SchemaRegionWritePlanFactory
.
getChangeAliasPlan
(
path
,
alias
));
}
catch
(
IOException
e
)
{
throw
new
MetadataException
(
e
);
}
}
/**
* Upsert tags and attributes key-value for the timeseries if the key has existed, just use the
* new value to update it.
...
...
@@ -991,15 +971,13 @@ public class SchemaRegionPBTreeImpl implements ISchemaRegion {
Map
<
String
,
String
>
attributesMap
,
PartialPath
fullPath
)
throws
MetadataException
,
IOException
{
// upsert alias
upsertAlias
(
alias
,
fullPath
);
IMeasurementMNode
<
ICachedMNode
>
leafMNode
=
mtree
.
getMeasurementMNode
(
fullPath
);
try
{
// upsert alias
upsertAlias
(
alias
,
fullPath
,
leafMNode
);
if
(
tagsMap
==
null
&&
attributesMap
==
null
)
{
return
;
}
// no tag or attribute, we need to add a new record in log
if
(
leafMNode
.
getOffset
()
<
0
)
{
long
offset
=
tagManager
.
writeTagFile
(
tagsMap
,
attributesMap
);
...
...
@@ -1020,21 +998,9 @@ public class SchemaRegionPBTreeImpl implements ISchemaRegion {
}
}
private
void
upsertAlias
(
String
alias
,
PartialPath
fullPath
,
IMeasurementMNode
<
ICachedMNode
>
leafMNode
)
private
void
upsertAlias
(
String
alias
,
PartialPath
fullPath
)
throws
MetadataException
,
IOException
{
// upsert alias
if
(
alias
!=
null
&&
!
alias
.
equals
(
leafMNode
.
getAlias
()))
{
IDeviceMNode
<
ICachedMNode
>
device
=
leafMNode
.
getParent
().
getAsDeviceMNode
();
if
(!
device
.
addAlias
(
alias
,
leafMNode
))
{
throw
new
MetadataException
(
"The alias already exists."
);
}
if
(
leafMNode
.
getAlias
()
!=
null
)
{
device
.
deleteAliasChild
(
leafMNode
.
getAlias
());
}
mtree
.
setAlias
(
leafMNode
,
alias
);
if
(
mtree
.
changeAlias
(
alias
,
fullPath
))
{
// persist to WAL
writeToMLog
(
SchemaRegionWritePlanFactory
.
getChangeAliasPlan
(
fullPath
,
alias
));
}
...
...
@@ -1357,9 +1323,9 @@ public class SchemaRegionPBTreeImpl implements ISchemaRegion {
public
RecoverOperationResult
visitChangeAlias
(
IChangeAliasPlan
changeAliasPlan
,
SchemaRegionPBTreeImpl
context
)
{
try
{
changeAlias
(
changeAliasPlan
.
getPath
(),
changeAliasPlan
.
getAlias
());
upsertAlias
(
changeAliasPlan
.
getAlias
(),
changeAliasPlan
.
getPath
());
return
RecoverOperationResult
.
SUCCESS
;
}
catch
(
MetadataException
e
)
{
}
catch
(
MetadataException
|
IOException
e
)
{
return
new
RecoverOperationResult
(
e
);
}
}
...
...
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/MTreeBelowSGMemoryImpl.java
浏览文件 @
7c256485
...
...
@@ -479,6 +479,29 @@ public class MTreeBelowSGMemoryImpl {
}
return
failingMeasurementMap
;
}
public
boolean
changeAlias
(
String
alias
,
PartialPath
fullPath
)
throws
MetadataException
{
IMeasurementMNode
<
IMemMNode
>
measurementMNode
=
getMeasurementMNode
(
fullPath
);
// upsert alias
if
(
alias
!=
null
&&
!
alias
.
equals
(
measurementMNode
.
getAlias
()))
{
synchronized
(
this
)
{
IDeviceMNode
<
IMemMNode
>
device
=
measurementMNode
.
getParent
().
getAsDeviceMNode
();
IMemMNode
memMNode
=
store
.
getChild
(
device
.
getAsMNode
(),
alias
);
if
(
memMNode
!=
null
)
{
throw
new
MetadataException
(
"The alias is duplicated with the name or alias of other measurement."
);
}
if
(
measurementMNode
.
getAlias
()
!=
null
)
{
device
.
deleteAliasChild
(
measurementMNode
.
getAlias
());
}
device
.
addAlias
(
alias
,
measurementMNode
);
setAlias
(
measurementMNode
,
alias
);
}
return
true
;
}
return
false
;
}
/**
* Delete path. The path should be a full path from root to leaf node
*
...
...
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java
浏览文件 @
7c256485
...
...
@@ -422,6 +422,33 @@ public class MTreeBelowSGCachedImpl {
}
}
public
boolean
changeAlias
(
String
alias
,
PartialPath
fullPath
)
throws
MetadataException
{
IMeasurementMNode
<
ICachedMNode
>
measurementMNode
=
getMeasurementMNode
(
fullPath
);
try
{
// upsert alias
if
(
alias
!=
null
&&
!
alias
.
equals
(
measurementMNode
.
getAlias
()))
{
synchronized
(
this
)
{
IDeviceMNode
<
ICachedMNode
>
device
=
measurementMNode
.
getParent
().
getAsDeviceMNode
();
ICachedMNode
cachedMNode
=
store
.
getChild
(
device
.
getAsMNode
(),
alias
);
if
(
cachedMNode
!=
null
)
{
unPinMNode
(
cachedMNode
);
throw
new
MetadataException
(
"The alias is duplicated with the name or alias of other measurement."
);
}
if
(
measurementMNode
.
getAlias
()
!=
null
)
{
device
.
deleteAliasChild
(
measurementMNode
.
getAlias
());
}
device
.
addAlias
(
alias
,
measurementMNode
);
setAlias
(
measurementMNode
,
alias
);
}
return
true
;
}
return
false
;
}
finally
{
unPinMNode
(
measurementMNode
.
getAsMNode
());
}
}
public
Map
<
Integer
,
MetadataException
>
checkMeasurementExistence
(
PartialPath
devicePath
,
List
<
String
>
measurementList
,
List
<
String
>
aliasList
)
{
ICachedMNode
device
;
...
...
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
浏览文件 @
7c256485
...
...
@@ -245,6 +245,25 @@ public class SchemaRegionAliasAndTagTest extends AbstractSchemaRegionTest {
public
void
testUpsertAliasAndTagsAndAttributes
()
{
try
{
prepareTimeseries
();
try
{
schemaRegion
.
upsertAliasAndTagsAndAttributes
(
"s2"
,
null
,
null
,
new
PartialPath
(
"root.sg.wf01.wt01.v1.s1"
));
Assert
.
fail
();
}
catch
(
Exception
e
)
{
Assert
.
assertTrue
(
e
.
getMessage
()
.
contains
(
"The alias is duplicated with the name or alias of other measurement."
));
}
try
{
schemaRegion
.
upsertAliasAndTagsAndAttributes
(
"temp"
,
null
,
null
,
new
PartialPath
(
"root.sg.wf01.wt01.v1.s1"
));
Assert
.
fail
();
}
catch
(
Exception
e
)
{
Assert
.
assertTrue
(
e
.
getMessage
()
.
contains
(
"The alias is duplicated with the name or alias of other measurement."
));
}
Map
<
String
,
String
>
newTags
=
new
HashMap
<
String
,
String
>()
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录