Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ddlStatement
| setSchemaTemplate | unsetSchemaTemplate
| alterSchemaTemplate
// TTL
| setTTL | unsetTTL | showAllTTL
| setTTL | unsetTTL | showTTL | showAllTTL
// Function
| createFunction | dropFunction | showFunctions
// Trigger
Expand Down Expand Up @@ -325,6 +325,11 @@ unsetTTL
: UNSET TTL TO path=prefixPath
;

// ---- Show TTL
showTTL
: SHOW TTL ON prefixPath (COMMA prefixPath)*
;

// ---- Show All TTL
showAllTTL
: SHOW ALL TTL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@

import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
import org.apache.iotdb.db.utils.constant.SqlConstant;

import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

public class ShowTTLPlan extends ConfigPhysicalPlan {
private String[] pathPattern;

public String[] getPathPattern() {
return pathPattern;
}

public ShowTTLPlan() {
super(ConfigPhysicalPlanType.ShowTTL);
this.pathPattern = SqlConstant.getSingleRootArray();
}

public ShowTTLPlan(String[] pathPattern) {
super(ConfigPhysicalPlanType.ShowTTL);
this.pathPattern = pathPattern;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ public DataSet getMatchedDatabaseSchemas(GetDatabasePlan getDatabaseReq) {
}

@Override
public DataSet showAllTTL(ShowTTLPlan showTTLPlan) {
public DataSet showTTL(ShowTTLPlan showTTLPlan) {
TSStatus status = confirmLeader();
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return ttlManager.showAllTTL(showTTLPlan);
return ttlManager.showTTL(showTTLPlan);
} else {
ShowTTLResp resp = new ShowTTLResp();
resp.setStatus(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public interface IManager {

TSStatus setTTL(SetTTLPlan configRequest);

DataSet showAllTTL(ShowTTLPlan showTTLPlan);
DataSet showTTL(ShowTTLPlan showTTLPlan);

TSStatus setSchemaReplicationFactor(SetSchemaReplicationFactorPlan configPhysicalPlan);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public TSStatus unsetTTL(SetTTLPlan setTTLPlan, final boolean isGeneratedByPipe)
return configManager.getProcedureManager().setTTL(setTTLPlan, isGeneratedByPipe);
}

public DataSet showAllTTL(ShowTTLPlan showTTLPlan) {
public DataSet showTTL(ShowTTLPlan showTTLPlan) {
try {
return configManager.getConsensusManager().read(showTTLPlan);
} catch (ConsensusException e) {
Expand All @@ -133,7 +133,7 @@ public DataSet showAllTTL(ShowTTLPlan showTTLPlan) {
}

public Map<String, Long> getAllTTL() {
return ((ShowTTLResp) showAllTTL(new ShowTTLPlan())).getPathTTLMap();
return ((ShowTTLResp) showTTL(new ShowTTLPlan())).getPathTTLMap();
}

public int getTTLCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.iotdb.commons.snapshot.SnapshotProcessor;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.confignode.consensus.request.read.ttl.ShowTTLPlan;
import org.apache.iotdb.confignode.consensus.request.write.database.SetTTLPlan;
import org.apache.iotdb.confignode.consensus.response.ttl.ShowTTLResp;
import org.apache.iotdb.rpc.RpcUtils;
Expand All @@ -43,6 +44,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -118,12 +120,19 @@ public TSStatus unsetTTL(SetTTLPlan plan) {
return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
}

public ShowTTLResp showAllTTL() {
public ShowTTLResp showTTL(ShowTTLPlan plan) {
ShowTTLResp resp = new ShowTTLResp();
Map<String, Long> pathTTLMap;
Map<String, Long> pathTTLMap = new HashMap<>();
lock.readLock().lock();
try {
pathTTLMap = ttlCache.getAllPathTTL();
PartialPath pathPattern = new PartialPath(plan.getPathPattern());
for (Map.Entry<String[], Long> entry : ttlCache.getAllTTLs().entrySet()) {
if (pathPattern.matchFullPath(entry.getKey())) {
pathTTLMap.put(
String.join(String.valueOf(IoTDBConstant.PATH_SEPARATOR), entry.getKey()),
entry.getValue());
}
}
} finally {
lock.readLock().unlock();
}
Expand Down Expand Up @@ -175,6 +184,8 @@ public void processLoadSnapshot(File snapshotDir) throws TException, IOException
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream)) {
ttlCache.clear();
ttlCache.deserialize(bufferedInputStream);
} catch (IllegalPathException e) {
throw new IOException(e);
} finally {
lock.writeLock().unlock();
}
Expand All @@ -190,7 +201,9 @@ public boolean equals(Object o) {
}
TTLInfo other = (TTLInfo) o;
return this.getTTLCount() == other.getTTLCount()
&& this.showAllTTL().getPathTTLMap().equals(other.showAllTTL().getPathTTLMap());
&& this.showTTL(new ShowTTLPlan())
.getPathTTLMap()
.equals(other.showTTL(new ShowTTLPlan()).getPathTTLMap());
Comment thread
jt2594838 marked this conversation as resolved.
Resolved
}

@TestOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.iotdb.confignode.consensus.request.read.trigger.GetTriggerJarPlan;
import org.apache.iotdb.confignode.consensus.request.read.trigger.GetTriggerLocationPlan;
import org.apache.iotdb.confignode.consensus.request.read.trigger.GetTriggerTablePlan;
import org.apache.iotdb.confignode.consensus.request.read.ttl.ShowTTLPlan;
import org.apache.iotdb.confignode.consensus.request.write.confignode.ApplyConfigNodePlan;
import org.apache.iotdb.confignode.consensus.request.write.confignode.RemoveConfigNodePlan;
import org.apache.iotdb.confignode.consensus.request.write.confignode.UpdateClusterIdPlan;
Expand Down Expand Up @@ -310,7 +311,7 @@ public DataSet executeQueryPlan(ConfigPhysicalPlan req)
case ShowPipeV2:
return pipeInfo.getPipeTaskInfo().showPipes();
case ShowTTL:
return ttlInfo.showAllTTL();
return ttlInfo.showTTL((ShowTTLPlan) req);
case ShowTopic:
return subscriptionInfo.showTopics();
case ShowSubscription:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.iotdb.commons.schema.node.role.IDatabaseMNode;
import org.apache.iotdb.commons.schema.node.utils.IMNodeFactory;
import org.apache.iotdb.commons.utils.AuthUtils;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.ThriftConfigNodeSerDeUtils;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
Expand All @@ -38,7 +39,6 @@
import org.apache.iotdb.db.schemaengine.template.Template;

import org.apache.commons.io.IOUtils;
import org.apache.tsfile.common.constant.TsFileConstant;
import org.apache.tsfile.utils.Pair;
import org.apache.tsfile.utils.ReadWriteIOUtils;
import org.slf4j.Logger;
Expand All @@ -60,7 +60,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Stack;

import static org.apache.iotdb.commons.conf.IoTDBConstant.PATH_ROOT;
Expand Down Expand Up @@ -277,13 +276,11 @@ private void generateSetTTLPlan() {
while (size > 0) {
String path = ReadWriteIOUtils.readString(ttlInputStream);
long ttl = ReadWriteIOUtils.readLong(ttlInputStream);
planDeque.add(
new SetTTLPlan(
Objects.requireNonNull(path).split(TsFileConstant.PATH_SEPARATER_NO_REGEX), ttl));
planDeque.add(new SetTTLPlan(PathUtils.splitPathToDetachedNodes(path), ttl));
size--;
}
} catch (IOException e) {
logger.error("Got IOException when deserializing ttl file", e);
} catch (IOException | IllegalPathException e) {
logger.error("Got exception when deserializing ttl file", e);
latestException = e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.iotdb.common.rpc.thrift.TSetTTLReq;
import org.apache.iotdb.common.rpc.thrift.TSetThrottleQuotaReq;
import org.apache.iotdb.common.rpc.thrift.TShowConfigurationResp;
import org.apache.iotdb.common.rpc.thrift.TShowTTLReq;
import org.apache.iotdb.common.rpc.thrift.TTestConnectionResp;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.consensus.ConsensusGroupId;
Expand Down Expand Up @@ -494,8 +495,10 @@ public TDatabaseSchemaResp getMatchedDatabaseSchemas(TGetDatabaseReq req) {
}

@Override
public TShowTTLResp showAllTTL() {
ShowTTLResp showTTLResp = (ShowTTLResp) configManager.showAllTTL(new ShowTTLPlan());
public TShowTTLResp showTTL(TShowTTLReq req) {
ShowTTLResp showTTLResp =
(ShowTTLResp)
configManager.showTTL(new ShowTTLPlan(req.getPathPattern().toArray(new String[0])));
return showTTLResp.convertToRPCTShowTTLResp();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.confignode.consensus.request.read.ttl.ShowTTLPlan;
import org.apache.iotdb.confignode.consensus.request.write.database.SetTTLPlan;
import org.apache.iotdb.confignode.consensus.response.ttl.ShowTTLResp;

Expand Down Expand Up @@ -68,7 +69,7 @@ public void tearDown() throws IOException {

@Test
public void testSetAndUnsetTTL() throws IllegalPathException {
ShowTTLResp resp = ttlInfo.showAllTTL();
ShowTTLResp resp = ttlInfo.showTTL(new ShowTTLPlan());
Map<String, Long> ttlMap = resp.getPathTTLMap();

Map<String, Long> resultMap = new HashMap<>();
Expand All @@ -80,125 +81,125 @@ public void testSetAndUnsetTTL() throws IllegalPathException {
PartialPath path = new PartialPath("root.test.db1.**");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 121322323L));
resultMap.put(path.getFullPath(), 121322323L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(2, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test.db1.group1.group1.d1");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 2222L));
resultMap.put(path.getFullPath(), 2222L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(3, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test.db1.group1.group2.d1");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 1));
resultMap.put(path.getFullPath(), 1L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(4, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test1.db1.group1.group2.d1");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 599722L));
resultMap.put(path.getFullPath(), 599722L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(5, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test1.db1.group1.group2.d1.**");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 9999999L));
resultMap.put(path.getFullPath(), 9999999L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(6, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test1.db1.group1.group2.d1.d2.**");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 888888L));
resultMap.put(path.getFullPath(), 888888L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(7, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test1.db1.group1.group2.d1.d2");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 9898989898L));
resultMap.put(path.getFullPath(), 9898989898L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(8, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test.db1.group1.group2.d1");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 11111222L));
resultMap.put(path.getFullPath(), 11111222L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(8, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.test.db1.group1");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), Long.MAX_VALUE));
resultMap.put(path.getFullPath(), Long.MAX_VALUE);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(9, ttlInfo.getTTLCount());

// set ttl
path = new PartialPath("root.**");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 222222L));
resultMap.put(path.getFullPath(), 222222L);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(9, ttlInfo.getTTLCount());

// set ttl, not support negative ttl
path = new PartialPath("root.test.db1.group1.group2");
ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(9, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.test.db1.group1.group2");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.remove(path.getFullPath());
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(9, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.test.db1.group1");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.remove(path.getFullPath());
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(8, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.**");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.put(path.getFullPath(), ttl);
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(8, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.test1.db1.group1.group2.d1.d2");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.remove(path.getFullPath());
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(7, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.test.db1.**");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.remove(path.getFullPath());
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(6, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.test1.db1.group1.group2.d1");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.remove(path.getFullPath());
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(5, ttlInfo.getTTLCount());

// unset ttl
path = new PartialPath("root.test1.db1.group1.group2.d1.d2.**");
ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), -1));
resultMap.remove(path.getFullPath());
Assert.assertEquals(resultMap, ttlInfo.showAllTTL().getPathTTLMap());
Assert.assertEquals(resultMap, ttlInfo.showTTL(new ShowTTLPlan()).getPathTTLMap());
Assert.assertEquals(4, ttlInfo.getTTLCount());
}

Expand Down
Loading