Skip to content

Commit

Permalink
Add SchemaRegion Interfaces to SchemaEngine (#5349)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosZyk authored Mar 28, 2022
1 parent bbfa720 commit b103385
Show file tree
Hide file tree
Showing 70 changed files with 1,746 additions and 1,082 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,6 @@ public boolean isPathExist(PartialPath path) {
}
}

@Override
protected IMNode getDeviceNodeWithAutoCreate(PartialPath path)
throws MetadataException, IOException {
return getDeviceNodeWithAutoCreate(
path,
ClusterDescriptor.getInstance().getConfig().isEnableAutoCreateSchema(),
false,
config.getDefaultStorageGroupLevel());
}

private static class RemoteMetaCache extends LRUCache<PartialPath, IMeasurementMNode> {

RemoteMetaCache(int cacheSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public class AsyncDataLogApplierTest {
public void setUp() throws Exception {
logsToApply = new ArrayList<>();
appliedLogs = new ConcurrentSkipListSet<>();
IoTDB.schemaEngine.init();
IoTDB.configManager.init();
for (int i = 0; i < 10; i++) {
IoTDB.schemaEngine.setStorageGroup(new PartialPath(TestUtils.getTestSg(i)));
}
}

@After
public void tearDown() throws IOException {
IoTDB.schemaEngine.clear();
IoTDB.configManager.clear();
EnvironmentUtils.cleanAllDir();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private boolean dummyMatchTerm(long index, long term) {

@Before
public void setUp() {
IoTDB.schemaEngine.init();
IoTDB.configManager.init();
prevUseAsyncServer = ClusterDescriptor.getInstance().getConfig().isUseAsyncServer();
ClusterDescriptor.getInstance().getConfig().setUseAsyncServer(true);
receivedLogs = new ArrayList<>();
Expand All @@ -197,7 +197,7 @@ public void setUp() {

@After
public void tearDown() throws Exception {
IoTDB.schemaEngine.clear();
IoTDB.configManager.clear();
sender.stop();
sender.closeLogManager();
EnvironmentUtils.cleanAllDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static SchemaEngine newSchemaEngine(String logFilePath) {
SchemaEngine schemaEngine = constructor.newInstance();
new File(logFilePath).getParentFile().mkdirs();
Whitebox.setInternalState(schemaEngine, "logFilePath", logFilePath);
schemaEngine.initForMultiSchemaEngineTest();
// schemaEngine.initForMultiSchemaEngineTest();
return schemaEngine;
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void setUp() throws MetadataException {
prevPartitionInterval = StorageEngine.getTimePartitionInterval();
StorageEngine.setEnablePartition(true);

IoTDB.schemaEngine.init();
IoTDB.configManager.init();
StorageEngine.setTimePartitionInterval(7 * 24 * 3600 * 1000L);
nodes = new ArrayList<>();
IntStream.range(0, 20).forEach(i -> nodes.add(getNode(i)));
Expand Down Expand Up @@ -175,7 +175,7 @@ public void tearDown() throws IOException, StorageEngineException {
ClusterDescriptor.getInstance().getConfig().setReplicationNum(prevReplicaNum);
if (schemaEngines != null) {
for (SchemaEngine schemaEngine : schemaEngines) {
schemaEngine.clear();
// schemaEngine.clear();
}
}
EnvironmentUtils.cleanEnv();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testSaveTimeEncoderToSystemProperties() throws Exception {
public void testAlterTimeEncoderAfterStartService() throws Exception {
EnvironmentUtils.shutdownDaemon();
EnvironmentUtils.stopDaemon();
IoTDB.schemaEngine.clear();
IoTDB.configManager.clear();
systemProperties.put("time_encoder", "REGULAR");
writeSystemFile();
EnvironmentUtils.reactiveDaemon();
Expand All @@ -123,7 +123,7 @@ public void testAlterTimeEncoderAfterStartService() throws Exception {
public void testSameTimeEncoderAfterStartService() throws Exception {
EnvironmentUtils.shutdownDaemon();
EnvironmentUtils.stopDaemon();
IoTDB.schemaEngine.clear();
IoTDB.configManager.clear();
systemProperties.put("time_encoder", "TS_2DIFF");
writeSystemFile();
EnvironmentUtils.reactiveDaemon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.iotdb.itbase.category.LocalStandaloneTest;
import org.apache.iotdb.itbase.category.RemoteTest;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -45,7 +43,6 @@
import java.util.HashSet;
import java.util.Set;

import static org.apache.iotdb.db.metadata.SchemaEngine.TIME_SERIES_TREE_HEADER;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -222,19 +219,6 @@ public void showStorageGroupTest() throws SQLException {
}
}

@Test
@Category({LocalStandaloneTest.class})
public void databaseMetaDataTest() throws SQLException {
try (Connection connection = EnvFactory.getEnv().getConnection()) {
databaseMetaData = connection.getMetaData();
showTimeseriesInJson();

} catch (Exception e) {
logger.error("databaseMetaDataTest() failed", e);
fail(e.getMessage());
}
}

@Test
@Category({LocalStandaloneTest.class})
public void showVersionTest() throws SQLException {
Expand Down Expand Up @@ -605,25 +589,6 @@ public void showCountNodes() throws SQLException {
}
}

/** show metadata in json */
private void showTimeseriesInJson() {
String metadataInJson = databaseMetaData.toString();
String standard =
"=== Timeseries Tree ===\n"
+ "\n"
+ "{\"root\":{\"ln2\":{\"wf01\":{\"wt01\":{\"temperature\":{\"DataType\":\"FLOAT\",\"Encoding\":\"RLE\",\"Compressor\":\"SNAPPY\",\"args\":\"{max_point_number=3}\",\"StorageGroup\":\"root.ln2.wf01.wt01\"},\"status\":{\"DataType\":\"BOOLEAN\",\"Encoding\":\"PLAIN\",\"Compressor\":\"SNAPPY\",\"StorageGroup\":\"root.ln2.wf01.wt01\"}}}},\"ln\":{\"wf01\":{\"wt02\":{\"s1\":{\"DataType\":\"INT32\",\"Encoding\":\"RLE\",\"Compressor\":\"SNAPPY\",\"StorageGroup\":\"root.ln.wf01.wt02\"},\"s2\":{\"DataType\":\"DOUBLE\",\"Encoding\":\"GORILLA\",\"Compressor\":\"SNAPPY\",\"StorageGroup\":\"root.ln.wf01.wt02\"}},\"wt01\":{\"temperature\":{\"DataType\":\"FLOAT\",\"Encoding\":\"RLE\",\"Compressor\":\"SNAPPY\",\"args\":\"{max_point_number=3}\",\"StorageGroup\":\"root.ln.wf01.wt01\"},\"status\":{\"DataType\":\"BOOLEAN\",\"Encoding\":\"PLAIN\",\"Compressor\":\"SNAPPY\",\"StorageGroup\":\"root.ln.wf01.wt01\"}}}},\"ln1\":{\"wf01\":{\"wt01\":{\"temperature\":{\"DataType\":\"FLOAT\",\"Encoding\":\"RLE\",\"Compressor\":\"SNAPPY\",\"args\":\"{max_point_number=3}\",\"StorageGroup\":\"root.ln1.wf01.wt01\"},\"status\":{\"DataType\":\"BOOLEAN\",\"Encoding\":\"PLAIN\",\"Compressor\":\"SNAPPY\",\"StorageGroup\":\"root.ln1.wf01.wt01\"}}}}}}";
// TODO Remove the constant json String.
// Do not depends on the sequence of property in json string if you do not
// explictly mark the sequence, when we use jackson, the json result may change again
String rawJsonString = metadataInJson.substring(TIME_SERIES_TREE_HEADER.length());
Gson gson = new Gson();
JsonObject actual = gson.fromJson(rawJsonString, JsonObject.class);
JsonObject expected =
gson.fromJson(standard.substring(TIME_SERIES_TREE_HEADER.length()), JsonObject.class);

Assert.assertEquals(expected, actual);
}

@Test
@Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
public void showAlignedTimeseriesWithAliasAndTags() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
*/
package org.apache.iotdb.commons.partition;

import java.util.Objects;

public class SchemaRegionId {
private int schemaRegionId;

public SchemaRegionId(int schemaRegionId) {
this.schemaRegionId = schemaRegionId;
}

public int getSchemaRegionId() {
return schemaRegionId;
}
Expand All @@ -29,6 +35,19 @@ public void setSchemaRegionId(int schemaRegionId) {
this.schemaRegionId = schemaRegionId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SchemaRegionId that = (SchemaRegionId) o;
return schemaRegionId == that.schemaRegionId;
}

@Override
public int hashCode() {
return Objects.hash(schemaRegionId);
}

public String toString() {
return String.format("SchemaRegion-%d", schemaRegionId);
}
Expand Down
Loading

0 comments on commit b103385

Please sign in to comment.