Skip to content

[IOTDB-1931] Adapt tree structrued Template with MManager#4391

Merged
qiaojialin merged 115 commits intoapache:masterfrom
bigreybear:new_vector_with_treeTemplate
Nov 21, 2021
Merged

[IOTDB-1931] Adapt tree structrued Template with MManager#4391
qiaojialin merged 115 commits intoapache:masterfrom
bigreybear:new_vector_with_treeTemplate

Conversation

@bigreybear
Copy link
Copy Markdown
Contributor

This PR has been merged with new_vector branch in apache repository.
All CI in metadata package passed, while some other packages remaining to be fixed as new_vector branch.

JackieTien97 and others added 30 commits October 28, 2021 11:20
Comment on lines +280 to +282
if (!(par instanceof IEntityMNode)) {
throw new MetadataException("Measurement not under entity: " + currentNode.getName());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid instanceof. Use IMNode.isEntity instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it is not necessary, will be removed then

Comment on lines +280 to +282
if (!(par instanceof IEntityMNode)) {
throw new MetadataException("Measurement not under entity: " + currentNode.getName());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? How could the parent MNode of current MeasurementMNode not be Entity?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed now

Comment on lines +296 to +297
retPath.setUnderAlignedEntity(((IEntityMNode) par).isAligned());
return retPath;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace (IEntityMNode) par with par.getAsEntity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now

Comment on lines 149 to 152
traverseContext.push(node);
traverse(child, idx + 1, level + 1);
traverseContext.pop();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to make the context contains node from root to current node's parent, maybe put this push and pop out of the for loop is better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all push and pop are out of loop now

Comment on lines +1924 to +1941
* Before to insert, set using template if template accessed. Better performance if refactored
* with getDeviceNodeWithAutoCreate
*/
private void activateTemplateBeforeAccess(PartialPath deviceId, String[] measurements)
throws MetadataException {
StringBuilder builder = new StringBuilder(deviceId.getFullPath());
if (builder.length() != 0) {
builder.append(TsFileConstant.PATH_SEPARATOR);
}
for (String measurement : measurements) {
builder.append(measurement);
IMNode mountedNode = mtree.getTemplateMountedNode(new PartialPath(builder.toString()));
if (mountedNode != null && !mountedNode.isUseTemplate()) {
setUsingSchemaTemplate(mountedNode);
}
builder.delete(builder.length() - measurement.length(), builder.length());
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mountedNode has not been created on MTree, how could you activate it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you insight!
Now, I will get the template mounted node index, rather than IMNode, so that auto create process methods are decoupled from mounted node detecting.

Comment on lines 1730 to 1731
activateTemplateBeforeAccess(devicePath, measurementList);
IMNode deviceMNode = getDeviceNodeWithAutoCreate(devicePath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the device now is represented by template, this method maybe invalid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As fixed above, this methods no longer exists.

Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Only one format issue and one question. Please have a look~

for (MeasurementPath measurementPath :
manager.getMeasurementPaths(new PartialPath("root.sg1.d1.*"))) {
allSchema.remove(measurementPath.getMeasurementSchema());
manager.getMeasurementPaths(new PartialPath("root.sg1.d1.**"))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the ** means currently? Maybe I miss something in the design part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, the usage of '**' has not change ever, it is still a multil-level wildcard.

The reason to change here, is that template converted to a tree structured one now. As before, this template has 2 schemasName which won't present in measurement path, 's11' and 'vector'. Now measurements of the template contain 2 sublist, which is 's11' and 'vector.s1....s10'.

So, in order to traverse this template, I modify it to '**' as above.


// 1. get device node
// 1. get device node, set using template if accessed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It has been removed now.

try {
resultSet.add(getCurrentPartialPath(node));
} catch (MetadataException e) {
logger.error(e.getMessage());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw exception again here?

Copy link
Copy Markdown
Contributor Author

@bigreybear bigreybear Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to deal with this. It is a exception will not happen actually, so I did not throw it again here.
The exception is caused by a construct of ParitialPath where content are nodes during a traverse which should assure to avoid illegal path. But this method override an abstract method which does not throw exception, so this catch did not throw again.

} else {
for (IMNode child : mountedNode.getChildren().values()) {
if (child.isMeasurement()) {
if (template.getAlignedPrefixSet().contains("")
Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of empty string here? Maybe we need some comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This string tries to represent alignment of direct measurement of a template. I will add more comment.

@qiaojialin qiaojialin changed the base branch from new_vector to master November 17, 2021 01:24
@coveralls
Copy link
Copy Markdown

coveralls commented Nov 17, 2021

Coverage Status

Coverage increased (+0.01%) to 66.979% when pulling f8b9dbf on bigreybear:new_vector_with_treeTemplate into d9d8733 on apache:master.

Comment on lines +279 to +297
protected MeasurementPath getCurrentMeasurementPathInTraverse(IMeasurementMNode currentNode)
throws MetadataException {
IMNode par = traverseContext.peek();

Iterator<IMNode> nodes = traverseContext.descendingIterator();
StringBuilder builder = new StringBuilder(nodes.next().getName());
while (nodes.hasNext()) {
builder.append(TsFileConstant.PATH_SEPARATOR);
builder.append(nodes.next().getName());
}
if (builder.length() != 0) {
builder.append(TsFileConstant.PATH_SEPARATOR);
}
builder.append(currentNode.getName());
MeasurementPath retPath =
new MeasurementPath(new PartialPath(builder.toString()), currentNode.getSchema());
retPath.setUnderAlignedEntity(par.getAsEntityMNode().isAligned());
return retPath;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this method to MeasurementCollector is better, if this method is only used in that kind of tasks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been moved now

Comment on lines +1594 to +1597
throw new MetadataException(
String.format(
"Path [%s] overlaps but not matches template [%s] under node [%s]",
measurementPath.getFullPath(), upperTemplate.getName(), fullPathNodes[index]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we make this kind exception message as a specific Exception class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new exception TemplateImcompatibleException replaces all these usages.

Comment on lines 2021 to 2024
// node might be replaced when check with alignment
node = mtree.checkTemplateAlignmentWithMountedNode(node, template);

node.setSchemaTemplate(template);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this node is not using template, why should it be replaced by entityMNode?

Copy link
Copy Markdown
Contributor Author

@bigreybear bigreybear Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. This check should be a part of setUsingTemplate methods rather than this one. Fixed now.

Comment on lines 2074 to 2083
// this operation may change mtree structure and node type
// invoke mnode.setUseTemplate is invalid
IEntityMNode entityMNode = mtree.setToEntity(node);

// to ensure alignment adapt with former node or template
entityMNode.setAligned(
node.isEntity()
? node.getAsEntityMNode().isAligned()
: node.getUpperTemplate().isDirectAligned());
entityMNode.setUseTemplate(true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, a MNode using template is possibly not an entityMNode since the template may not has direct measurement. Thus the node type transform need check first.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the field "isUsingTemplate" from EntityMNode to InternalMNode. This may be better to adapt to Tree template.

Copy link
Copy Markdown
Contributor Author

@bigreybear bigreybear Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this method (setUsingTemplate), it will check alignment and replace it if direct measurement exists now.
To implement this, I add setUseTemplate into Interface IMNode.
And this method will return an IMNode rather than IEntityNode now.

Comment on lines +1734 to +1750
int indexRecord = -1;
// check every measurement path
for (String measurementId : measurementList) {
PartialPath fullPath = devicePath.concatNode(measurementId);
int index = mtree.getMountedNodeIndexOnMeasurementPath(fullPath);
if (index != fullPath.getNodeLength() - 1) {
// this measurement is in template, need to assure mounted node exists and set using
// template.
if (index != indexRecord) {
// Without allowing overlap of template and MTree, this block run only once
String[] mountedPathNodes = Arrays.copyOfRange(fullPath.getNodes(), 0, index + 1);
IMNode mountedNode = getDeviceNodeWithAutoCreate(new PartialPath(mountedPathNodes));
setUsingSchemaTemplate(mountedNode);
indexRecord = index;
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since insertPlan only process one device, it is unnecessary to finish the whole loop. Break as early as the device has been checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it needs to check each measurementPath with template whether compatible, I use a boolean to avoid reduntant process.

Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one issue in IT. Other part are look good to me~


// delete series inside template
try {
session.deleteTimeseries("root.sg.loc1.sector.x");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a fail() after this line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! And it has been added now.

@bigreybear bigreybear force-pushed the new_vector_with_treeTemplate branch from 5a38e3f to 6d5d384 Compare November 20, 2021 01:53
@qiaojialin qiaojialin merged commit 441d6b7 into apache:master Nov 21, 2021
@bigreybear bigreybear deleted the new_vector_with_treeTemplate branch July 28, 2022 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.