You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/06/05 04:43:10 UTC
[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #1315: [IOTDB-744] Support upsert alias
JackieTien97 commented on a change in pull request #1315:
URL: https://github.com/apache/incubator-iotdb/pull/1315#discussion_r435686688
##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
##########
@@ -1010,62 +1031,97 @@ public void changeOffset(String path, long offset) throws MetadataException {
}
}
+ public void changeAlias(String path, String alias) throws MetadataException {
+ lock.writeLock().lock();
+ try {
+ LeafMNode leafMNode = (LeafMNode) mtree.getNodeByPath(path);
+ leafMNode.getParent().deleteAliasChild(leafMNode.getAlias());
+ leafMNode.getParent().addAlias(alias, leafMNode);
+ leafMNode.setAlias(alias);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
/**
* upsert tags and attributes key-value for the timeseries if the key has existed, just use the
* new value to update it.
*
+ * @param alias newly added alias
* @param tagsMap newly added tags map
* @param attributesMap newly added attributes map
* @param fullPath timeseries
*/
- public void upsertTagsAndAttributes(
- Map<String, String> tagsMap, Map<String, String> attributesMap, String fullPath)
- throws MetadataException, IOException {
+ public void upsertTagsAndAttributes(String alias, Map<String, String> tagsMap,
+ Map<String, String> attributesMap, String fullPath) throws MetadataException, IOException {
lock.writeLock().lock();
try {
MNode mNode = mtree.getNodeByPath(fullPath);
if (!(mNode instanceof LeafMNode)) {
throw new PathNotExistException(fullPath);
}
LeafMNode leafMNode = (LeafMNode) mNode;
+ // upsert alias
+ if (alias != null) {
+ if (leafMNode.getParent().hasChild(alias)) {
+ throw new MetadataException("The alias already exits.");
+ }
+ if (leafMNode.getAlias() != null) {
+ leafMNode.getParent().deleteAliasChild(leafMNode.getAlias());
+ leafMNode.getParent().addAlias(alias, leafMNode);
+ leafMNode.setAlias(alias);
+ // persist to WAL
+ logWriter.changeAlias(fullPath, alias);
+ }
+ }
+ //
+ 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 = tagLogFile.write(tagsMap, attributesMap);
logWriter.changeOffset(fullPath, offset);
leafMNode.setOffset(offset);
// update inverted Index map
- for (Entry<String, String> entry : tagsMap.entrySet()) {
- tagIndex.computeIfAbsent(entry.getKey(), k -> new HashMap<>())
- .computeIfAbsent(entry.getValue(), v -> new HashSet<>()).add(leafMNode);
+ if (tagsMap != null) {
Review comment:
Yes, Or the `tagsMap.entrySet()` will throw NullPointerException
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org