@Test public void testSetStorageGroup() throws IllegalPathException { MTree root = new MTree(); try { root.setStorageGroup(new PartialPath("root.laptop.d1")); assertTrue(root.isPathExist(new PartialPath("root.laptop.d1"))); assertTrue(root.checkStorageGroupByPath(new PartialPath("root.laptop.d1"))); assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1")).getFullPath()); assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s1"))); assertTrue(root.checkStorageGroupByPath(new PartialPath("root.laptop.d1.s1"))); assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1.s1")).getFullPath()); } catch (MetadataException e) { e.printStackTrace(); fail(e.getMessage()); } try { root.setStorageGroup(new PartialPath("root.laptop.d2")); } catch (MetadataException e) { fail(e.getMessage()); } try { root.setStorageGroup(new PartialPath("root.laptop")); } catch (MetadataException e) { Assert.assertEquals( "root.laptop has already been set to storage group", e.getMessage()); } assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s0"))); assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s1"))); assertFalse(root.isPathExist(new PartialPath("root.laptop.d2.s0"))); assertFalse(root.isPathExist(new PartialPath("root.laptop.d2.s1"))); try { assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1.s0")).getFullPath()); root.createTimeseries(new PartialPath("root.laptop.d1.s0"), TSDataType.INT32, TSEncoding.RLE, TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null); assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1.s1")).getFullPath()); root.createTimeseries(new PartialPath("root.laptop.d1.s1"), TSDataType.INT32, TSEncoding.RLE, TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null); assertEquals("root.laptop.d2", root.getStorageGroupPath(new PartialPath("root.laptop.d2.s0")).getFullPath()); root.createTimeseries(new PartialPath("root.laptop.d2.s0"), TSDataType.INT32, TSEncoding.RLE, TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null); assertEquals("root.laptop.d2", root.getStorageGroupPath(new PartialPath("root.laptop.d2.s1")).getFullPath()); root.createTimeseries(new PartialPath("root.laptop.d2.s1"), TSDataType.INT32, TSEncoding.RLE, TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null); } catch (MetadataException e) { e.printStackTrace(); fail(e.getMessage()); } try { root.deleteTimeseriesAndReturnEmptyStorageGroup(new PartialPath("root.laptop.d1.s0")); } catch (MetadataException e) { e.printStackTrace(); fail(e.getMessage()); } assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s0"))); try { root.deleteStorageGroup(new PartialPath("root.laptop.d1")); } catch (MetadataException e) { e.printStackTrace(); fail(e.getMessage()); } assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s1"))); assertFalse(root.isPathExist(new PartialPath("root.laptop.d1"))); assertTrue(root.isPathExist(new PartialPath("root.laptop"))); assertTrue(root.isPathExist(new PartialPath("root.laptop.d2"))); assertTrue(root.isPathExist(new PartialPath("root.laptop.d2.s0"))); }
void setStorageGroup(PartialPath path) throws MetadataException { String[] nodeNames = path.getNodes(); checkStorageGroup(path.getFullPath()); MNode cur = root; if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) { throw new IllegalPathException(path.getFullPath()); } int i = 1; while (i < nodeNames.length - 1) { MNode temp = cur.getChild(nodeNames[i]); if (temp == null) { cur.addChild(nodeNames[i], new MNode(cur, nodeNames[i])); } else if (temp instanceof StorageGroupMNode) { throw new StorageGroupAlreadySetException(temp.getFullPath()); } cur = cur.getChild(nodeNames[i]); i++; } if (cur.hasChild(nodeNames[i])) { throw new StorageGroupAlreadySetException(path.getFullPath()); } else { StorageGroupMNode storageGroupMNode = new StorageGroupMNode( cur, nodeNames[i], IoTDBDescriptor.getInstance().getConfig().getDefaultTTL()); cur.addChild(nodeNames[i], storageGroupMNode); } }
MTree implements Serializable { void setStorageGroup(PartialPath path) throws MetadataException { String[] nodeNames = path.getNodes(); checkStorageGroup(path.getFullPath()); MNode cur = root; if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) { throw new IllegalPathException(path.getFullPath()); } int i = 1; while (i < nodeNames.length - 1) { MNode temp = cur.getChild(nodeNames[i]); if (temp == null) { cur.addChild(nodeNames[i], new MNode(cur, nodeNames[i])); } else if (temp instanceof StorageGroupMNode) { throw new StorageGroupAlreadySetException(temp.getFullPath()); } cur = cur.getChild(nodeNames[i]); i++; } if (cur.hasChild(nodeNames[i])) { throw new StorageGroupAlreadySetException(path.getFullPath()); } else { StorageGroupMNode storageGroupMNode = new StorageGroupMNode( cur, nodeNames[i], IoTDBDescriptor.getInstance().getConfig().getDefaultTTL()); cur.addChild(nodeNames[i], storageGroupMNode); } } }
MTree implements Serializable { void setStorageGroup(PartialPath path) throws MetadataException { String[] nodeNames = path.getNodes(); checkStorageGroup(path.getFullPath()); MNode cur = root; if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) { throw new IllegalPathException(path.getFullPath()); } int i = 1; while (i < nodeNames.length - 1) { MNode temp = cur.getChild(nodeNames[i]); if (temp == null) { cur.addChild(nodeNames[i], new MNode(cur, nodeNames[i])); } else if (temp instanceof StorageGroupMNode) { throw new StorageGroupAlreadySetException(temp.getFullPath()); } cur = cur.getChild(nodeNames[i]); i++; } if (cur.hasChild(nodeNames[i])) { throw new StorageGroupAlreadySetException(path.getFullPath()); } else { StorageGroupMNode storageGroupMNode = new StorageGroupMNode( cur, nodeNames[i], IoTDBDescriptor.getInstance().getConfig().getDefaultTTL()); cur.addChild(nodeNames[i], storageGroupMNode); } } MTree(); private  MTree(MNode root); }
MTree implements Serializable { void setStorageGroup(PartialPath path) throws MetadataException { String[] nodeNames = path.getNodes(); checkStorageGroup(path.getFullPath()); MNode cur = root; if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) { throw new IllegalPathException(path.getFullPath()); } int i = 1; while (i < nodeNames.length - 1) { MNode temp = cur.getChild(nodeNames[i]); if (temp == null) { cur.addChild(nodeNames[i], new MNode(cur, nodeNames[i])); } else if (temp instanceof StorageGroupMNode) { throw new StorageGroupAlreadySetException(temp.getFullPath()); } cur = cur.getChild(nodeNames[i]); i++; } if (cur.hasChild(nodeNames[i])) { throw new StorageGroupAlreadySetException(path.getFullPath()); } else { StorageGroupMNode storageGroupMNode = new StorageGroupMNode( cur, nodeNames[i], IoTDBDescriptor.getInstance().getConfig().getDefaultTTL()); cur.addChild(nodeNames[i], storageGroupMNode); } } MTree(); private  MTree(MNode root); void serializeTo(String snapshotPath); @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning static MTree deserializeFrom(File mtreeSnapshot); @Override String toString(); }
MTree implements Serializable { void setStorageGroup(PartialPath path) throws MetadataException { String[] nodeNames = path.getNodes(); checkStorageGroup(path.getFullPath()); MNode cur = root; if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) { throw new IllegalPathException(path.getFullPath()); } int i = 1; while (i < nodeNames.length - 1) { MNode temp = cur.getChild(nodeNames[i]); if (temp == null) { cur.addChild(nodeNames[i], new MNode(cur, nodeNames[i])); } else if (temp instanceof StorageGroupMNode) { throw new StorageGroupAlreadySetException(temp.getFullPath()); } cur = cur.getChild(nodeNames[i]); i++; } if (cur.hasChild(nodeNames[i])) { throw new StorageGroupAlreadySetException(path.getFullPath()); } else { StorageGroupMNode storageGroupMNode = new StorageGroupMNode( cur, nodeNames[i], IoTDBDescriptor.getInstance().getConfig().getDefaultTTL()); cur.addChild(nodeNames[i], storageGroupMNode); } } MTree(); private  MTree(MNode root); void serializeTo(String snapshotPath); @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning static MTree deserializeFrom(File mtreeSnapshot); @Override String toString(); static final Gson GSON; }