Skip to content

[IOTDB-868] fix comma bug for mlog#1721

Merged
qiaojialin merged 20 commits intoapache:masterfrom
mychaow:mlog
Dec 14, 2020
Merged

[IOTDB-868] fix comma bug for mlog#1721
qiaojialin merged 20 commits intoapache:masterfrom
mychaow:mlog

Conversation

@mychaow
Copy link
Member

@mychaow mychaow commented Sep 10, 2020

After we import the double-quoted path, users may have any characters in the path that includes ",".

If we still record the mlog using csv format, we could not operate correctly to paths like

root.changde.e34c49.struct@VALUE%PRESENT_ANGLE,_CUTTING_HEAD]

The mlog needs to be encoded.

https://issues.apache.org/jira/browse/IOTDB-868

@mychaow mychaow requested a review from qiaojialin September 10, 2020 09:01
Copy link
Contributor

@samperson1997 samperson1997 left a comment

Choose a reason for hiding this comment

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

Hi Chao, thanks for your contribution! This is a very vital fix. From my first view, I have a few questions to discuss. Could you help and answer them?

Copy link
Member

@qiaojialin qiaojialin left a comment

Choose a reason for hiding this comment

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

Good work! It really a lot effort. Finding a way to replace MNodePlan by MNode is better.

import java.io.IOException;


public class OldMLogReader implements AutoCloseable {
Copy link
Member

Choose a reason for hiding this comment

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

rename to MLogTXTReader or add a javadoc : for reading mlog.txt

try {
plan.serialize(mlogBuffer);
} catch (BufferOverflowException e) {
logger.error("MLog {} BufferOverflow !", plan.getOperatorType(), e);
Copy link
Member

Choose a reason for hiding this comment

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

This is not an error case, change this to debug level is better. The case is: Allocate 16MB for buffer and put log into this buffer one by one, In the end, it always trigger the BufferOverflowException, just reseting the buffer is ok.

However, if one log exceeds 16M, this will throw an exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

private File logFile;
private LogWriter logWriter;
private int logNum;
private ByteBuffer mlogBuffer = ByteBuffer.allocate(
Copy link
Member

Choose a reason for hiding this comment

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

If using a buffer like WAL, we also need a thread to sync the buffer periodically like the forceTask in MultiFileLogNodeManager. Otherwise, the last logs in the buffer will never be persisted.

One option is to sync the mlog one by one.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I think maybe we need to call the forceTask periodically. Because FileChannel.force(true) is more costful than bufferedWriter.flush, this will result in performance degradation of metadata operation.

Comment on lines +1027 to +1246
if (plan instanceof StorageGroupMNodePlan) {
node = StorageGroupMNode.deserializeFrom((StorageGroupMNodePlan) plan);
childrenSize = ((StorageGroupMNodePlan) plan).getChildSize();
} else if (plan instanceof MeasurementMNodePlan) {
node = MeasurementMNode.deserializeFrom((MeasurementMNodePlan) plan);
childrenSize = ((MeasurementMNodePlan) plan).getChildSize();
} else if (plan instanceof MNodePlan) {
node = new MNode(null, ((MNodePlan) plan).getName());
childrenSize = ((MNodePlan) plan).getChildSize();
}
Copy link
Member

Choose a reason for hiding this comment

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

The XXMNodePlan is almost the same as the XXMNode, the structure is not a problem. But creating or recovering a snapshot may be slower in this way. Better to test the performance. If the performance does not decrease a lot, this is acceptable. We could test 10M timeseries (10000 device * 1000 measurement)

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, I will do some tests.

Copy link
Member Author

@mychaow mychaow Sep 17, 2020

Choose a reason for hiding this comment

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

I have done some tests, 1M timeseries, the cpu cost it almost same.

new FileWriter(SystemFileFactory.INSTANCE.getFile(snapshotPath)))) {
root.serializeTo(bw);
try (MLogWriter mLogWriter = new MLogWriter(snapshotPath)) {
root.serializeTo(mLogWriter);
Copy link
Member

Choose a reason for hiding this comment

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

Pay attention to force mLogWriter before close it.

@mychaow mychaow force-pushed the mlog branch 2 times, most recently from c9db0fe to 72e188c Compare September 27, 2020 06:35
@HTHou
Copy link
Contributor

HTHou commented Oct 10, 2020

There are some conflicts now, please take a look and fix them.

@mychaow
Copy link
Member Author

mychaow commented Oct 12, 2020

There are some conflicts now, please take a look and fix them.

fix

@mychaow mychaow force-pushed the mlog branch 2 times, most recently from 3fd3e5a to 5491c8c Compare October 12, 2020 11:30
@HTHou HTHou added rel/0.11 and removed rel/0.11 labels Oct 26, 2020
@mychaow mychaow marked this pull request as draft November 18, 2020 06:16
@mychaow mychaow force-pushed the mlog branch 2 times, most recently from df0282f to 7a5ad6d Compare November 20, 2020 02:37
@mychaow mychaow marked this pull request as ready for review November 20, 2020 03:41
@mychaow mychaow requested a review from qiaojialin November 20, 2020 03:52
@mychaow mychaow added the Module - Schema MManager label Nov 20, 2020
Copy link
Contributor

@samperson1997 samperson1997 left a comment

Choose a reason for hiding this comment

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

Hi @mychaow , the parser is quite convenient and I really appreciate your work. Here I have some questions about the details, please have a look ; )

if (!properties.containsKey(IOTDB_VERSION_STRING)) {
logger.error("DO NOT UPGRADE IoTDB from v0.9 or lower version to v0.11!"
+ " Please upgrade to v0.10 first");
// check whether upgrading from v0.9 to v0.12
Copy link
Member

Choose a reason for hiding this comment

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

from <=0.10 to 0.12

Copy link
Member

@qiaojialin qiaojialin left a comment

Choose a reason for hiding this comment

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

There is not a thread to do the periodic Channel.force(true) for MLogWriter, is this meet our expectation?

* Size of log buffer for every MetaData operation. If the size of a MetaData operation plan
* is larger than this parameter, then the MetaData operation plan will be rejected by MManager.
*/
private int mlogBufferSize = 1024 * 1024;
Copy link
Member

Choose a reason for hiding this comment

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

make this consistent with iotdb-engine.properties?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is not a thread to do the periodic Channel.force(true) for MLogWriter, is this meet our expectation?

Not,just when we use thread pool to write, and we call shutdown to interrupt the thread, see this
https://stackoverflow.com/questions/1161297/why-are-we-getting-closedbyinterruptexception-from-filechannel-map-in-java-1-6

logFile = SystemFileFactory.INSTANCE.getFile(logFilePath);
this.forcePeriodInMs = forcePeriodInMs;

if (channel == null) {
Copy link
Member

Choose a reason for hiding this comment

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

this is always true, said by idea..

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, but I think add a check is not redundancy

this.logFile = logFile;
this.forcePeriodInMs = forcePeriodInMs;

if (channel == null) {
Copy link
Member

Choose a reason for hiding this comment

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

this is always true, said by idea..

IoTDBDescriptor.getInstance().getConfig().getMlogBufferSize());

// we write log to channel every time, so we need not to call channel.force every time
private static final long DUMMY_FLUSH_TIME = 100;
Copy link
Member

Choose a reason for hiding this comment

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

The function of this field is the same with a boolean

}

public LogWriter(File logFile) {
public LogWriter(File logFile, long forcePeriodInMs) throws FileNotFoundException {
Copy link
Member

Choose a reason for hiding this comment

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

The actual usage of 'forcePeriodInMs' parameter is a boolean 'forceAtEachWrite'

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that, wal use this to optimize the performance after hundreds of milliseconds.

Comment on lines +81 to +82
CHANGE_TAG_OFFSET, CHANGE_ALIAS, MNODE,
MEASUREMENT_MNODE, STORAGE_GROUP_MNODE;
Copy link
Member

Choose a reason for hiding this comment

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

This could be removed, the operator is only generated in SQL parser.

Copy link
Member Author

Choose a reason for hiding this comment

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

I use them to unify the wal and mlog, for deserializing the log.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@qiaojialin qiaojialin merged commit a75b722 into apache:master Dec 14, 2020
@mychaow mychaow deleted the mlog branch December 15, 2020 07:20
@fanhualta fanhualta mentioned this pull request Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants