...
|
...
|
@@ -177,6 +177,27 @@ public class CassandraBaseTimeseriesDao extends AbstractCassandraBaseTimeseriesD |
177
|
177
|
}
|
178
|
178
|
|
179
|
179
|
@Override
|
|
180
|
+ public ListenableFuture<Integer> savePartition(TenantId tenantId, EntityId entityId, long tsKvEntryTs, String key, long ttl) {
|
|
181
|
+ if (isFixedPartitioning()) {
|
|
182
|
+ return Futures.immediateFuture(null);
|
|
183
|
+ }
|
|
184
|
+ ttl = computeTtl(ttl);
|
|
185
|
+ long partition = toPartitionTs(tsKvEntryTs);
|
|
186
|
+ if (cassandraTsPartitionsCache == null) {
|
|
187
|
+ return doSavePartition(tenantId, entityId, key, ttl, partition);
|
|
188
|
+ } else {
|
|
189
|
+ CassandraPartitionCacheKey partitionSearchKey = new CassandraPartitionCacheKey(entityId, key, partition);
|
|
190
|
+ if (!cassandraTsPartitionsCache.has(partitionSearchKey)) {
|
|
191
|
+ ListenableFuture<Integer> result = doSavePartition(tenantId, entityId, key, ttl, partition);
|
|
192
|
+ Futures.addCallback(result, new CacheCallback<>(partitionSearchKey), MoreExecutors.directExecutor());
|
|
193
|
+ return result;
|
|
194
|
+ } else {
|
|
195
|
+ return Futures.immediateFuture(0);
|
|
196
|
+ }
|
|
197
|
+ }
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ @Override
|
180
|
201
|
public ListenableFuture<Void> remove(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) {
|
181
|
202
|
long minPartition = toPartitionTs(query.getStartTs());
|
182
|
203
|
long maxPartition = toPartitionTs(query.getEndTs());
|
...
|
...
|
@@ -449,47 +470,17 @@ public class CassandraBaseTimeseriesDao extends AbstractCassandraBaseTimeseriesD |
449
|
470
|
return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
|
450
|
471
|
}
|
451
|
472
|
|
452
|
|
- @Override
|
453
|
|
- public ListenableFuture<Integer> savePartition(TenantId tenantId, EntityId entityId, long tsKvEntryTs, String key, long ttl) {
|
454
|
|
- if (isFixedPartitioning()) {
|
455
|
|
- return Futures.immediateFuture(null);
|
456
|
|
- }
|
457
|
|
- ttl = computeTtl(ttl);
|
458
|
|
- long partition = toPartitionTs(tsKvEntryTs);
|
459
|
|
- if (cassandraTsPartitionsCache == null) {
|
460
|
|
- return doSavePartition(tenantId, entityId, key, ttl, partition);
|
461
|
|
- } else {
|
462
|
|
- CassandraPartitionCacheKey partitionSearchKey = new CassandraPartitionCacheKey(entityId, key, partition);
|
463
|
|
- if (!cassandraTsPartitionsCache.has(partitionSearchKey)) {
|
464
|
|
- ListenableFuture<Integer> result = doSavePartition(tenantId, entityId, key, ttl, partition);
|
465
|
|
- Futures.addCallback(result, new CacheCallback<>(partitionSearchKey), MoreExecutors.directExecutor());
|
466
|
|
- return result;
|
467
|
|
- } else {
|
468
|
|
- return Futures.immediateFuture(0);
|
469
|
|
- }
|
470
|
|
- }
|
471
|
|
- }
|
472
|
|
-
|
473
|
473
|
private ListenableFuture<Integer> doSavePartition(TenantId tenantId, EntityId entityId, String key, long ttl, long partition) {
|
474
|
474
|
log.debug("Saving partition {} for the entity [{}-{}] and key {}", partition, entityId.getEntityType(), entityId.getId(), key);
|
475
|
|
- PreparedStatement preparedStatement = ttl == 0 ? getPartitionInsertStmt() : getPartitionInsertTtlStmt();
|
476
|
|
- BoundStatement stmt = preparedStatement.bind();
|
477
|
|
- stmt.setString(0, entityId.getEntityType().name());
|
478
|
|
- stmt.setUuid(1, entityId.getId());
|
479
|
|
- stmt.setLong(2, partition);
|
480
|
|
- stmt.setString(3, key);
|
|
475
|
+ BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getPartitionInsertStmt() : getPartitionInsertTtlStmt()).bind());
|
|
476
|
+ stmtBuilder.setString(0, entityId.getEntityType().name())
|
|
477
|
+ .setUuid(1, entityId.getId())
|
|
478
|
+ .setLong(2, partition)
|
|
479
|
+ .setString(3, key);
|
481
|
480
|
if (ttl > 0) {
|
482
|
|
- stmt.setInt(4, (int) ttl);
|
|
481
|
+ stmtBuilder.setInt(4, (int) ttl);
|
483
|
482
|
}
|
484
|
|
-// BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(bind);
|
485
|
|
-// stmtBuilder.setString(0, entityId.getEntityType().name())
|
486
|
|
-// .setUuid(1, entityId.getId())
|
487
|
|
-// .setLong(2, partition)
|
488
|
|
-// .setString(3, key);
|
489
|
|
-// if (ttl > 0) {
|
490
|
|
-// stmtBuilder.setInt(4, (int) ttl);
|
491
|
|
-// }
|
492
|
|
-// BoundStatement stmt = stmtBuilder.build();
|
|
483
|
+ BoundStatement stmt = stmtBuilder.build();
|
493
|
484
|
return getFuture(executeAsyncWrite(tenantId, stmt), rs -> 0);
|
494
|
485
|
}
|
495
|
486
|
|
...
|
...
|
|