-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support ttl for vertex and edge #794
Conversation
Codecov Report
@@ Coverage Diff @@
## master #794 +/- ##
============================================
+ Coverage 69.72% 70.04% +0.31%
- Complexity 5126 5255 +129
============================================
Files 320 324 +4
Lines 24853 25433 +580
Branches 3466 3559 +93
============================================
+ Hits 17329 17814 +485
- Misses 5861 5916 +55
- Partials 1663 1703 +40
Continue to review full report at Codecov.
|
@@ -116,4 +116,8 @@ public boolean supportsNumberType() { | |||
public boolean supportsAggregateProperty() { | |||
return false; | |||
} | |||
|
|||
@Override public boolean supportsTtl() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap line after @OverRide
int ttl = ttl(entry); | ||
if (ttl != 0) { | ||
update.using(QueryBuilder.ttl(ttl)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer add a static method setTtl(statment, entry)
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of(); | ||
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of( | ||
HugeKeys.EXPIRED_TIME, DataType.decimal() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to store a column of data for EXPIRED_TIME if the backend supports ttl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't get ttl along with existing query statement. Using extra query degrades performance
if (index == null) { | ||
// Index is expired | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather determine here whether it is expired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
element_ids may have different ttl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to change HugeIndex struct
public static final ConfigOption<Integer> EXPIRED_DELETE_BATCH = | ||
new ConfigOption<>( | ||
"expired.delete_batch", | ||
"Whether to delete expired object synchronously.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update description
if (this.deleteTemplate != null) { | ||
protected String buildDeleteTemplate(List<HugeKeys> idNames, | ||
Long expiredTime) { | ||
boolean cached; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to updateCache
protected String buildDeleteTemplate(List<HugeKeys> idNames) { | ||
if (this.deleteTemplate != null) { | ||
protected String buildDeleteTemplate(List<HugeKeys> idNames, | ||
Long expiredTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long
} else { | ||
cached = false; | ||
// Set delete with ttl to avoid mistaken deletion | ||
idNames.add(HugeKeys.EXPIRED_TIME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why EXPIRED_TIME is in idNames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it
@@ -118,4 +118,8 @@ public boolean supportsNumberType() { | |||
public boolean supportsAggregateProperty() { | |||
return false; | |||
} | |||
|
|||
@Override public boolean supportsTtl() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -45,5 +45,7 @@ palo.host=localhost | |||
|
|||
snowflake.force_string=true | |||
schema.sync_deletion=true | |||
expired.sync_deletion=true | |||
expired.delete_batch=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new ConfigOption<>( | ||
"expired.sync_deletion", | ||
"Whether to delete expired object synchronously.", | ||
"sync_deletion", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task.sync_deletion
disallowEmpty(), | ||
false | ||
); | ||
|
||
public static final ConfigOption<Integer> EXPIRED_DELETE_BATCH = | ||
new ConfigOption<>( | ||
"expired.delete_batch", | ||
"Whether to delete expired object synchronously.", | ||
"The batch size used to delete expired data.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reuse COMMIT_BATCH?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it
@@ -166,6 +171,8 @@ public void init(CassandraSessionPool.Session session) { | |||
.put(HugeKeys.ENABLE_LABEL_INDEX, DataType.cboolean()) | |||
.put(HugeKeys.USER_DATA, TYPE_UD) | |||
.put(HugeKeys.STATUS, DataType.tinyint()) | |||
.put(HugeKeys.TTL, DataType.cint()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define TYPE_TTL
@@ -294,7 +301,8 @@ public void init(CassandraSessionPool.Session session) { | |||
HugeKeys.OTHER_VERTEX, TYPE_ID | |||
); | |||
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of( | |||
HugeKeys.PROPERTIES, DataType.map(TYPE_PK, TYPE_PROP) | |||
HugeKeys.PROPERTIES, DataType.map(TYPE_PK, TYPE_PROP), | |||
HugeKeys.EXPIRED_TIME, DataType.decimal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define TYPE_EXPIRED_TIME as long
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of(); | ||
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of( | ||
HugeKeys.EXPIRED_TIME, DataType.decimal() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
if (!graph.graphTransaction().store().features().supportsTtl() && | ||
!query.showExpired() && | ||
index.expiredTime() != 0L && index.expiredTime() < now) { | ||
GraphTransaction.asyncDeleteExpiredObject(graph, index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -437,5 +437,9 @@ public boolean supportsNumberType() { | |||
public boolean supportsAggregateProperty() { | |||
return false; | |||
} | |||
|
|||
@Override public boolean supportsTtl() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap line, check all "@OverRide public"
@@ -189,6 +193,10 @@ protected void updateIndex(Id ilId, HugeElement element, boolean removed) { | |||
// Not build index for record with nullable field except unique index | |||
List<Object> propValues = allPropValues.subList(0, firstNullField); | |||
|
|||
// Expired time | |||
long expiredTime = element.type().isEdge() ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it's better to keep compatible with Vertex
if (index == null) { | ||
// Index is expired | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to change HugeIndex struct
protected String buildDeleteTemplate(List<HugeKeys> idNames, | ||
Long expiredTime) { | ||
boolean updateCache; | ||
if (expiredTime == null || expiredTime == 0L) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have to use expiredTime == null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it
481d343
to
be2c284
Compare
|
||
public Set<IdWithExpiredTime> expiredElementIds() { | ||
long now = DateUtil.now().getTime(); | ||
Set<IdWithExpiredTime> expired = new LinkedHashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InsertionOrderUtil.newSet(this.elementIds.size())
public Set<Id> elementIds() { | ||
return Collections.unmodifiableSet(this.elementIds); | ||
Set<Id> ids = new LinkedHashSet<>(this.elementIds.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InsertionOrderUtil.newSet(this.elementIds.size())
I will add method InsertionOrderUtil.newSet(int size) to common
@@ -187,7 +188,7 @@ private void unlistenChanges() { | |||
|
|||
return results; | |||
} | |||
|
|||
@SuppressWarnings("unchecked") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing empty line
if (survivedEdges.size() < edges.size()) { | ||
edges = survivedEdges; | ||
} | ||
if (edges.size() <= MAX_CACHE_EDGES_PER_QUERY) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't update cache if unneeded
@@ -569,6 +585,20 @@ private IdHolder doIndexQueryBatch(IndexLabel indexLabel, | |||
}); | |||
} | |||
|
|||
private void removeExpiredIndexIfNeeded(HugeIndex index, | |||
boolean showExpired) { | |||
if (graph().graphTransaction().store().features().supportsTtl() || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.store().features()
@@ -169,17 +184,34 @@ protected void parseRowColumns(Result row, BackendEntry entry, | |||
public static class IndexTable extends HbaseTable { | |||
|
|||
private static final int INDEX_DELETE_BATCH = 1000; | |||
protected HugeType type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final
session.put(this.table(), CF, col.name, | ||
BinarySerializer.EMPTY_BYTES, col.value); | ||
BytesBuffer buffer = BytesBuffer.wrap(col.name); | ||
buffer.readIndexId(this.type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a field ttl to BackendColumn
protected String buildDeleteTemplate(List<HugeKeys> idNames, | ||
Long expiredTime) { | ||
boolean updateCache; | ||
if (expiredTime == null || expiredTime == 0L) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it
} else { | ||
cached = false; | ||
// Set delete with ttl to avoid mistaken deletion | ||
idNames.add(HugeKeys.EXPIRED_TIME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address it
List<HugeKeys> idNames = this.idColumnName(); | ||
String template = this.buildDeleteTemplate(idNames); | ||
|
||
List<HugeKeys> idNames = new ArrayList<>(this.idColumnName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't clone ArrayList here
@@ -101,7 +101,7 @@ | |||
* [0.50] Issue-746: Support userdata for index label | |||
* [0.51] Issue-929: Support 5 TP RESTful API | |||
* [0.52] Issue-781: Support range query for rest api like P.gt(18) | |||
* [0.53] Issue-295: Support ttl for edge label | |||
* [0.53] Issue-295: Support ttl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support ttl for edge and vertex
@Override | ||
public void eliminate(CassandraSessionPool.Session session, | ||
CassandraBackendEntry.Row entry) { | ||
Update append = this.buildEliminate(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: append
and seems no need to set ttl for eliminate
Using usingTtl = QueryBuilder.ttl(ttl); | ||
long ttl = entry.ttl(); | ||
if (ttl != 0L) { | ||
int calcTtl = (int) Math.ceil((double) ttl / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert (double) ttl may loss accuracy, prefer ttl / 1000d
@@ -655,6 +660,8 @@ public static void shutdown(long timeout) { | |||
private final AtomicInteger refs; | |||
// Flag opened of each thread | |||
private final ThreadLocal<Boolean> opened; | |||
// Last time check flag opened of each thread | |||
private final ThreadLocal<Long> lastCheckOpenedTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to Txs class
@@ -707,6 +716,7 @@ public void rollback() { | |||
|
|||
@Override | |||
public boolean isOpen() { | |||
this.lastCheckOpenedTime.set(DateUtil.now().getTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update in setOpened()
private Set<Id> elementIds; | ||
private long expiredTime; | ||
private Set<IdWithExpiredTime> elementIds; | ||
private HugeGraph graph; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final and move to the first line
@Override | ||
public void insert(Session session, BackendEntry entry) { | ||
long ttl = entry.ttl(); | ||
if (ttl == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ttl <= 0L
long expiredTime = BytesBuffer.wrap(col.value).readVLong(); | ||
if (expiredTime == 0) { | ||
long ttl = entry.ttl(); | ||
if (ttl == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
long expiredTime = buffer.readVLong(); | ||
if (expiredTime == 0) { | ||
long ttl = entry.ttl(); | ||
if (ttl == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
if (aggregate == null && !hasOrder) { | ||
select.append(this.orderByKeys()); | ||
} | ||
if (!query.nolimit() || query.offset() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0L
IdQuery newQuery = new IdQuery(HugeType.VERTEX, query); | ||
List<HugeVertex> vertices = new ArrayList<>(); | ||
for (Id vertexId : query.ids()) { | ||
HugeVertex vertex = (HugeVertex) this.verticesCache.get(vertexId); | ||
if (vertex == null) { | ||
if (vertex == null || vertex.expired()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invalid it if expired
@@ -716,7 +712,9 @@ public void rollback() { | |||
|
|||
@Override | |||
public boolean isOpen() { | |||
this.lastCheckOpenedTime.set(DateUtil.now().getTime()); | |||
if (this.transactions.get() != null) { | |||
this.transactions.get().openTime(DateUtil.now().getTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should set in open()
c47e73c
to
df01dc7
Compare
implemented: #295 Change-Id: I16a762c5aa850f14cbd554d29fb8592db87e7619
Change-Id: I8a2a7869136908eb86f9330cbf807eb24a157717
Change-Id: I29f4cfa2fca4b52e0c6a20edaa0885b51e1d2c57
Change-Id: I08e85edbe872480d6bf37019caa832c30d0d8735
Change-Id: I076ba069123ae7e9530d5a5e2f3c6054c781b7a4
Change-Id: If953f7321a424e62c73fea90969588cd8ecb8db6
Change-Id: I2b83062d46906165e9ad8dee385d39fd1c7b71fb
Change-Id: Ie8be022cd19caf53aa59ab65c12266e109d911dc
Change-Id: Ieaff6f73dac21b73696e529f0ba65163239de7b6
Change-Id: Ib64d259c6f4eb67b370b4261a93c40f77fe4a6b1
Change-Id: I886df8c99e80a9514bb6076deac5dca5da177569
Change-Id: Ia00f4811b27048629497d476a25dfc7c5c60470b
Change-Id: Ib3afe8ca6f76d761ba8f0c7140af31ce6c1cbb6c
Change-Id: Iba66cde9ae8152e47830ec6ec9034816a3cc3f7d
Change-Id: I363947c8031ae150a6e769255bc54e0d0db586cb
Change-Id: Ibab2e6034a45cbf808a5a6718c1e42704844cb74
Change-Id: I1b1832e2a55b4587e3a1521d0409765cf849f9f8
Change-Id: Id0efc2bac16fea21f41b9e348ed9d6684ee8034f
<<<<<<< HEAD | ||
======= | ||
* Add a row record to a table with ttl for index | ||
*/ | ||
public void put(String table, byte[] family, byte[] rowkey, | ||
byte[] qualifier, byte[] value, long ttl) { | ||
Put put = new Put(rowkey); | ||
put.addColumn(family, qualifier, value); | ||
put.setTTL(ttl); | ||
this.batch(table, put); | ||
} | ||
|
||
/** | ||
* Delete a record by rowkey and qualifier from a table | ||
*/ | ||
public void remove(String table, byte[] family, | ||
byte[] rowkey, byte[] qualifier) { | ||
this.remove(table, family, rowkey, qualifier, false); | ||
} | ||
|
||
/** | ||
>>>>>>> support edgeLabel ttl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems there is a pair of neglected conflicting code block marks
implemented: #295
Change-Id: I16a762c5aa850f14cbd554d29fb8592db87e7619